From d56fca96ed3174ffa0eeab1fe1a96cbae7ce1c9e Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Wed, 6 Mar 2019 12:06:15 -0800 Subject: [PATCH] pkg/version: Include the commit hash And include that hash in the 'openshift version' and log output. This makes it easier to troubleshoot reports from official builds, which currently reference internal tags: $ RELEASE=quay.io/openshift-release-dev/ocp-release:4.0.0-0.7 $ INSTALLER="$(oc adm release info "${RELEASE}" --image-for installer)" $ oc image extract "${INSTALLER}" --file=/usr/bin/openshift-install $ chmod +x openshift-install $ ./openshift-install version ./openshift-install v4.0.15-1-dirty although you can currently extract the commit given the pullspec and access to the backing registry: $ oc image info --output=json "${INSTALLER}" | jq -r '.config.config.Labels["io.openshift.build.commit.id"]' c8b3b5532694c7713efe300a636108174d623c52 --- cmd/openshift-install/log.go | 3 +++ cmd/openshift-install/version.go | 3 +++ hack/build.sh | 2 +- pkg/version/version.go | 4 ++++ 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/cmd/openshift-install/log.go b/cmd/openshift-install/log.go index 526a8560ed..0c76500177 100644 --- a/cmd/openshift-install/log.go +++ b/cmd/openshift-install/log.go @@ -68,6 +68,9 @@ func setupFileHook(baseDir string) func() { })) logrus.Debugf(version.String) + if version.Commit != "" { + logrus.Debugf("Built from commit %s", version.Commit) + } return func() { logfile.Close() diff --git a/cmd/openshift-install/version.go b/cmd/openshift-install/version.go index 30d09b9299..504ea591e7 100644 --- a/cmd/openshift-install/version.go +++ b/cmd/openshift-install/version.go @@ -21,5 +21,8 @@ func newVersionCmd() *cobra.Command { func runVersionCmd(cmd *cobra.Command, args []string) error { fmt.Printf("%s %s\n", os.Args[0], version.Raw) + if version.Commit != "" { + fmt.Printf("built from commit %s\n", version.Commit) + } return nil } diff --git a/hack/build.sh b/hack/build.sh index 8b79ed465e..ad9063dc9b 100755 --- a/hack/build.sh +++ b/hack/build.sh @@ -31,7 +31,7 @@ then fi MODE="${MODE:-release}" -LDFLAGS="${LDFLAGS} -X github.com/openshift/installer/pkg/version.Raw=$(git describe --always --abbrev=40 --dirty)" +LDFLAGS="${LDFLAGS} -X github.com/openshift/installer/pkg/version.Raw=$(git describe --always --abbrev=40 --dirty) -X github.com/openshift/installer/pkg/version.Commit=$(git rev-parse --verify 'HEAD^{commit}')" TAGS="${TAGS:-}" OUTPUT="${OUTPUT:-bin/openshift-install}" export CGO_ENABLED=0 diff --git a/pkg/version/version.go b/pkg/version/version.go index 625009a477..867ea108f5 100644 --- a/pkg/version/version.go +++ b/pkg/version/version.go @@ -11,4 +11,8 @@ var ( // String is the human-friendly representation of the version. String = fmt.Sprintf("OpenShift Installer %s", Raw) + + // Commit is the commit hash from which the installer was built. + // Set in hack/build.sh. + Commit = "" )