Skip to content

Commit f23a6f5

Browse files
authored
Add build metadata to Docker image (#292)
Signed-off-by: carlory <[email protected]>
1 parent f7d25ad commit f23a6f5

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ RUN ranlib lib/*.a
3434
ENV CGO_ENABLED=1
3535
ENV GOOS=${TARGETOS:-linux}
3636
ENV GOARCH=${TARGETARCH}
37-
RUN go build -a -o bin/epp -ldflags="-extldflags '-L$(pwd)/lib'" cmd/epp/main.go
37+
ARG COMMIT_SHA=unknown
38+
ARG BUILD_REF
39+
RUN go build -a -o bin/epp -ldflags="-extldflags '-L$(pwd)/lib' -X sigs.k8s.io/gateway-api-inference-extension/pkg/epp/metrics.CommitSHA=${COMMIT_SHA} -X sigs.k8s.io/gateway-api-inference-extension/pkg/epp/metrics.BuildRef=${BUILD_REF}" cmd/epp/main.go
3840

3941
# Use ubi9 as a minimal base image to package the manager binary
4042
# Refer to https://catalog.redhat.com/software/containers/ubi9/ubi-minimal/615bd9b4075b022acc111bf5 for more details

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ CONTAINER_TOOL := $(shell { command -v docker >/dev/null 2>&1 && echo docker; }
1717
BUILDER := $(shell command -v buildah >/dev/null 2>&1 && echo buildah || echo $(CONTAINER_TOOL))
1818
PLATFORMS ?= linux/amd64 # linux/arm64 # linux/s390x,linux/ppc64le
1919

20+
GIT_COMMIT_SHA ?= "$(shell git rev-parse HEAD 2>/dev/null)"
21+
BUILD_REF ?= $(shell git describe --abbrev=0 2>/dev/null)
22+
2023
# go source files
2124
SRC = $(shell find . -type f -name '*.go')
2225

@@ -93,6 +96,8 @@ image-build: check-container-tool ## Build Docker image ## Build Docker image us
9396
--platform $(TARGETOS)/$(TARGETARCH) \
9497
--build-arg TARGETOS=$(TARGETOS) \
9598
--build-arg TARGETARCH=$(TARGETARCH) \
99+
--build-arg COMMIT_SHA=${GIT_COMMIT_SHA} \
100+
--build-arg BUILD_REF=${BUILD_REF} \
96101
-t $(IMG) .
97102

98103
.PHONY: image-push

0 commit comments

Comments
 (0)