build: replace Docker-based image build with goreleaser/ko#2956
Conversation
|
This issue is currently awaiting triage. If kube-state-metrics contributors determine this is a relevant issue, they will accept it by applying the The DetailsInstructions 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. |
|
[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 DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
1244837 to
b486c0f
Compare
There was a problem hiding this comment.
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 +
koconfiguration for multi-arch image builds in.goreleaser.yaml. - Updates
Makefiletargets to use GoReleaser forbuild,container,all-container, andpush, 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.
| 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" }} |
|
|
dde6e90 to
f78b385
Compare
f78b385 to
39232a7
Compare
a8b84e5 to
47cfddf
Compare
4454285 to
23aa746
Compare
23aa746 to
61b0af6
Compare
| # 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 |
| 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 |
| case "$GOARCH" in | ||
| amd64) VARIANT="_$(go env GOAMD64)" ;; | ||
| arm) VARIANT="_$(go env GOARM)" ;; | ||
| arm64) VARIANT="_$(go_env GOARM64)" ;; |
| @@ -31,7 +31,6 @@ dependencies: | |||
| third-party-packages: true | |||
| dependencies-lists: | |||
| - https://github.com/kubernetes/kube-state-metrics/blob/main/go.mod | |||
| 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
61b0af6 to
dd7e79b
Compare
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:
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 #