From 967e4745db3c8d62449bce2be9a52b70c47a8d28 Mon Sep 17 00:00:00 2001 From: appkins Date: Fri, 17 Oct 2025 00:03:29 -0500 Subject: [PATCH] feat: Add ko build for Go Releaser Signed-off-by: appkins --- .github/workflows/ci.yaml | 18 ++++------------- .github/workflows/release.yaml | 18 ++++++----------- .goreleaser.yaml | 37 ++++++++++++++++++++++++---------- 3 files changed, 36 insertions(+), 37 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 75b8de5..320a3d7 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -73,22 +73,12 @@ jobs: go-version: "${{ env.GO_VERSION }}" cache: true - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Log in to the Container registry - uses: docker/login-action@v3 - with: - registry: ${{ env.REGISTRY }} - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} + - uses: ko-build/setup-ko@v0.9 + - run: ko login ${{ env.REGISTRY }} -u ${{ github.actor }} --password ${{ secrets.GITHUB_TOKEN }} - name: Build and push image run: make build-image-push env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - IS_RELEASE: false - GORELEASER_EXTRA_FLAGS: "--skip=validate" + IS_RELEASE: true + GORELEASER_EXTRA_FLAGS: "--clean --skip=validate" diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 1ab431f..050397d 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -27,18 +27,12 @@ jobs: go-version: "${{ env.GO_VERSION }}" cache: true - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Log in to the Container registry - uses: docker/login-action@v3 - with: - registry: ${{ env.REGISTRY }} - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} + - uses: ko-build/setup-ko@v0.9 + env: + KO_DEFAULTBASEIMAGE: docker.io/chainguard/static + KO_DOCKER_REPO: "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}" + + - run: ko login ${{ env.REGISTRY }} -u ${{ github.actor }} --password ${{ secrets.GITHUB_TOKEN }} - name: Build and push image run: make build-image-push diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 2710bd2..8f29e69 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -2,7 +2,7 @@ version: 2 env: - REGISTRY={{ if index .Env "REGISTRY" }}{{ .Env.REGISTRY }}{{ else }}ghcr.io{{ end }} - - IMAGE_NAME={{ if index .Env "IMAGE_NAME" }}{{ .Env.IMAGE_NAME }}{{ else }}tinkerbell/cluster-api-provider-tinkerbell{{ end }} + - IMAGE_NAME={{ if index .Env "IMAGE_NAME" }}{{ .Env.IMAGE_NAME }}{{ else }}{{.GitURL | trimprefix "https://" | trimprefix "git@" | trimprefix "github.com" | trimprefix ":" | trimprefix "/" | trimsuffix ".git"}}{{ end }} - BINARY=capt - IS_RELEASE={{ if index .Env "IS_RELEASE" }}{{ .Env.IS_RELEASE }}{{ else }}true{{ end }} @@ -14,31 +14,36 @@ builds: - id: build binary: "{{ .Env.BINARY }}" env: - - CGO_ENABLED=0 + - CGO_ENABLED=0 goos: - - linux + - linux ldflags: - - -s -w + - -s -w goarch: - - amd64 - - arm64 + - amd64 + - arm64 + skip: false checksum: - name_template: 'checksums.txt' + name_template: "checksums.txt" archives: - formats: - - binary + - binary release: disable: true -dockers_v2: - - images: +snapshot: + version_template: "{{ incpatch .Version }}-next" + +kos: + - build: build + repositories: - "{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}" tags: - '{{ if eq .Env.IS_RELEASE "true" }}v{{ .Version }}{{ end }}' - - '{{ if not .IsNightly }}latest{{ end }}' + - "{{ if not .IsSnapshot }}latest{{ end }}" - '{{ if eq .Branch "main" }}sha-{{ .ShortCommit }}{{ end }}' labels: "org.opencontainers.image.created": "{{.Date}}" @@ -46,3 +51,13 @@ dockers_v2: "org.opencontainers.image.revision": "{{.FullCommit}}" "org.opencontainers.image.version": "v{{.Version}}" "org.opencontainers.image.source": "{{.GitURL}}" + bare: true + preserve_import_paths: false + platforms: + - linux/amd64 + - linux/arm64 + base_image: docker.io/chainguard/static + creation_time: "{{.CommitTimestamp}}" + ko_data_creation_time: "{{.CommitTimestamp}}" + sbom: none + disable: "{{ .IsSnapshot }}"