feat: binaries know their build date and commit hash

Will be used for a future metric reporting exporter infos.
This commit is contained in:
Thibault VINCENT
2022-09-17 14:06:17 +02:00
parent 06d52fcfae
commit e5ff47e3d0
3 changed files with 9 additions and 4 deletions

View File

@@ -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

View File

@@ -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()
}

View File

@@ -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 = ""