From 7434778a4fb9cec92476e1324a966910b50bd5e8 Mon Sep 17 00:00:00 2001 From: Mark Sagi-Kazar Date: Fri, 19 Jan 2024 21:18:57 +0100 Subject: [PATCH 1/4] ci: improve binary archive Signed-off-by: Mark Sagi-Kazar --- ci/build.go | 22 ++++++++-------------- ci/dagger.json | 2 ++ ci/go.mod | 2 +- flake.lock | 6 +++--- 4 files changed, 14 insertions(+), 18 deletions(-) diff --git a/ci/build.go b/ci/build.go index 4b99349..07e4dbb 100644 --- a/ci/build.go +++ b/ci/build.go @@ -2,7 +2,6 @@ package main import ( "fmt" - "path" "strings" "time" ) @@ -118,19 +117,14 @@ func (m *Build) binaryArchives(version string) []*File { func (m *Build) binaryArchive(version string, platform Platform) *File { binary := m.binary(platform, version) - dir := dag.Directory(). - WithFile("benthos", binary). - WithFile("", m.Source.File("README.md")). - WithFile("", m.Source.File("LICENSE")) - - archiveName := fmt.Sprintf("benthos_%s.tar.gz", strings.ReplaceAll(string(platform), "/", "_")) - - return dag.Container(). - From(alpineBaseImage). - WithWorkdir("/work"). - WithMountedDirectory("/work", dir). - WithExec([]string{"tar", "-czf", archiveName, "."}). - File(path.Join("/work", archiveName)) + return dag.Arc().ArchiveFiles( + fmt.Sprintf("benthos_%s", strings.ReplaceAll(string(platform), "/", "_")), + []*File{ + binary, + m.Source.File("README.md"), + m.Source.File("LICENSE"), + }, + ).TarGz() // TODO: use zip for windows } func (m *Build) checksums(files []*File) *File { diff --git a/ci/dagger.json b/ci/dagger.json index 41eafdf..8191fdf 100644 --- a/ci/dagger.json +++ b/ci/dagger.json @@ -8,6 +8,8 @@ "api/client/node/node_modules" ], "dependencies": [ + "github.com/sagikazarmark/daggerverse/arc@20e8626c9f25d570e6321765d496643736d76ee5", + "github.com/sagikazarmark/daggerverse/archive@5429a12ed7cad99697fb680b7acaff9d9074e169", "github.com/sagikazarmark/daggerverse/gh@ef6b5bf932277ffc4b7e1ea9fd9a1c26a2780da3", "github.com/sagikazarmark/daggerverse/go@54de323eba85e8d1154751b84a3fb7ab8e2fdd8e", "github.com/sagikazarmark/daggerverse/golangci-lint@fd0f3da52f511b9188a6f5bd44b193e3d614f0e2", diff --git a/ci/go.mod b/ci/go.mod index af4c13e..9c93560 100644 --- a/ci/go.mod +++ b/ci/go.mod @@ -11,5 +11,5 @@ require ( require ( github.com/stretchr/testify v1.8.3 // indirect - github.com/vektah/gqlparser/v2 v2.5.6 // indirect + github.com/vektah/gqlparser/v2 v2.5.6 ) diff --git a/flake.lock b/flake.lock index cf7ada5..0c0cb82 100644 --- a/flake.lock +++ b/flake.lock @@ -7,11 +7,11 @@ ] }, "locked": { - "lastModified": 1704294979, - "narHash": "sha256-66B+UtFsv9Uq2RS0v9/+oLJAQ6rOwzRRXf6cXeiABX8=", + "lastModified": 1705674713, + "narHash": "sha256-SA8SIG+CdGTFMw/0eod8+tvROQ9fhqQJF3XgmfRrTsc=", "owner": "dagger", "repo": "nix", - "rev": "5bc932eb359181053d42f6d73cc173966b8ff258", + "rev": "d74bfdc29cfa2d89c02f0c5ba2f76c2608fe582b", "type": "github" }, "original": { From e5cde8a5e99bfbb0f11d39ae47d38048e510dc24 Mon Sep 17 00:00:00 2001 From: Mark Sagi-Kazar Date: Mon, 22 Jan 2024 17:41:47 +0100 Subject: [PATCH 2/4] feat: improve archiving Signed-off-by: Mark Sagi-Kazar --- ci/build.go | 22 ++++++++++++++-------- ci/dagger.json | 9 ++++----- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/ci/build.go b/ci/build.go index 07e4dbb..51c3cc0 100644 --- a/ci/build.go +++ b/ci/build.go @@ -88,6 +88,7 @@ func (m *Build) binary(platform Platform, version string) *File { WithCgoDisabled(). WithSource(m.Source). Build(GoWithSourceBuildOpts{ + Name: "benthos", Trimpath: true, RawArgs: []string{ "-ldflags", @@ -115,16 +116,21 @@ func (m *Build) binaryArchives(version string) []*File { } func (m *Build) binaryArchive(version string, platform Platform) *File { - binary := m.binary(platform, version) + var archiver interface { + Archive(name string, source *Directory) *File + } = dag.Archivist().TarGz() - return dag.Arc().ArchiveFiles( + if strings.HasPrefix(string(platform), "windows/") { + archiver = dag.Archivist().Zip() + } + + return archiver.Archive( fmt.Sprintf("benthos_%s", strings.ReplaceAll(string(platform), "/", "_")), - []*File{ - binary, - m.Source.File("README.md"), - m.Source.File("LICENSE"), - }, - ).TarGz() // TODO: use zip for windows + dag.Directory(). + WithFile("", m.binary(platform, version)). + WithFile("", m.Source.File("README.md")). + WithFile("", m.Source.File("LICENSE")), + ) } func (m *Build) checksums(files []*File) *File { diff --git a/ci/dagger.json b/ci/dagger.json index 8191fdf..05dcfdf 100644 --- a/ci/dagger.json +++ b/ci/dagger.json @@ -8,13 +8,12 @@ "api/client/node/node_modules" ], "dependencies": [ - "github.com/sagikazarmark/daggerverse/arc@20e8626c9f25d570e6321765d496643736d76ee5", - "github.com/sagikazarmark/daggerverse/archive@5429a12ed7cad99697fb680b7acaff9d9074e169", + "github.com/sagikazarmark/daggerverse/archivist@493a0d97d9468d8dee23dec1f805268e940c386d", + "github.com/sagikazarmark/daggerverse/checksum@493a0d97d9468d8dee23dec1f805268e940c386d", "github.com/sagikazarmark/daggerverse/gh@ef6b5bf932277ffc4b7e1ea9fd9a1c26a2780da3", - "github.com/sagikazarmark/daggerverse/go@54de323eba85e8d1154751b84a3fb7ab8e2fdd8e", + "github.com/sagikazarmark/daggerverse/go@493a0d97d9468d8dee23dec1f805268e940c386d", "github.com/sagikazarmark/daggerverse/golangci-lint@fd0f3da52f511b9188a6f5bd44b193e3d614f0e2", "github.com/sagikazarmark/daggerverse/helm-docs@1e4b4c1ac88f2980870d084f51f5adb33bf227a3", - "github.com/sagikazarmark/daggerverse/helm@4e48ba4471930a7b1f131f029afd4785c8a6f133", - "github.com/shykes/daggerverse/supergit@4113b803fcf4ba83b39cd464856af94656197cbf" + "github.com/sagikazarmark/daggerverse/helm@4e48ba4471930a7b1f131f029afd4785c8a6f133" ] } From 4334898178227489afadbe0744c321a4e615dc46 Mon Sep 17 00:00:00 2001 From: Mark Sagi-Kazar Date: Mon, 22 Jan 2024 17:47:05 +0100 Subject: [PATCH 3/4] ci: upgrade dagger Signed-off-by: Mark Sagi-Kazar --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 9ff8358..7b8c7aa 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -21,7 +21,7 @@ jobs: module: github.com/${{ github.repository }}/ci@${{ github.ref }} args: --checkout ${{ github.ref }} ci cloud-token: ${{ secrets.DAGGER_CLOUD_TOKEN }} - version: "0.9.5" + version: "0.9.7" build: name: Build From 07fa85d7d466977c751cebd4a47c8580c3fc594f Mon Sep 17 00:00:00 2001 From: Mark Sagi-Kazar Date: Tue, 23 Jan 2024 13:29:36 +0100 Subject: [PATCH 4/4] ci: use checksum module Signed-off-by: Mark Sagi-Kazar --- ci/build.go | 17 ----------------- ci/dagger.json | 2 +- ci/release.go | 2 +- 3 files changed, 2 insertions(+), 19 deletions(-) diff --git a/ci/build.go b/ci/build.go index 51c3cc0..bb43914 100644 --- a/ci/build.go +++ b/ci/build.go @@ -133,23 +133,6 @@ func (m *Build) binaryArchive(version string, platform Platform) *File { ) } -func (m *Build) checksums(files []*File) *File { - return dag.Container(). - From(alpineBaseImage). - WithWorkdir("/work"). - With(func(c *Container) *Container { - dir := dag.Directory() - - for _, file := range files { - dir = dir.WithFile("", file) - } - - return c.WithMountedDirectory("/work", dir) - }). - WithExec([]string{"sh", "-c", "sha256sum $(ls) > checksums.txt"}). - File("/work/checksums.txt") -} - func (m *Build) HelmChart( // Release version. // +optional diff --git a/ci/dagger.json b/ci/dagger.json index 05dcfdf..dc8a409 100644 --- a/ci/dagger.json +++ b/ci/dagger.json @@ -9,7 +9,7 @@ ], "dependencies": [ "github.com/sagikazarmark/daggerverse/archivist@493a0d97d9468d8dee23dec1f805268e940c386d", - "github.com/sagikazarmark/daggerverse/checksum@493a0d97d9468d8dee23dec1f805268e940c386d", + "github.com/sagikazarmark/daggerverse/checksum@5b3e18c117fb761d645d04c69347b0e1ced73e77", "github.com/sagikazarmark/daggerverse/gh@ef6b5bf932277ffc4b7e1ea9fd9a1c26a2780da3", "github.com/sagikazarmark/daggerverse/go@493a0d97d9468d8dee23dec1f805268e940c386d", "github.com/sagikazarmark/daggerverse/golangci-lint@fd0f3da52f511b9188a6f5bd44b193e3d614f0e2", diff --git a/ci/release.go b/ci/release.go index 82965f7..79f9f51 100644 --- a/ci/release.go +++ b/ci/release.go @@ -120,7 +120,7 @@ func (m *Ci) pushImages(ctx context.Context, version string, tags []string) erro func (m *Ci) releaseAssets(version string) []*File { binaryArchives := m.Build().binaryArchives(version) - checksums := m.Build().checksums(binaryArchives) + checksums := dag.Checksum().Sha256().Calculate(binaryArchives) return append(binaryArchives, checksums) }