diff --git a/Makefile b/Makefile index 8ac8bbe3..efe83af5 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 97d8c8f8..f8982f6e 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",