File tree Expand file tree Collapse file tree 3 files changed +27
-3
lines changed
Expand file tree Collapse file tree 3 files changed +27
-3
lines changed Original file line number Diff line number Diff line change 7575 username : ${{ github.actor }}
7676 password : ${{ secrets.GITHUB_TOKEN }}
7777
78+ - name : Compute short SHA
79+ run : echo "SHORT_SHA=${GITHUB_SHA::7}" >> "$GITHUB_ENV"
80+
7881 - name : Build container image
7982 uses : docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
8083 with :
8891 cache-from : type=gha
8992 cache-to : type=gha,mode=max
9093 outputs : type=oci,dest=container-image.tar
94+ build-args : |
95+ VERSION=${{ env.SHORT_SHA }}
96+ GIT_COMMIT=${{ github.sha }}
97+ BUILD_DATE=${{ github.event.head_commit.timestamp }}
9198
9299 - name : Push to registry (sha)
93100 run : |
Original file line number Diff line number Diff line change @@ -8,6 +8,12 @@ FROM --platform=$BUILDPLATFORM golang:1.25.7-alpine3.23 AS builder
88ARG TARGETOS
99ARG TARGETARCH
1010
11+ # Version metadata injected at build time via --build-arg.
12+ # Defaults ensure a plain `docker build .` still works.
13+ ARG VERSION=dev
14+ ARG GIT_COMMIT=unknown
15+ ARG BUILD_DATE=unknown
16+
1117WORKDIR /workspace
1218# Copy the Go Modules manifests
1319COPY go.mod go.mod
@@ -26,7 +32,10 @@ RUN CGO_ENABLED=0 \
2632 GOOS=${TARGETOS:-linux} \
2733 GOARCH=${TARGETARCH} \
2834 go build \
29- -ldflags '-s -w -buildid=' \
35+ -ldflags "-s -w -buildid= \
36+ -X main.version=${VERSION} \
37+ -X main.gitCommit=${GIT_COMMIT} \
38+ -X main.buildDate=${BUILD_DATE}" \
3039 -trimpath -mod=readonly \
3140 -a -o manager \
3241 cmd/multigres-operator/main.go
Original file line number Diff line number Diff line change @@ -270,7 +270,11 @@ run: manifests generate fmt vet ## Run a controller from your host.
270270# Use docker-buildx target or pass --platform to docker build for multi-arch images.
271271.PHONY : container
272272container : # # Build container image
273- $(CONTAINER_TOOL ) build -t ${IMG} .
273+ $(CONTAINER_TOOL ) build \
274+ --build-arg VERSION=$$(git rev-parse --short HEAD ) \
275+ --build-arg GIT_COMMIT=$$(git rev-parse HEAD ) \
276+ --build-arg BUILD_DATE=$$(date -u +%Y-%m-%dT%H:%M:%SZ ) \
277+ -t ${IMG} .
274278
275279.PHONY : minikube-load
276280minikube-load :
@@ -286,7 +290,11 @@ PLATFORMS ?= linux/arm64,linux/amd64
286290docker-buildx : # # Build and push docker image for cross-platform support
287291 - $(CONTAINER_TOOL ) buildx create --name multigres-operator-builder
288292 $(CONTAINER_TOOL ) buildx use multigres-operator-builder
289- - $(CONTAINER_TOOL ) buildx build --push --platform=$(PLATFORMS ) --tag ${IMG} .
293+ - $(CONTAINER_TOOL ) buildx build --push --platform=$(PLATFORMS ) \
294+ --build-arg VERSION=$$(git rev-parse --short HEAD ) \
295+ --build-arg GIT_COMMIT=$$(git rev-parse HEAD ) \
296+ --build-arg BUILD_DATE=$$(date -u +%Y-%m-%dT%H:%M:%SZ ) \
297+ --tag ${IMG} .
290298 - $(CONTAINER_TOOL ) buildx rm multigres-operator-builder
291299
292300.PHONY : build-installer
You can’t perform that action at this time.
0 commit comments