From 78c92a9f71853a14f53fc80ac22ca4147bc70ade Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20D=C3=B6ll?= Date: Sun, 14 Jul 2024 18:10:18 +0000 Subject: [PATCH] chore: update release worklow --- .github/workflows/release.yml | 59 +++++++++++++++++++-- .goreleaser.yml | 93 +++++++++++++++++++++++----------- Dockerfile | 7 +++ go.mod | 11 +++- go.sum | 15 ++++++ internal/tools/updater/main.go | 48 ++++++++++++++++++ 6 files changed, 197 insertions(+), 36 deletions(-) create mode 100644 Dockerfile create mode 100644 internal/tools/updater/main.go diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f55a2c6..e6a63af 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -3,13 +3,16 @@ name: Release on: + workflow_dispatch: push: tags: - - 'v*' + - "v*" env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - + IMAGE_NAME: zeiss/knox + REGISTRY: ghcr.io + jobs: test: permissions: @@ -17,12 +20,58 @@ jobs: uses: ./.github/workflows/main.yml release: + needs: [test] runs-on: ubuntu-latest - needs: [ test ] + permissions: + packages: write + contents: write steps: - uses: actions/checkout@v4 + - run: | + git config user.name "$GITHUB_ACTOR" + git config user.email "$GITHUB_ACTOR@users.noreply.github.com" + - run: | + echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV - uses: actions/setup-go@v5 with: go-version-file: ./go.mod - - run: make release - if: success() \ No newline at end of file + - uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - uses: actions/cache@v3 + with: + path: | + ~/go/pkg/mod + key: ${{ github.job }}-${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ github.job }}-${{ runner.os }}-go- + - id: image-tag + run: | + IMAGE_TAG=${GITHUB_SHA} + [[ ${GITHUB_REF_TYPE} == "tag" ]] && IMAGE_TAG=${GITHUB_REF_NAME} + echo "IMAGE_TAG=${IMAGE_TAG}" >> $GITHUB_OUTPUT + - run: sudo apt-get update && sudo apt install -y libxml2-dev libxslt1-dev liblzma-dev zlib1g-dev + - run: | + IMAGE_TAG=${{ steps.image-tag.outputs.IMAGE_TAG }} make release + env: + KO_DOCKER_REPO: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + DIST_DIR: /tmp/dist + if: success() + - run: | + go run internal/tools/updater/main.go --file helm/charts/knox/Chart.yaml --version ${{ env.RELEASE_VERSION }} + - uses: azure/setup-helm@v4 + with: + version: v3.11.2 + - uses: helm/chart-releaser-action@v1.6.0 + with: + charts_dir: helm/charts + config: helm/cr.yaml + env: + CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + - uses: actions/upload-artifact@v4 + with: + name: manifests + path: /tmp/dist + retention-days: 14 \ No newline at end of file diff --git a/.goreleaser.yml b/.goreleaser.yml index 2938cb4..904d38a 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -1,56 +1,91 @@ project_name: knox +env: + - GO111MODULE=on + - CGO_ENABLED=0 + before: hooks: - go mod tidy + - go mod download builds: - - + - id: main + binary: main + main: ./main.go goos: + - windows - darwin - linux - - windows goarch: - 386 - amd64 - arm - arm64 - goarm: - - 7 - ignore: - - goos: darwin - goarch: 386 - - goos: windows - goarch: arm - env: - - CGO_ENABLED=0 ldflags: - - -s -w + - -s -w archives: - - builds: - - csync - name_template: "csync_{{ .Version }}_{{ .Os }}_{{ .Arch }}" + - id: main + builds: + - main + name_template: "knox_{{ .Version }}_{{ .Os }}_{{ .Arch }}" -release: - header: | - ## Changelog ({{ .Date }}) - - Welcome to this new release! We hope you enjoy the changes we've made.# dockers: - - image_templates: - - 'zeiss/knox:{{ .Tag }}-amd64' + - image_templates: [ + "ghcr.io/zeiss/{{ .ProjectName }}/knox:{{ .Version }}-amd64" + ] + dockerfile: Dockerfile use: buildx + goos: linux + goarch: amd64 build_flag_templates: - - "--pull" - - "--platform=linux/amd64" - - image_templates: - - 'zeiss/knox:{{ .Tag }}-arm64' + - --platform=linux/amd64 + - --label=org.opencontainers.image.title={{ .ProjectName }} + - --label=org.opencontainers.image.description={{ .ProjectName }} + - --label=org.opencontainers.image.url=https://github.com/zeiss/{{ .ProjectName }}/knox + - --label=org.opencontainers.image.source=https://github.com/zeiss/{{ .ProjectName }} + - --label=org.opencontainers.image.version={{ .Version }} + - --label=org.opencontainers.image.created={{ time "2006-01-02T15:04:05Z07:00" }} + - --label=org.opencontainers.image.revision={{ .FullCommit }} + - --label=org.opencontainers.image.licenses=Apache-2.0 + - image_templates: [ + "ghcr.io/zeiss/{{ .ProjectName }}/knox:{{ .Version }}-arm64" + ] + dockerfile: Dockerfile use: buildx - build_flag_templates: - - "--pull" - - "--platform=linux/arm64" + goos: linux goarch: arm64 + build_flag_templates: + - --platform=linux/arm64 + - --label=org.opencontainers.image.title={{ .ProjectName }} + - --label=org.opencontainers.image.description={{ .ProjectName }} + - --label=org.opencontainers.image.url=https://github.com/zeiss/{{ .ProjectName }}/knox + - --label=org.opencontainers.image.source=https://github.com/zeiss/{{ .ProjectName }} + - --label=org.opencontainers.image.version={{ .Version }} + - --label=org.opencontainers.image.created={{ time "2006-01-02T15:04:05Z07:00" }} + - --label=org.opencontainers.image.revision={{ .FullCommit }} + - --label=org.opencontainers.image.licenses=Apache-2.0 + +docker_manifests: + - name_template: "ghcr.io/zeiss/{{ .ProjectName }}/knox:{{ .Version }}" + image_templates: + - 'ghcr.io/zeiss/{{ .ProjectName }}/knox:{{ .Version }}-amd64' + - 'ghcr.io/zeiss/{{ .ProjectName }}/knox:{{ .Version }}-arm64' + + +gomod: + proxy: true + +release: + draft: true + +checksum: + name_template: "{{ .ProjectName }}_checksums.txt" + +snapshot: + name_template: SNAPSHOT-{{.ShortCommit}} + changelog: groups: - title: Features diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..63a0f5c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM cgr.dev/chainguard/static:latest + +WORKDIR / + +COPY knox /main + +ENTRYPOINT ["/main"] \ No newline at end of file diff --git a/go.mod b/go.mod index 62cbdd3..11a5fa6 100644 --- a/go.mod +++ b/go.mod @@ -15,12 +15,15 @@ require ( github.com/oapi-codegen/fiber-middleware v1.0.2 github.com/oapi-codegen/runtime v1.1.1 github.com/spf13/cobra v1.8.1 + github.com/spf13/pflag v1.0.5 github.com/zeiss/fiber-authz v1.0.31 github.com/zeiss/fiber-goth v1.2.8 github.com/zeiss/gorm-seed v0.1.2 + golang.org/x/mod v0.18.0 gorm.io/datatypes v1.2.1 gorm.io/driver/postgres v1.5.9 gorm.io/gorm v1.25.11 + helm.sh/helm v2.17.0+incompatible mvdan.cc/gofumpt v0.6.0 ) @@ -37,6 +40,7 @@ require ( github.com/Crocmagnon/fatcontext v0.2.2 // indirect github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24 // indirect github.com/GaijinEntertainment/go-exhaustruct/v3 v3.2.0 // indirect + github.com/Masterminds/semver v1.5.0 // indirect github.com/Masterminds/semver/v3 v3.2.1 // indirect github.com/OpenPeeDeeP/depguard/v2 v2.2.0 // indirect github.com/alecthomas/go-check-sumtype v0.1.4 // indirect @@ -62,6 +66,7 @@ require ( github.com/chavacava/garif v0.1.0 // indirect github.com/ckaznocha/intrange v0.1.2 // indirect github.com/curioswitch/go-reassign v0.2.0 // indirect + github.com/cyphar/filepath-securejoin v0.2.4 // indirect github.com/daixiang0/gci v0.13.4 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect @@ -72,6 +77,7 @@ require ( github.com/firefart/nonamedreturns v1.0.5 // indirect github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/fzipp/gocyclo v0.6.0 // indirect + github.com/ghodss/yaml v1.0.0 // indirect github.com/ghostiam/protogetter v0.3.6 // indirect github.com/go-critic/go-critic v0.11.4 // indirect github.com/go-openapi/jsonpointer v0.21.0 // indirect @@ -89,6 +95,7 @@ require ( github.com/gobwas/glob v0.2.3 // indirect github.com/goccy/go-json v0.10.2 // indirect github.com/gofrs/flock v0.8.1 // indirect + github.com/golang/protobuf v1.5.4 // indirect github.com/golangci/dupl v0.0.0-20180902072040-3e9179ac440a // indirect github.com/golangci/gofmt v0.0.0-20231018234816-f50ced29576e // indirect github.com/golangci/misspell v0.6.0 // indirect @@ -191,7 +198,6 @@ require ( github.com/sourcegraph/go-diff v0.7.0 // indirect github.com/spf13/afero v1.11.0 // indirect github.com/spf13/cast v1.6.0 // indirect - github.com/spf13/pflag v1.0.5 // indirect github.com/spf13/viper v1.18.2 // indirect github.com/ssgreg/nlreturn/v2 v2.2.1 // indirect github.com/stbenjam/no-sprintf-host-port v0.1.1 // indirect @@ -224,7 +230,6 @@ require ( golang.org/x/crypto v0.24.0 // indirect golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect golang.org/x/exp/typeparams v0.0.0-20240314144324-c7f7c6466f7f // indirect - golang.org/x/mod v0.18.0 // indirect golang.org/x/sync v0.7.0 // indirect golang.org/x/sys v0.21.0 // indirect golang.org/x/text v0.16.0 // indirect @@ -235,5 +240,7 @@ require ( gopkg.in/yaml.v3 v3.0.1 // indirect gorm.io/driver/mysql v1.5.6 // indirect honnef.co/go/tools v0.4.7 // indirect + k8s.io/apimachinery v0.27.0 // indirect + k8s.io/helm v2.17.0+incompatible // indirect mvdan.cc/unparam v0.0.0-20240528143540-8a5130ca722f // indirect ) diff --git a/go.sum b/go.sum index 30e42e0..613789f 100644 --- a/go.sum +++ b/go.sum @@ -22,6 +22,8 @@ github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24 h1:sHglBQTwgx+rW github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24/go.mod h1:4UJr5HIiMZrwgkSPdsjy2uOQExX/WEILpIrO9UPGuXs= github.com/GaijinEntertainment/go-exhaustruct/v3 v3.2.0 h1:sATXp1x6/axKxz2Gjxv8MALP0bXaNRfQinEwyfMcx8c= github.com/GaijinEntertainment/go-exhaustruct/v3 v3.2.0/go.mod h1:Nl76DrGNJTA1KJ0LePKBw/vznBX1EHbAZX8mwjR82nI= +github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww= +github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y= github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0rYXWg0= github.com/Masterminds/semver/v3 v3.2.1/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ= github.com/OpenPeeDeeP/depguard/v2 v2.2.0 h1:vDfG60vDtIuf0MEOhmLlLLSzqaRM8EMcgJPdp74zmpA= @@ -79,6 +81,8 @@ github.com/ckaznocha/intrange v0.1.2/go.mod h1:RWffCw/vKBwHeOEwWdCikAtY0q4gGt8Vh github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/curioswitch/go-reassign v0.2.0 h1:G9UZyOcpk/d7Gd6mqYgd8XYWFMw/znxwGDUstnC9DIo= github.com/curioswitch/go-reassign v0.2.0/go.mod h1:x6OpXuWvgfQaMGks2BZybTngWjT84hqJfKoO8Tt/Roc= +github.com/cyphar/filepath-securejoin v0.2.4 h1:Ugdm7cg7i6ZK6x3xDF1oEu1nfkyfH53EtKeQYTC3kyg= +github.com/cyphar/filepath-securejoin v0.2.4/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4= github.com/daixiang0/gci v0.13.4 h1:61UGkmpoAcxHM2hhNkZEf5SzwQtWJXTSws7jaPyqwlw= github.com/daixiang0/gci v0.13.4/go.mod h1:12etP2OniiIdP4q+kjUGrC/rUagga7ODbqsom5Eo5Yk= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -106,6 +110,8 @@ github.com/fzipp/gocyclo v0.6.0 h1:lsblElZG7d3ALtGMx9fmxeTKZaLLpU8mET09yN4BBLo= github.com/fzipp/gocyclo v0.6.0/go.mod h1:rXPyn8fnlpa0R2csP/31uerbiVBugk5whMdlyaLkLoA= github.com/getkin/kin-openapi v0.126.0 h1:c2cSgLnAsS0xYfKsgt5oBV6MYRM/giU8/RtwUY4wyfY= github.com/getkin/kin-openapi v0.126.0/go.mod h1:7mONz8IwmSRg6RttPu6v8U/OJ+gr+J99qSFNjPGSQqw= +github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= +github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/ghostiam/protogetter v0.3.6 h1:R7qEWaSgFCsy20yYHNIJsU9ZOb8TziSRRxuAOTVKeOk= github.com/ghostiam/protogetter v0.3.6/go.mod h1:7lpeDnEJ1ZjL/YtyoN99ljO4z0pd3H0d18/t2dPBxHw= github.com/go-critic/go-critic v0.11.4 h1:O7kGOCx0NDIni4czrkRIXTnit0mkyKOCePh3My6OyEU= @@ -119,6 +125,7 @@ github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI= github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y= github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg= +github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 h1:p104kn46Q8WdvHunIJ9dAyjPVtrBPhSr3KT2yUst43I= github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI= github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8= github.com/go-test/deep v1.0.8 h1:TDsG77qcSprGbC6vTN8OuXp5g+J+b5Pcguhf7Zt61VM= @@ -160,6 +167,8 @@ github.com/golang-sql/sqlexp v0.1.0 h1:ZCD6MBpcuOVfGVqsEmY5/4FtYiKz6tSyUv9LPEDei github.com/golang-sql/sqlexp v0.1.0/go.mod h1:J4ad9Vo8ZCWQ2GMrC4UCQy1JpCbwU9m3EOqtpKwwwHI= github.com/golang/mock v1.7.0-rc.1 h1:YojYx61/OLFsiv6Rw1Z96LpldJIy31o+UHmwAUMJ6/U= github.com/golang/mock v1.7.0-rc.1/go.mod h1:s42URUywIqd+OcERslBJvOjepvNymP31m3q8d/GkuRs= +github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= +github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/golangci/dupl v0.0.0-20180902072040-3e9179ac440a h1:w8hkcTqaFpzKqonE9uMCefW1WDie15eSP/4MssdenaM= github.com/golangci/dupl v0.0.0-20180902072040-3e9179ac440a/go.mod h1:ryS0uhF+x9jgbj/N71xsEqODy9BN81/GonCZiOzirOk= github.com/golangci/gofmt v0.0.0-20231018234816-f50ced29576e h1:ULcKCDV1LOZPFxGZaA6TlQbiM3J2GCPnkx/bGF6sX/g= @@ -679,8 +688,14 @@ gorm.io/driver/sqlserver v1.4.1/go.mod h1:DJ4P+MeZbc5rvY58PnmN1Lnyvb5gw5NPzGshHD gorm.io/gorm v1.25.7/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8= gorm.io/gorm v1.25.11 h1:/Wfyg1B/je1hnDx3sMkX+gAlxrlZpn6X0BXRlwXlvHg= gorm.io/gorm v1.25.11/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ= +helm.sh/helm v2.17.0+incompatible h1:cSe3FaQOpRWLDXvTObQNj0P7WI98IG5yloU6tQVls2k= +helm.sh/helm v2.17.0+incompatible/go.mod h1:0Xbc6ErzwWH9qC55X1+hE3ZwhM3atbhCm/NbFZw5i+4= honnef.co/go/tools v0.4.7 h1:9MDAWxMoSnB6QoSqiVr7P5mtkT9pOc1kSxchzPCnqJs= honnef.co/go/tools v0.4.7/go.mod h1:+rnGS1THNh8zMwnd2oVOTL9QF6vmfyG6ZXBULae2uc0= +k8s.io/apimachinery v0.27.0 h1:vEyy/PVMbPMCPutrssCVHCf0JNZ0Px+YqPi82K2ALlk= +k8s.io/apimachinery v0.27.0/go.mod h1:5ikh59fK3AJ287GUvpUsryoMFtH9zj/ARfWCo3AyXTM= +k8s.io/helm v2.17.0+incompatible h1:Bpn6o1wKLYqKM3+Osh8e+1/K2g/GsQJ4F4yNF2+deao= +k8s.io/helm v2.17.0+incompatible/go.mod h1:LZzlS4LQBHfciFOurYBFkCMTaZ0D1l+p0teMg7TSULI= mvdan.cc/gofumpt v0.6.0 h1:G3QvahNDmpD+Aek/bNOLrFR2XC6ZAdo62dZu65gmwGo= mvdan.cc/gofumpt v0.6.0/go.mod h1:4L0wf+kgIPZtcCWXynNS2e6bhmj73umwnuXSZarixzA= mvdan.cc/unparam v0.0.0-20240528143540-8a5130ca722f h1:lMpcwN6GxNbWtbpI1+xzFLSW8XzX0u72NttUGVFjO3U= diff --git a/internal/tools/updater/main.go b/internal/tools/updater/main.go new file mode 100644 index 0000000..049b565 --- /dev/null +++ b/internal/tools/updater/main.go @@ -0,0 +1,48 @@ +package main + +import ( + "errors" + "log" + "os" + "strings" + + "github.com/spf13/pflag" + "golang.org/x/mod/semver" + "helm.sh/helm/pkg/chartutil" +) + +type flags struct { + File string + Version string +} + +func main() { + log.SetFlags(0) + log.SetOutput(os.Stderr) + + f := &flags{} + + pflag.StringVar(&f.File, "file", f.File, "chart") + pflag.StringVar(&f.Version, "version", f.Version, "version") + pflag.Parse() + + ok := semver.IsValid(f.Version) + if !ok { + log.Fatal(errors.New("updater: no valid version")) + } + + f.Version = strings.TrimPrefix(f.Version, "v") + + meta, err := chartutil.LoadChartfile(f.File) + if err != nil { + log.Fatal(err) + } + + meta.AppVersion = f.Version + meta.Version = f.Version + + err = chartutil.SaveChartfile(f.File, meta) + if err != nil { + log.Fatal(err) + } +}