From 1700cee8546834228defbc6744a969e61b10ccf3 Mon Sep 17 00:00:00 2001 From: Kian Parvin <46668016+kian99@users.noreply.github.com> Date: Tue, 4 Jul 2023 09:44:45 +0200 Subject: [PATCH] Added build tag to include version info in Docker build (#983) --- Dockerfile | 2 +- cmd/jimmsrv/main.go | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 82e2c534d..a9bff8391 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,7 +20,7 @@ COPY . . RUN echo "${GIT_COMMIT}" | tee ./version/commit.txt RUN echo "${VERSION}" | tee ./version/version.txt RUN --mount=type=ssh source /root/.gvm/scripts/gvm && go mod vendor -RUN --mount=type=ssh source /root/.gvm/scripts/gvm && go build -o jimmsrv -race -v -a -mod vendor ./cmd/jimmsrv +RUN --mount=type=ssh source /root/.gvm/scripts/gvm && go build -tags version -o jimmsrv -v -a -mod vendor ./cmd/jimmsrv # Define a smaller single process image for deployment FROM ${DOCKER_REGISTRY}ubuntu:20.04 AS deploy-env diff --git a/cmd/jimmsrv/main.go b/cmd/jimmsrv/main.go index 1db21faaf..c5f2d3054 100644 --- a/cmd/jimmsrv/main.go +++ b/cmd/jimmsrv/main.go @@ -15,6 +15,7 @@ import ( "go.uber.org/zap" "github.com/CanonicalLtd/jimm" + "github.com/CanonicalLtd/jimm/version" ) func main() { @@ -32,6 +33,10 @@ func main() { // start initialises the jimmsrv service. func start(ctx context.Context, s *service.Service) error { + zapctx.Info(ctx, "jimm info", + zap.String("version", version.VersionInfo.Version), + zap.String("commit", version.VersionInfo.GitCommit), + ) if logLevel := os.Getenv("JIMM_LOG_LEVEL"); logLevel != "" { if err := zapctx.LogLevel.UnmarshalText([]byte(logLevel)); err != nil { zapctx.Error(ctx, "cannot set log level", zap.Error(err))