-
Notifications
You must be signed in to change notification settings - Fork 564
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1644 from diggerhq/feat/dgctl-artefacts-support
feat/dgctl artefacts support
- Loading branch information
Showing
19 changed files
with
572 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
-- Create "job_artefacts" table | ||
CREATE TABLE "public"."job_artefacts" ( | ||
"id" bigserial NOT NULL, | ||
"created_at" timestamptz NULL, | ||
"updated_at" timestamptz NULL, | ||
"deleted_at" timestamptz NULL, | ||
"job_token_id" bigint NULL, | ||
"contents" bytea NULL, | ||
PRIMARY KEY ("id"), | ||
CONSTRAINT "fk_job_artefacts_job_token" FOREIGN KEY ("job_token_id") REFERENCES "public"."job_tokens" ("id") ON UPDATE NO ACTION ON DELETE NO ACTION | ||
); | ||
-- Create index "idx_job_artefacts_deleted_at" to table: "job_artefacts" | ||
CREATE INDEX "idx_job_artefacts_deleted_at" ON "public"."job_artefacts" ("deleted_at"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-- Modify "job_artefacts" table | ||
ALTER TABLE "public"."job_artefacts" ADD COLUMN "size" bigint NULL, ADD COLUMN "content_type" text NULL; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-- Modify "job_artefacts" table | ||
ALTER TABLE "public"."job_artefacts" ADD COLUMN "filename" text NULL; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package models | ||
|
||
import ( | ||
"gorm.io/gorm" | ||
) | ||
|
||
type JobArtefact struct { | ||
gorm.Model | ||
JobTokenID uint | ||
JobToken JobToken | ||
Filename string | ||
Contents []byte `gorm:"type:bytea"` | ||
Size int64 | ||
ContentType string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package utils | ||
|
||
import ( | ||
"archive/zip" | ||
"fmt" | ||
"io" | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
func ExtractZip(zipFilePath string, outDir string) error { | ||
|
||
// Open the zip file | ||
zipReader, err := zip.OpenReader(zipFilePath) | ||
if err != nil { | ||
return fmt.Errorf("failed to open zip: %w", err) | ||
} | ||
defer zipReader.Close() | ||
|
||
for _, file := range zipReader.File { | ||
path := filepath.Join(outDir, file.Name) | ||
|
||
if file.FileInfo().IsDir() { | ||
os.MkdirAll(path, os.ModePerm) | ||
continue | ||
} | ||
|
||
if err := os.MkdirAll(filepath.Dir(path), os.ModePerm); err != nil { | ||
return fmt.Errorf("failed to create directory: %w", err) | ||
} | ||
|
||
dstFile, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, file.Mode()) | ||
if err != nil { | ||
return fmt.Errorf("failed to create file: %w", err) | ||
} | ||
|
||
srcFile, err := file.Open() | ||
if err != nil { | ||
dstFile.Close() | ||
return fmt.Errorf("failed to open zip file: %w", err) | ||
} | ||
|
||
_, err = io.Copy(dstFile, srcFile) | ||
srcFile.Close() | ||
dstFile.Close() | ||
|
||
if err != nil { | ||
return fmt.Errorf("failed to extract file: %w", err) | ||
} | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.