File tree Expand file tree Collapse file tree 2 files changed +7
-3
lines changed Expand file tree Collapse file tree 2 files changed +7
-3
lines changed Original file line number Diff line number Diff line change 22FROM golang:1.21 AS builder
33ARG TARGETOS
44ARG TARGETARCH
5+ ARG BUILD_VERSION=Unknown
6+ ARG BUILD_DATE=Unknown
57
68WORKDIR /workspace
79# Copy the Go Modules manifests
@@ -22,7 +24,9 @@ COPY pkg/ pkg/
2224# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
2325# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
2426# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
25- RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/main.go
27+ RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a \
28+ -ldflags "-X 'main.BuildVersion=${BUILD_VERSION}' -X 'main.BuildDate=${BUILD_DATE}'" \
29+ -o manager cmd/main.go
2630
2731# Use distroless as minimal base image to package the manager binary
2832# Refer to https://github.com/GoogleContainerTools/distroless for more details
Original file line number Diff line number Diff line change @@ -139,7 +139,7 @@ build: manifests generate fmt vet ## Build manager binary.
139139# More info: https://docs.docker.com/develop/develop-images/build_enhancements/
140140.PHONY : docker-build
141141docker-build : # # Build docker image with the manager.
142- $(CONTAINER_TOOL ) build -t ${IMG} .
142+ $(CONTAINER_TOOL ) build --build-arg= ' BUILD_VERSION=$(BUILD_VERSION) ' --build-arg= ' BUILD_DATE=$(BUILD_DATE) ' - t ${IMG} .
143143
144144.PHONY : docker-push
145145docker-push : # # Push docker image with the manager.
@@ -162,7 +162,7 @@ docker-buildx: ## Build and push docker image for the manager for cross-platform
162162 sed -e ' 1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
163163 - $(CONTAINER_TOOL ) buildx create --name project-v3-builder
164164 $(CONTAINER_TOOL ) buildx use project-v3-builder
165- - $(CONTAINER_TOOL ) buildx build --push --platform=$(PLATFORMS ) --tag ${IMG} -f Dockerfile.cross .
165+ - $(CONTAINER_TOOL ) buildx build --build-arg= ' BUILD_VERSION=$(BUILD_VERSION) ' --build-arg= ' BUILD_DATE=$(BUILD_DATE) ' -- push --platform=$(PLATFORMS ) --tag ${IMG} -f Dockerfile.cross .
166166 - $(CONTAINER_TOOL ) buildx rm project-v3-builder
167167 rm Dockerfile.cross
168168
You can’t perform that action at this time.
0 commit comments