File tree 2 files changed +7
-3
lines changed
2 files changed +7
-3
lines changed Original file line number Diff line number Diff line change 2
2
FROM golang:1.21 AS builder
3
3
ARG TARGETOS
4
4
ARG TARGETARCH
5
+ ARG BUILD_VERSION=Unknown
6
+ ARG BUILD_DATE=Unknown
5
7
6
8
WORKDIR /workspace
7
9
# Copy the Go Modules manifests
@@ -22,7 +24,9 @@ COPY pkg/ pkg/
22
24
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
23
25
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
24
26
# 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
26
30
27
31
# Use distroless as minimal base image to package the manager binary
28
32
# 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.
139
139
# More info: https://docs.docker.com/develop/develop-images/build_enhancements/
140
140
.PHONY : docker-build
141
141
docker-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} .
143
143
144
144
.PHONY : docker-push
145
145
docker-push : # # Push docker image with the manager.
@@ -162,7 +162,7 @@ docker-buildx: ## Build and push docker image for the manager for cross-platform
162
162
sed -e ' 1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
163
163
- $(CONTAINER_TOOL ) buildx create --name project-v3-builder
164
164
$(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 .
166
166
- $(CONTAINER_TOOL ) buildx rm project-v3-builder
167
167
rm Dockerfile.cross
168
168
You can’t perform that action at this time.
0 commit comments