From 829658ae4df6bd8a7d16486344e75483c973db32 Mon Sep 17 00:00:00 2001 From: Dan Sosedoff Date: Tue, 6 Dec 2022 17:55:27 -0600 Subject: [PATCH] Include build arch info into binary --- Makefile | 2 ++ pkg/command/version.go | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/Makefile b/Makefile index d392545..d470dbe 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ PKG = github.com/sosedoff/pgweb GIT_COMMIT ?= $(shell git rev-parse HEAD) BUILD_TIME ?= $(shell date -u +"%Y-%m-%dT%H:%M:%SZ" | tr -d '\n') +BUILD_ARCH ?= $(shell uname -s | awk '{print tolower($0)}')/$(shell uname -m) GO_VERSION ?= $(shell go version | awk {'print $$3'}) DOCKER_RELEASE_TAG = "sosedoff/pgweb:$(shell git describe --abbrev=0 --tags | sed 's/v//')" @@ -9,6 +10,7 @@ DOCKER_LATEST_TAG = "sosedoff/pgweb:latest" LDFLAGS = -s -w LDFLAGS += -X $(PKG)/pkg/command.GitCommit=$(GIT_COMMIT) LDFLAGS += -X $(PKG)/pkg/command.BuildTime=$(BUILD_TIME) +LDFLAGS += -X $(PKG)/pkg/command.BuildArch=$(BUILD_ARCH) LDFLAGS += -X $(PKG)/pkg/command.GoVersion=$(GO_VERSION) usage: diff --git a/pkg/command/version.go b/pkg/command/version.go index 2f4404d..92cb1cf 100644 --- a/pkg/command/version.go +++ b/pkg/command/version.go @@ -17,6 +17,9 @@ var ( // BuildTime contains the binary build time BuildTime string + // BuildArch contains the OS architecture of the binary + BuildArch string + // GoVersion contains the build time Go version GoVersion string @@ -29,12 +32,14 @@ type VersionInfo struct { GitCommit string `json:"git_sha"` BuildTime string `json:"build_time"` GoVersion string `json:"go_version"` + BuildArch string `json:"build_arch"` } func init() { Info.Version = Version Info.GitCommit = GitCommit Info.BuildTime = BuildTime + Info.BuildArch = BuildArch Info.GoVersion = GoVersion } @@ -50,6 +55,9 @@ func VersionString() string { if BuildTime != "" { chunks = append(chunks, fmt.Sprintf("(build time: %s)", BuildTime)) } + if BuildArch != "" { + chunks = append(chunks, fmt.Sprintf("(arch: %s)", BuildArch)) + } return strings.Join(chunks, " ") }