Skip to content

build: replace Docker-based image build with goreleaser/ko#2956

Open
mrueg wants to merge 1 commit into
kubernetes:mainfrom
mrueg:goreleaser-container-builds
Open

build: replace Docker-based image build with goreleaser/ko#2956
mrueg wants to merge 1 commit into
kubernetes:mainfrom
mrueg:goreleaser-container-builds

Conversation

@mrueg
Copy link
Copy Markdown
Member

@mrueg mrueg commented May 12, 2026

What this PR does / why we need it:
Replace the manual multi-arch Docker build process with goreleaser's ko integration, which builds container images directly from Go source without a Dockerfile.

Changes:

  • .goreleaser.yaml: add builds section with ldflags matching the previous Makefile, and a kos section for multi-arch container builds (amd64, arm/v6, arm/v7, arm64, ppc64le, s390x) using gcr.io/distroless/static-debian13 as base image
  • Makefile: replace Docker-based container/push targets with goreleaser; 'container' builds a local snapshot for the current arch (used by e2e), 'all-container' builds all platforms, 'push' runs a full goreleaser release for Cloud Build; 'build' now uses goreleaser build --snapshot; remove ALL_ARCH, MULTI_ARCH_IMG, KO_CLI and DOCKER_CLI_EXPERIMENTAL variables
  • ci.yml: replace 'make build' (Docker-in-Docker) in the build job with goreleaser build --snapshot via goreleaser-action
  • pre-release.yml: fix stale comment referencing Dockerfile
  • Dockerfile: remove, ko builds from source directly; port/telemetry port defaults (8080/8081) are already set in pkg/options/options.go
  • SECURITY-INSIGHTS.yml: replace Dockerfile link with .goreleaser.yaml
  • tests/e2e.sh: remove arch suffix from image name to match ko output
  • .gitignore: add /dist (goreleaser build output)

How does this change affect the cardinality of KSM: (increases, decreases or does not change cardinality)
None
Which issue(s) this PR fixes: (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged)
Fixes #

@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label May 12, 2026
@mrueg mrueg requested a review from Copilot May 12, 2026 20:40
@k8s-ci-robot k8s-ci-robot added the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label May 12, 2026
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

This issue is currently awaiting triage.

If kube-state-metrics contributors determine this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mrueg

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot requested review from bhope and dgrisonnet May 12, 2026 20:40
@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 12, 2026
@github-project-automation github-project-automation Bot moved this to Needs Triage in SIG Instrumentation May 12, 2026
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels May 12, 2026
@mrueg mrueg force-pushed the goreleaser-container-builds branch from 1244837 to b486c0f Compare May 12, 2026 20:42
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates kube-state-metrics’ container image build flow away from a Dockerfile/Docker-based multi-arch build to GoReleaser’s ko integration, aiming to build multi-platform images directly from Go source.

Changes:

  • Introduces GoReleaser build + ko configuration for multi-arch image builds in .goreleaser.yaml.
  • Updates Makefile targets to use GoReleaser for build, container, all-container, and push, and removes Dockerfile-based image build logic.
  • Adjusts CI build workflow to use goreleaser-action, and updates e2e image naming and various references (SECURITY-INSIGHTS.yml, .gitignore, workflow comment).

Reviewed changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
tests/e2e.sh Updates expected image name (removes arch suffix) to align with ko-style image naming.
SECURITY-INSIGHTS.yml Replaces Dockerfile reference with .goreleaser.yaml.
Makefile Replaces Docker-based build/push targets with GoReleaser/ko-driven targets.
Dockerfile Removes Dockerfile (ko builds from source).
.goreleaser.yaml Adds GoReleaser builds and kos config for multi-arch binaries/images and ldflags.
.gitignore Ignores GoReleaser output directory (/dist).
.github/workflows/pre-release.yml Updates a stale comment about where the Go version comes from.
.github/workflows/ci.yml Switches build job from make build to GoReleaser snapshot build via GitHub Action.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Makefile Outdated
Comment thread Makefile Outdated
Comment thread Makefile Outdated
Comment thread .goreleaser.yaml
Comment on lines +20 to +26
ldflags:
- -s -w
- -X github.com/prometheus/common/version.Version={{.Version}}
- -X github.com/prometheus/common/version.Revision={{.Commit}}
- -X github.com/prometheus/common/version.Branch={{.Branch}}
- -X github.com/prometheus/common/version.BuildDate={{.Date}}
- -X k8s.io/kube-state-metrics/v2/pkg/app.ClientGoVersion={{ index .Env "K8S_CLIENT_VERSION" }}
Comment thread .github/workflows/ci.yml Outdated
@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla Bot commented May 12, 2026

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: mrueg / name: Manuel Rüger (23aa746)

@mrueg mrueg requested a review from Copilot May 12, 2026 20:48
@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. and removed cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels May 12, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 8 changed files in this pull request and generated 9 comments.

Comment thread Makefile Outdated
Comment thread Makefile Outdated
Comment thread Makefile Outdated
Comment thread Makefile Outdated
Comment thread .goreleaser.yaml Outdated
Comment thread .goreleaser.yaml Outdated
Comment thread .github/workflows/ci.yml Outdated
Comment thread .github/workflows/ci.yml Outdated
Comment thread SECURITY-INSIGHTS.yml
@mrueg mrueg force-pushed the goreleaser-container-builds branch 4 times, most recently from dde6e90 to f78b385 Compare May 18, 2026 15:13
@mrueg mrueg changed the title WIP: build: replace Docker-based image build with goreleaser/ko build: replace Docker-based image build with goreleaser/ko May 18, 2026
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label May 18, 2026
@mrueg mrueg force-pushed the goreleaser-container-builds branch from f78b385 to 39232a7 Compare May 18, 2026 15:14
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels May 18, 2026
@mrueg mrueg force-pushed the goreleaser-container-builds branch 4 times, most recently from a8b84e5 to 47cfddf Compare May 18, 2026 16:04
@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. and removed cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels May 18, 2026
@mrueg mrueg force-pushed the goreleaser-container-builds branch from 4454285 to 23aa746 Compare May 18, 2026 21:03
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels May 18, 2026
@mrueg mrueg requested a review from Copilot May 18, 2026 21:05
@mrueg mrueg force-pushed the goreleaser-container-builds branch from 23aa746 to 61b0af6 Compare May 18, 2026 21:05
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 9 changed files in this pull request and generated 5 comments.

Comment thread Makefile Outdated
# Need to update git setting to prevent failing builds due to https://github.com/docker-library/golang/issues/452
${DOCKER_CLI} run --rm -v "${PWD}:/go/src/k8s.io/kube-state-metrics" -w /go/src/k8s.io/kube-state-metrics -e GOOS=$(OS) -e GOARCH=$(ARCH) golang:${GO_VERSION} git config --global --add safe.directory "*" && make build-local
build:
GOOS=$(shell uname -s | tr A-Z a-z) GOARCH=$(ARCH) goreleaser build --single-target --clean --snapshot
Comment thread Makefile Outdated
Comment on lines +107 to +111
container: all-container

do-push-%:
${DOCKER_CLI} push $(IMAGE)-$*:$(TAG)
all-container:
K8S_CLIENT_VERSION=$(CLIENT_GO_VERSION) \
goreleaser release --snapshot --clean --skip=archive,announce,publish
Comment thread scripts/generate-help-text.sh Outdated
case "$GOARCH" in
amd64) VARIANT="_$(go env GOAMD64)" ;;
arm) VARIANT="_$(go env GOARM)" ;;
arm64) VARIANT="_$(go_env GOARM64)" ;;
Comment thread SECURITY-INSIGHTS.yml
@@ -31,7 +31,6 @@ dependencies:
third-party-packages: true
dependencies-lists:
- https://github.com/kubernetes/kube-state-metrics/blob/main/go.mod
Comment thread .goreleaser.yaml
env:
- CGO_ENABLED=0
goos:
- linux
Replace the manual Dockerfile-based multi-arch container build pipeline
with goreleaser and ko:

- Remove Dockerfile; container images are now built via ko in goreleaser
- Add build and kos sections to .goreleaser.yaml with multi-arch support
  (amd64, arm/v6, arm/v7, arm64, ppc64le, s390x) using distroless base
- Simplify Makefile: replace docker-based build/push targets with
  goreleaser equivalents; remove ALL_ARCH loop and manifest logic
- Update CI workflow to use goreleaser-action for the build job and
  extract client-go version for ldflags injection
- Update generate-help-text.sh to reference the goreleaser dist output path
- Update e2e.sh to use the unified image name (drop arch suffix)
- Add /dist to .gitignore
- Remove Dockerfile reference from SECURITY-INSIGHTS.yml
@mrueg mrueg force-pushed the goreleaser-container-builds branch from 61b0af6 to dd7e79b Compare May 18, 2026 23:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

Status: Needs Triage

Development

Successfully merging this pull request may close these issues.

3 participants