From beb3e5e71acb8788ef1d8102add02270e19a0d0b Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Fri, 11 Mar 2016 13:49:45 -0800 Subject: [PATCH] Add gitcommit to runc builds Signed-off-by: Michael Crosby --- Makefile | 5 +++-- main.go | 14 +++++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 8ac8bbe3ef8..efe83af5486 100644 --- a/Makefile +++ b/Makefile @@ -5,16 +5,17 @@ TEST_DOCKERFILE=script/test_Dockerfile BUILDTAGS=seccomp RUNC_BUILD_PATH=/go/src/github.com/opencontainers/runc/runc RUNC_INSTANCE=runc_dev +COMMIT=$(shell git rev-parse HEAD 2> /dev/null || true) export GOPATH:=$(CURDIR)/Godeps/_workspace:$(GOPATH) .PHONY=dbuild all: ln -sfn $(CURDIR) $(CURDIR)/Godeps/_workspace/src/github.com/opencontainers/runc - go build -tags "$(BUILDTAGS)" -o runc . + go build -ldflags "-X main.gitCommit=${COMMIT}" -tags "$(BUILDTAGS)" -o runc . static: - CGO_ENABLED=1 go build -tags "$(BUILDTAGS) cgo static_build" -ldflags "-w -extldflags -static" -o runc . + CGO_ENABLED=1 go build -tags "$(BUILDTAGS) cgo static_build" -ldflags "-w -extldflags -static -X main.gitCommit=${COMMIT}" -o runc . vet: go get golang.org/x/tools/cmd/vet diff --git a/main.go b/main.go index 97d8c8f8864..f8982f6e48d 100644 --- a/main.go +++ b/main.go @@ -3,12 +3,17 @@ package main import ( "fmt" "os" + "strings" "github.com/Sirupsen/logrus" "github.com/codegangsta/cli" "github.com/opencontainers/specs/specs-go" ) +// gitCommit will be the hash that the binary was built from +// and will be populated by the Makefile +var gitCommit = "" + const ( version = "0.0.9" specConfig = "config.json" @@ -41,7 +46,14 @@ func main() { app := cli.NewApp() app.Name = "runc" app.Usage = usage - app.Version = fmt.Sprintf("%s\nspec version %s", version, specs.Version) + v := []string{ + version, + } + if gitCommit != "" { + v = append(v, fmt.Sprintf("commit: %s", gitCommit)) + } + v = append(v, fmt.Sprintf("spec: %s", specs.Version)) + app.Version = strings.Join(v, "\n") app.Flags = []cli.Flag{ cli.BoolFlag{ Name: "debug",