From a37d38a864bb211d3dcd07926de03de1beb5c46a Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Sun, 21 Aug 2022 16:58:22 +0200 Subject: [PATCH] Set version and revision at linked time Signed-off-by: CrazyMax --- Dockerfile | 17 ++++++++++------- Makefile | 24 ++++++++++++++---------- credentials/credentials.go | 2 +- credentials/version.go | 16 ++++++++++++++-- 4 files changed, 39 insertions(+), 20 deletions(-) diff --git a/Dockerfile b/Dockerfile index 78bd902..ebc1269 100644 --- a/Dockerfile +++ b/Dockerfile @@ -60,8 +60,8 @@ RUN --mount=type=bind,target=. \ FROM gobase AS version ARG PKG RUN --mount=target=. \ - VERSION=$(git describe --match 'v[0-9]*' --dirty='.m' --always --tags); \ - echo "-s -w -X ${PKG}/credentials.Version=${VERSION}" | tee /tmp/.ldflags; \ + VERSION=$(git describe --match 'v[0-9]*' --dirty='.m' --always --tags) REVISION=$(git rev-parse HEAD)$(if ! git diff --no-ext-diff --quiet --exit-code; then echo .m; fi); \ + echo "-s -w -X ${PKG}/credentials.Version=${VERSION} -X ${PKG}/credentials.Revision=${REVISION} -X ${PKG}/credentials.Package=${PKG}" | tee /tmp/.ldflags; \ echo -n "${VERSION}" | tee /tmp/.version; FROM gobase AS base @@ -93,6 +93,7 @@ FROM scratch AS test-coverage COPY --from=test /out / FROM base AS build-linux +ARG PKG ARG TARGETOS ARG TARGETARCH ARG TARGETVARIANT @@ -102,13 +103,14 @@ RUN --mount=type=bind,target=. \ --mount=type=bind,from=version,source=/tmp/.ldflags,target=/tmp/.ldflags <