From 627208da4e54d302ed4698fb6847e4dbbb3d64a4 Mon Sep 17 00:00:00 2001 From: Pier-Olivier Thibault <23230+pier-oliviert@users.noreply.github.com> Date: Sun, 17 Nov 2024 08:13:17 -0500 Subject: [PATCH] fix(build): Export version to the right ldflag path Go silently ignore values passed by `ldflags -X` and resulted in release not carrying version numbers for the hardcoded values in the binary. Maybe this way of packaging version should be revisited as it had a bunch of issues with deployment, but maybe it's just one of those things that are hard to get right but once it is, it becomes stable. --- Dockerfile.controller | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile.controller b/Dockerfile.controller index 84bb7fb..ed5f995 100644 --- a/Dockerfile.controller +++ b/Dockerfile.controller @@ -2,6 +2,7 @@ FROM golang:1.23 AS source ARG TARGETOS ARG TARGETARCH +ARG PROVIDER_VERSION WORKDIR /workspace # Copy the Go Modules manifests @@ -19,7 +20,7 @@ COPY pkg/ pkg/ COPY internal/ internal/ COPY cmd/controller/main.go cmd/main.go -RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -ldflags="-X 'providers.ProviderVersion=${PROVIDER_VERSION}'" -a -o controller cmd/main.go +RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -ldflags="-X 'github.com/pier-oliviert/phonebook/pkg/providers.ProviderVersion=${PROVIDER_VERSION}'" -a -o controller cmd/main.go # Use distroless as minimal base image to package the controller binary