Skip to content

Releasing Go binaries with GoReleaser — multi-arch, signed, and SBOM-aware

Set up GoReleaser to build Go binaries for multiple OS/arch, sign them with cosign, generate an SBOM, and publish to GitHub Releases plus Docker registries.

A go build && scp release works for one operator on one server, but it doesn’t survive an audit, a multi-platform support requirement, or a supply-chain question six months later. GoReleaser turns Go releases into reproducible artifacts with signatures, SBOMs, and multi-arch container images — driven by a single YAML in your repo. This article shows the GoReleaser configuration Stack Harbor uses for production Go services.

How to verify

After release, the artifacts should be reproducible and signed:

goreleaser check
goreleaser build --snapshot --clean
ls dist/
cosign verify-blob --signature dist/myapp_1.0.0_linux_amd64.tar.gz.sig dist/myapp_1.0.0_linux_amd64.tar.gz
syft dist/myapp_1.0.0_linux_amd64.tar.gz -o spdx-json | jq '.packages | length'
cosign verify ghcr.io/example/myapp:1.0.0 --certificate-identity-regexp '.*' --certificate-oidc-issuer-regexp '.*'

goreleaser check validates the config without building. --snapshot builds without git tags for testing.

What’s happening

GoReleaser orchestrates four phases per release: build (cross-compile Go for the matrix of OS/arch you list), archive (tar/zip + checksum each binary), release (push to GitHub/GitLab/Gitea releases), and publish (push Docker images, Homebrew taps, Linux packages). Plugins extend each phase — cosign signs blobs and images, syft generates SBOMs, nfpm builds deb/rpm packages.

The release is driven by a Git tag matching v*. CI invokes goreleaser release --clean from a workflow triggered on tag push. The result is a tarball-per-platform on the release page, a signed checksums file, an SBOM, and (optionally) a multi-arch Docker manifest.

The reproducibility story matters. GoReleaser sets -trimpath, embeds a build date you can override, and respects SOURCE_DATE_EPOCH for fully reproducible builds. Two CI runs from the same tag should produce byte-identical archives.

The procedure

  1. Author .goreleaser.yaml at the repo root.

    version: 2
    project_name: myapp
    
    before:
      hooks:
        - go mod tidy
        - go generate ./...
    
    builds:
      - id: myapp
        main: ./cmd/myapp
        binary: myapp
        env:
          - CGO_ENABLED=0
        goos: [linux, darwin, windows]
        goarch: [amd64, arm64]
        flags:
          - -trimpath
        ldflags:
          - -s -w
          - -X main.version={{.Version}}
          - -X main.commit={{.Commit}}
          - -X main.date={{.CommitDate}}
    
    archives:
      - format: tar.gz
        format_overrides:
          - goos: windows
            format: zip
        name_template: >-
          {{ .ProjectName }}_{{ .Version }}_
          {{- .Os }}_{{ .Arch }}
    
    checksum:
      name_template: 'checksums.txt'
    
    signs:
      - cmd: cosign
        args:
          - 'sign-blob'
          - '--yes'
          - '--output-signature=${signature}'
          - '${artifact}'
        artifacts: checksum
        output: true
    
    sboms:
      - artifacts: archive
  2. Add a Docker manifest for multi-arch images.

    dockers:
      - image_templates:
          - 'ghcr.io/example/myapp:{{ .Version }}-amd64'
        dockerfile: Dockerfile
        use: buildx
        build_flag_templates:
          - '--platform=linux/amd64'
          - '--label=org.opencontainers.image.source=https://github.com/example/myapp'
        goarch: amd64
      - image_templates:
          - 'ghcr.io/example/myapp:{{ .Version }}-arm64'
        use: buildx
        build_flag_templates:
          - '--platform=linux/arm64'
        goarch: arm64
    
    docker_manifests:
      - name_template: 'ghcr.io/example/myapp:{{ .Version }}'
        image_templates:
          - 'ghcr.io/example/myapp:{{ .Version }}-amd64'
          - 'ghcr.io/example/myapp:{{ .Version }}-arm64'
      - name_template: 'ghcr.io/example/myapp:latest'
        image_templates:
          - 'ghcr.io/example/myapp:{{ .Version }}-amd64'
          - 'ghcr.io/example/myapp:{{ .Version }}-arm64'
    
    docker_signs:
      - cmd: cosign
        args: ['sign', '--yes', '${artifact}@${digest}']
        artifacts: manifests
  3. Author a minimal Dockerfile. GoReleaser injects the prebuilt binary:

    FROM gcr.io/distroless/static-debian12:nonroot
    COPY myapp /usr/bin/myapp
    USER nonroot:nonroot
    ENTRYPOINT ["/usr/bin/myapp"]

    The binary is already cross-compiled and lives at the build root.

  4. GitHub Actions workflow that releases on tag.

    name: release
    on:
      push:
        tags: ['v*']
    permissions:
      contents: write
      packages: write
      id-token: write  # for cosign keyless
    jobs:
      release:
        runs-on: ubuntu-22.04
        steps:
          - uses: actions/checkout@v4
            with: { fetch-depth: 0 }
          - uses: actions/setup-go@v5
            with: { go-version: '1.22.5' }
          - uses: sigstore/cosign-installer@v3
          - uses: anchore/sbom-action/download-syft@v0
          - uses: docker/login-action@v3
            with:
              registry: ghcr.io
              username: ${{ github.actor }}
              password: ${{ secrets.GITHUB_TOKEN }}
          - uses: goreleaser/goreleaser-action@v6
            with:
              distribution: goreleaser
              version: latest
              args: release --clean
            env:
              GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  5. Cut a release.

    git tag -a v1.0.0 -m "v1.0.0"
    git push origin v1.0.0

    The workflow fires, GoReleaser builds the matrix, signs the checksums, builds and pushes multi-arch images, and uploads the SBOM. The GitHub Releases page populates automatically.

  6. Generate Homebrew or Linux packages. Add brews: and nfpms: sections:

    brews:
      - repository:
          owner: example
          name: homebrew-tap
        homepage: https://example.com/myapp
        description: 'MyApp is ...'
    
    nfpms:
      - id: packages
        package_name: myapp
        file_name_template: '{{ .ConventionalFileName }}'
        vendor: Example
        homepage: https://example.com/myapp
        maintainer: 'Ops <ops@example.com>'
        formats: [deb, rpm, apk]
        bindir: /usr/bin

Common pitfalls

  • Forgotten -trimpath ruins reproducibility. Without it, the build host’s filesystem prefix is baked into the binary — two CI runs produce different bytes.
  • fetch-depth: 0 is mandatory. Goreleaser computes the changelog from git log between tags. Shallow clones break it.
  • CGO_ENABLED=0 for static binaries. Cross-compiling with CGO needs zig cc or a cross toolchain; staying CGO-off keeps the matrix simple.
  • Image signing fails without id-token: write. Cosign keyless mode needs an OIDC token from GitHub Actions — that permission must be granted explicitly.
  • goreleaser release from a dirty working tree refuses. Run --snapshot for local testing or --clean to force.

Stack Harbor stands up GoReleaser pipelines for every Go service we ship as part of the build infrastructure — reproducible builds, multi-arch images, cosign signatures, and SBOMs that survive the next audit. See how that fits into our managed operations practice when supply-chain provenance must be defensible.