From e5ff47e3d0c199b739ef5ab62df9851c11bd7721 Mon Sep 17 00:00:00 2001 From: Thibault VINCENT Date: Sat, 17 Sep 2022 14:06:17 +0200 Subject: [PATCH] feat: binaries know their build date and commit hash Will be used for a future metric reporting exporter infos. --- Dockerfile | 7 +++++-- cmd/x509-certificate-exporter/main.go | 2 +- internal/version.go | 4 +++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 0267444..71b7b58 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,8 +19,11 @@ ENV GOOS=${TARGETOS} ENV GOARCH=${TARGETARCH} ARG VERSION="0.0.0" - -RUN go build -tags netgo,osusergo -ldflags "-X \"github.com/enix/x509-certificate-exporter/v3/internal.Version=${VERSION}\"" ./cmd/x509-certificate-exporter + -tags netgo,osusergo \ + -ldflags "-X \"github.com/enix/x509-certificate-exporter/v3/internal.Version=${VERSION}\" \ + -X \"github.com/enix/x509-certificate-exporter/v3/internal.CommitHash=${VCS_REF}\" \ + -X \"github.com/enix/x509-certificate-exporter/v3/internal.BuildDateTime=$(date -u -Iseconds)\"" \ + ./cmd/x509-certificate-exporter ## Production Stage diff --git a/cmd/x509-certificate-exporter/main.go b/cmd/x509-certificate-exporter/main.go index 5aed660..58d96e4 100644 --- a/cmd/x509-certificate-exporter/main.go +++ b/cmd/x509-certificate-exporter/main.go @@ -109,7 +109,7 @@ func main() { } } - log.Infof("starting %s version %s", path.Base(os.Args[0]), internal.Version) + log.Infof("starting %s version %s (%s) (%s)", path.Base(os.Args[0]), internal.Version, internal.CommitHash, internal.BuildDateTime) rand.Seed(time.Now().UnixNano()) exporter.ListenAndServe() } diff --git a/internal/version.go b/internal/version.go index 949c7f3..0b4df61 100644 --- a/internal/version.go +++ b/internal/version.go @@ -1,4 +1,6 @@ package internal -// Version is the exporter semantic version and is set at link time +// Version and build informations set at link time var Version = "0.0.0" +var CommitHash = "" +var BuildDateTime = ""