From ee53b1cb000c4bdefc3a5342b5ee5811aec354ff Mon Sep 17 00:00:00 2001 From: Thomas Boni Date: Fri, 21 Aug 2026 08:51:43 +0000 Subject: [PATCH] fix(docker): stamp version metadata into the published image The published Docker image reported "plumber version dev" (commit: none, built: unknown) because the Dockerfile built the binary without the -X ldflags that release.yml applies to the release binaries. Add VERSION / COMMIT / BUILD_DATE build args to the Dockerfile, feed them into -X ldflags on cmd/version.go, and pass them from the release workflow's docker job. Plain builds (ci.yml, local) keep the dev defaults. Fixes #425 Co-Authored-By: Claude Fable 5 --- .github/workflows/release.yml | 12 ++++++++++++ Dockerfile | 12 +++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0682e315..add030a9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -237,6 +237,11 @@ jobs: type=semver,pattern={{major}},value=${{ needs.release.outputs.new_release_version }} type=raw,value=latest + # Same timestamp format as the release binaries' BUILD_DATE above. + - name: Compute build date + id: build_date + run: echo "date=$(date -u +"%Y-%m-%dT%H:%M:%SZ")" >> "$GITHUB_OUTPUT" + - name: Build and push id: push uses: docker/build-push-action@53b7df96c91f9c12dcc8a07bcb9ccacbed38856a # v7.3.0 @@ -246,6 +251,13 @@ jobs: push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + # Stamp version metadata into the binary (Dockerfile ARGs feeding + # -X ldflags on cmd/version.go); without these the image reports + # "plumber version dev" (getplumber/plumber#425). + build-args: | + VERSION=${{ needs.release.outputs.new_release_version }} + COMMIT=${{ github.sha }} + BUILD_DATE=${{ steps.build_date.outputs.date }} cache-from: type=gha cache-to: type=gha,mode=max # Always rebuild the `runtime` stage so `apk upgrade` re-runs and pulls diff --git a/Dockerfile b/Dockerfile index f284fd54..a04286a6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,8 +23,18 @@ RUN go mod download # Copy source code COPY . . +# Version metadata stamped into the binary (cmd/version.go). The release +# workflow passes these as build args so `plumber version` in the published +# image reports the release, matching the ldflags used for the release +# binaries in release.yml. Plain `docker build` (ci.yml, local) keeps the +# dev defaults. Declared here, after the cacheable dependency layers, so a +# changing BUILD_DATE never invalidates `go mod download`. +ARG VERSION=dev +ARG COMMIT=none +ARG BUILD_DATE=unknown + # Build static binary -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o plumber . +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w -X github.com/getplumber/plumber/cmd.Version=${VERSION} -X github.com/getplumber/plumber/cmd.Commit=${COMMIT} -X github.com/getplumber/plumber/cmd.BuildDate=${BUILD_DATE}" -o plumber . # Final stage - Alpine (small, has shell for CI compatibility) # Named `runtime` so CI can target it with build-push-action's `no-cache-filter: