diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f8a14291..23dbfc7a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -83,6 +83,17 @@ jobs: # stage via buildx cache. Each image is published at # ghcr.io// with the release tag and `latest`. + # Mirrors GoReleaser's {{.Version}} / {{.Commit}} / {{.Date}} so + # binaries inside the images report the same buildinfo as the + # tarball binaries. + - name: Compute Docker build metadata + run: | + { + echo "BUILD_VERSION=${GITHUB_REF_NAME#v}" + echo "BUILD_COMMIT=${GITHUB_SHA}" + echo "BUILD_DATE=$(date -u +%Y-%m-%dT%H:%M:%SZ)" + } >> "$GITHUB_ENV" + - name: Docker meta — prosa (CLI) id: meta-cli uses: docker/metadata-action@v6 @@ -101,6 +112,10 @@ jobs: push: true tags: ${{ steps.meta-cli.outputs.tags }} labels: ${{ steps.meta-cli.outputs.labels }} + build-args: | + VERSION=${{ env.BUILD_VERSION }} + COMMIT=${{ env.BUILD_COMMIT }} + BUILD_DATE=${{ env.BUILD_DATE }} - name: Docker meta — prosa-server id: meta-server @@ -120,6 +135,10 @@ jobs: push: true tags: ${{ steps.meta-server.outputs.tags }} labels: ${{ steps.meta-server.outputs.labels }} + build-args: | + VERSION=${{ env.BUILD_VERSION }} + COMMIT=${{ env.BUILD_COMMIT }} + BUILD_DATE=${{ env.BUILD_DATE }} - name: Docker meta — prosa-panel id: meta-panel @@ -139,3 +158,7 @@ jobs: push: true tags: ${{ steps.meta-panel.outputs.tags }} labels: ${{ steps.meta-panel.outputs.labels }} + build-args: | + VERSION=${{ env.BUILD_VERSION }} + COMMIT=${{ env.BUILD_COMMIT }} + BUILD_DATE=${{ env.BUILD_DATE }} diff --git a/Dockerfile b/Dockerfile index d5d416a9..7012194b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,12 +4,21 @@ ARG GO_VERSION=1.26.2 FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-bookworm AS build ARG TARGETOS ARG TARGETARCH +# Build metadata mirroring the GoReleaser ldflags so image binaries +# report a real version instead of "dev (none, unknown)". +ARG VERSION=dev +ARG COMMIT=none +ARG BUILD_DATE=unknown WORKDIR /src COPY go.mod go.sum ./ RUN go mod download COPY . . RUN mkdir -p /out && CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH \ - go build -ldflags='-s -w' -o /out/ ./cmd/... + go build -ldflags="-s -w \ + -X github.com/c3-oss/prosa/internal/buildinfo.Version=${VERSION} \ + -X github.com/c3-oss/prosa/internal/buildinfo.Commit=${COMMIT} \ + -X github.com/c3-oss/prosa/internal/buildinfo.BuildDate=${BUILD_DATE}" \ + -o /out/ ./cmd/... FROM gcr.io/distroless/static-debian12 AS prosa COPY --from=build /out/prosa /usr/local/bin/prosa diff --git a/docs/distribution/docker.md b/docs/distribution/docker.md index b9c095ca..7bfba6a5 100644 --- a/docs/distribution/docker.md +++ b/docs/distribution/docker.md @@ -31,12 +31,21 @@ ARG GO_VERSION=1.26.2 FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-bookworm AS build ARG TARGETOS ARG TARGETARCH +# Build metadata mirroring the GoReleaser ldflags so image binaries +# report a real version instead of "dev (none, unknown)". +ARG VERSION=dev +ARG COMMIT=none +ARG BUILD_DATE=unknown WORKDIR /src COPY go.mod go.sum ./ RUN go mod download COPY . . RUN mkdir -p /out && CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH \ - go build -ldflags='-s -w' -o /out/ ./cmd/... + go build -ldflags="-s -w \ + -X github.com/c3-oss/prosa/internal/buildinfo.Version=${VERSION} \ + -X github.com/c3-oss/prosa/internal/buildinfo.Commit=${COMMIT} \ + -X github.com/c3-oss/prosa/internal/buildinfo.BuildDate=${BUILD_DATE}" \ + -o /out/ ./cmd/... FROM gcr.io/distroless/static-debian12 AS prosa COPY --from=build /out/prosa /usr/local/bin/prosa @@ -58,6 +67,10 @@ Notes: `--target` invocations. - `CGO_ENABLED=0` keeps the binaries static — distroless has no glibc. - `-s -w` strips debug symbols. +- The release workflow passes `VERSION` / `COMMIT` / `BUILD_DATE` build + args (tag without the `v` prefix, commit SHA, UTC RFC 3339 date) so + `--version` and startup logs match the tarball binaries. Local builds + without the args report `dev (none, unknown)`. - `--platform=$BUILDPLATFORM` lets Buildx cross-compile from one builder; `TARGETOS`/`TARGETARCH` come from `docker buildx build --platform`.