diff --git a/Makefile b/Makefile index 340c8ea2..77f0a5f3 100644 --- a/Makefile +++ b/Makefile @@ -85,7 +85,10 @@ $(SETUP_ENVTEST): .PHONY: operator operator: - CGO_ENABLED=0 go build -o bin/aks-operator main.go + CGO_ENABLED=0 go build -ldflags \ + "-X github.com/rancher/aks-operator/pkg/version.GitCommit=$(GIT_COMMIT) \ + -X github.com/rancher/aks-operator/pkg/version.Version=$(TAG)" \ + -o bin/aks-operator . .PHONY: generate-go generate-go: $(MOCKGEN) @@ -139,7 +142,7 @@ buildx-machine: ## create rancher dockerbuildx machine targeting platform define .PHONY: image-build image-build: buildx-machine ## build (and load) the container image targeting the current platform. docker buildx build -f package/Dockerfile \ - --builder $(MACHINE) --build-arg VERSION=$(TAG) \ + --builder $(MACHINE) --build-arg COMMIT=$(GIT_COMMIT) --build-arg VERSION=$(TAG) \ -t "$(IMAGE)" $(BUILD_ACTION) . @echo "Built $(IMAGE)" diff --git a/package/Dockerfile b/package/Dockerfile index 89cf3061..ab3b104e 100644 --- a/package/Dockerfile +++ b/package/Dockerfile @@ -19,8 +19,14 @@ COPY ./main.go ./main.go COPY --from=xx / / ARG TARGETPLATFORM +ARG COMMIT +ARG VERSION ENV CGO_ENABLED=0 -RUN xx-go build -o /aks-operator && xx-verify /aks-operator +RUN xx-go build -ldflags \ + "-X github.com/rancher/aks-operator/pkg/version.GitCommit=${COMMIT} \ + -X github.com/rancher/aks-operator/pkg/version.Version=${VERSION}" \ + -o /aks-operator && \ + xx-verify /aks-operator FROM registry.suse.com/bci/bci-micro:15.6 COPY --from=base /etc/passwd /etc/passwd