From 08454801e63a61ea81d76b66f4af5e588e7a5b6c Mon Sep 17 00:00:00 2001 From: Ashley Cui Date: Thu, 5 Dec 2024 23:05:19 -0500 Subject: [PATCH] Add BuiltFor field to podman info BuiltFor is a field that can be set at build time by packagers. This helps us trace how and where the binary was built and installed from, allowing us to see if the issue is due to a specfic installation or a general podman bug. This field shows up in podman version and in podman info when populated. Automatically set the BuiltFor field when building the macOS pkginstaller to pkginstaller. Usage: make podman-remote BUILT_FOR="mypackaging" Signed-off-by: Ashley Cui --- Makefile | 1 + cmd/podman/client.go | 2 ++ cmd/podman/system/version.go | 2 ++ contrib/pkginstaller/package.sh | 3 ++- libpod/define/version.go | 5 +++++ 5 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index a17270fe78..077378e729 100644 --- a/Makefile +++ b/Makefile @@ -119,6 +119,7 @@ GOFLAGS ?= -trimpath LDFLAGS_PODMAN ?= \ $(if $(GIT_COMMIT),-X $(LIBPOD)/define.gitCommit=$(GIT_COMMIT),) \ $(if $(BUILD_INFO),-X $(LIBPOD)/define.buildInfo=$(BUILD_INFO),) \ + $(if $(BUILT_FOR),-X $(LIBPOD)/define.builtFor=$(BUILT_FOR),) \ -X $(LIBPOD)/config._installPrefix=$(PREFIX) \ -X $(LIBPOD)/config._etcDir=$(ETCDIR) \ -X $(PROJECT)/v5/pkg/systemd/quadlet._binDir=$(BINDIR) \ diff --git a/cmd/podman/client.go b/cmd/podman/client.go index b42a43520d..cc9e5056f7 100644 --- a/cmd/podman/client.go +++ b/cmd/podman/client.go @@ -6,6 +6,7 @@ type clientInfo struct { OSArch string `json:"OS"` Provider string `json:"provider"` Version string `json:"version"` + BuiltFor string `json:"builtFor,omitempty" yaml:",omitempty"` } func getClientInfo() (*clientInfo, error) { @@ -21,5 +22,6 @@ func getClientInfo() (*clientInfo, error) { OSArch: vinfo.OsArch, Provider: p, Version: vinfo.Version, + BuiltFor: vinfo.BuiltFor, }, nil } diff --git a/cmd/podman/system/version.go b/cmd/podman/system/version.go index 48ea151135..b24db3fd73 100644 --- a/cmd/podman/system/version.go +++ b/cmd/podman/system/version.go @@ -97,6 +97,7 @@ API Version:\t{{.APIVersion}} Go Version:\t{{.GoVersion}} {{if .GitCommit -}}Git Commit:\t{{.GitCommit}}\n{{end -}} Built:\t{{.BuiltTime}} +{{if .BuiltFor -}}Built For:\t{{.BuiltFor}}\n{{end -}} OS/Arch:\t{{.OsArch}} {{- end}} @@ -108,6 +109,7 @@ API Version:\t{{.APIVersion}} Go Version:\t{{.GoVersion}} {{if .GitCommit -}}Git Commit:\t{{.GitCommit}}\n{{end -}} Built:\t{{.BuiltTime}} +{{if .BuiltFor -}}Built For:\t{{.BuiltFor}}\n{{end -}} OS/Arch:\t{{.OsArch}} {{- end}}{{- end}} ` diff --git a/contrib/pkginstaller/package.sh b/contrib/pkginstaller/package.sh index 4d2cd7cd48..12e57f3e27 100755 --- a/contrib/pkginstaller/package.sh +++ b/contrib/pkginstaller/package.sh @@ -9,6 +9,7 @@ PRODUCTSIGN_IDENTITY=${PRODUCTSIGN_IDENTITY:-mock} NO_CODESIGN=${NO_CODESIGN:-0} HELPER_BINARIES_DIR="/opt/podman/bin" MACHINE_POLICY_JSON_DIR="/opt/podman/config" +BUILT_FOR="pkginstaller" tmpBin="contrib/pkginstaller/tmp-bin" @@ -42,7 +43,7 @@ function build_podman() { } function build_podman_arch(){ - make -B GOARCH="$1" podman-remote HELPER_BINARIES_DIR="${HELPER_BINARIES_DIR}" + make -B GOARCH="$1" podman-remote HELPER_BINARIES_DIR="${HELPER_BINARIES_DIR}" BUILT_FOR="${BUILT_FOR}" make -B GOARCH="$1" podman-mac-helper mkdir -p "${tmpBin}" cp bin/darwin/podman "${tmpBin}/podman-$1" diff --git a/libpod/define/version.go b/libpod/define/version.go index 13a8fdb778..0d9b80bc0c 100644 --- a/libpod/define/version.go +++ b/libpod/define/version.go @@ -16,6 +16,9 @@ var ( // BuildInfo is the time at which the binary was built // It will be populated by the Makefile. buildInfo string + // BuiltFor is the packager of the binary. + // It will be populated at build-time. + builtFor string ) // Version is an output struct for API @@ -26,6 +29,7 @@ type Version struct { GitCommit string BuiltTime string Built int64 + BuiltFor string `json:",omitempty" yaml:",omitempty"` OsArch string Os string } @@ -49,6 +53,7 @@ func GetVersion() (Version, error) { GitCommit: gitCommit, BuiltTime: time.Unix(buildTime, 0).Format(time.ANSIC), Built: buildTime, + BuiltFor: builtFor, OsArch: runtime.GOOS + "/" + runtime.GOARCH, Os: runtime.GOOS, }, nil