Tweak version display
Signed-off-by: Andy Goldstein <andy.goldstein@gmail.com>pull/82/head
parent
d0b7880881
commit
81fda27440
12
Makefile
12
Makefile
|
@ -21,17 +21,23 @@ OUTPUT_DIR = $(ROOT_DIR)/_output
|
||||||
BIN_DIR = $(OUTPUT_DIR)/bin
|
BIN_DIR = $(OUTPUT_DIR)/bin
|
||||||
GIT_SHA=$(shell git rev-parse --short HEAD)
|
GIT_SHA=$(shell git rev-parse --short HEAD)
|
||||||
GIT_DIRTY=$(shell git status --porcelain $(ROOT_DIR) 2> /dev/null)
|
GIT_DIRTY=$(shell git status --porcelain $(ROOT_DIR) 2> /dev/null)
|
||||||
ifneq ($(GIT_DIRTY),)
|
ifeq ($(GIT_DIRTY),)
|
||||||
GIT_SHA := $(GIT_SHA)-dirty
|
GIT_TREE_STATE := clean
|
||||||
|
else
|
||||||
|
GIT_TREE_STATE := dirty
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# docker related vars
|
# docker related vars
|
||||||
DOCKER ?= docker
|
DOCKER ?= docker
|
||||||
REGISTRY ?= gcr.io/heptio-images
|
REGISTRY ?= gcr.io/heptio-images
|
||||||
BUILD_IMAGE ?= gcr.io/heptio-images/golang:1.8-alpine3.6
|
BUILD_IMAGE ?= gcr.io/heptio-images/golang:1.8-alpine3.6
|
||||||
|
LDFLAGS := -X $(GOTARGET)/pkg/buildinfo.Version=$(VERSION)
|
||||||
|
LDFLAGS += -X $(GOTARGET)/pkg/buildinfo.DockerImage=$(REGISTRY)/$(PROJECT)
|
||||||
|
LDFLAGS += -X $(GOTARGET)/pkg/buildinfo.GitSHA=$(GIT_SHA)
|
||||||
|
LDFLAGS += -X $(GOTARGET)/pkg/buildinfo.GitTreeState=$(GIT_TREE_STATE)
|
||||||
# go build -i installs compiled packages so they can be reused later.
|
# go build -i installs compiled packages so they can be reused later.
|
||||||
# This speeds up recompiles.
|
# This speeds up recompiles.
|
||||||
BUILDCMD = go build -i -v -ldflags "-X $(GOTARGET)/pkg/buildinfo.Version=$(VERSION) -X $(GOTARGET)/pkg/buildinfo.DockerImage=$(REGISTRY)/$(PROJECT) -X $(GOTARGET)/pkg/buildinfo.GitSHA=$(GIT_SHA)"
|
BUILDCMD = go build -i -v -ldflags "$(LDFLAGS)"
|
||||||
BUILDMNT = /go/src/$(GOTARGET)
|
BUILDMNT = /go/src/$(GOTARGET)
|
||||||
EXTRA_MNTS ?=
|
EXTRA_MNTS ?=
|
||||||
|
|
||||||
|
|
|
@ -14,17 +14,23 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Package buildinfo holds build-time information like the sonobuoy version.
|
// Package buildinfo holds build-time information like the ark version.
|
||||||
// This is a separate package so that other packages can import it without
|
// This is a separate package so that other packages can import it without
|
||||||
// worrying about introducing circular dependencies.
|
// worrying about introducing circular dependencies.
|
||||||
package buildinfo
|
package buildinfo
|
||||||
|
|
||||||
// Version is the current version of Ark, set by the go linker's -X flag at build time.
|
var (
|
||||||
var Version string
|
// Version is the current version of Ark, set by the go linker's -X flag at build time.
|
||||||
|
Version string
|
||||||
|
|
||||||
// DockerImage is the full path to the docker image for this build, for example
|
// DockerImage is the full path to the docker image for this build, for example
|
||||||
// gcr.io/heptio-images/ark.
|
// gcr.io/heptio-images/ark.
|
||||||
var DockerImage string
|
DockerImage string
|
||||||
|
|
||||||
// GitSHA is the actual commit that is being built, set by the go linker's -X flag at build time.
|
// GitSHA is the actual commit that is being built, set by the go linker's -X flag at build time.
|
||||||
var GitSHA string
|
GitSHA string
|
||||||
|
|
||||||
|
// GitTreeState indicates if the git tree is clean or dirty, set by the go linker's -X flag at build
|
||||||
|
// time.
|
||||||
|
GitTreeState string
|
||||||
|
)
|
||||||
|
|
|
@ -29,7 +29,9 @@ func NewCommand() *cobra.Command {
|
||||||
Use: "version",
|
Use: "version",
|
||||||
Short: "Print the ark version and associated image",
|
Short: "Print the ark version and associated image",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
fmt.Printf("Version: [%s] - [%s]\n", buildinfo.Version, buildinfo.GitSHA)
|
fmt.Printf("Version: %s\n", buildinfo.Version)
|
||||||
|
fmt.Printf("Git commit: %s\n", buildinfo.GitSHA)
|
||||||
|
fmt.Printf("Git tree state: %s\n", buildinfo.GitTreeState)
|
||||||
fmt.Println("Configured docker image:", buildinfo.DockerImage)
|
fmt.Println("Configured docker image:", buildinfo.DockerImage)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue