From febace363393aba466429489e2419fb1560935d3 Mon Sep 17 00:00:00 2001 From: Kenfe-Mickael Laventure Date: Fri, 18 Mar 2016 15:29:22 -0700 Subject: [PATCH] Add the git commit to the output version Signed-off-by: Kenfe-Mickael Laventure --- Makefile | 8 ++++++-- containerd/main.go | 7 ++++++- ctr/main.go | 6 +++++- version.go | 2 ++ 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index a3adac9..234b235 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,9 @@ BUILDTAGS= +GIT_COMMIT := $(shell git rev-parse HEAD 2> /dev/null || true) + +LDFLAGS := "-X github.com/docker/containerd.GitCommit=${GIT_COMMIT} ${LDFLAGS}" + # if this session isn't interactive, then we don't want to allocate a # TTY, which would fail, but if it is interactive, we do want to attach # so that the user can send e.g. ^C through. @@ -22,10 +26,10 @@ clean: rm -rf bin client: bin - cd ctr && go build -o ../bin/ctr + cd ctr && go build -ldflags ${LDFLAGS} -o ../bin/ctr daemon: bin - cd containerd && go build -tags "$(BUILDTAGS)" -o ../bin/containerd + cd containerd && go build -ldflags ${LDFLAGS} -tags "$(BUILDTAGS)" -o ../bin/containerd shim: bin cd containerd-shim && go build -tags "$(BUILDTAGS)" -o ../bin/containerd-shim diff --git a/containerd/main.go b/containerd/main.go index e7ddcfb..d8d54e8 100644 --- a/containerd/main.go +++ b/containerd/main.go @@ -1,6 +1,7 @@ package main import ( + "fmt" "net" "os" "sync" @@ -52,7 +53,11 @@ func main() { appendPlatformFlags() app := cli.NewApp() app.Name = "containerd" - app.Version = containerd.Version + if containerd.GitCommit != "" { + app.Version = fmt.Sprintf("%s commit: %s", containerd.Version, containerd.GitCommit) + } else { + app.Version = containerd.Version + } app.Usage = usage app.Flags = daemonFlags setAppBefore(app) diff --git a/ctr/main.go b/ctr/main.go index d81960b..2837e39 100644 --- a/ctr/main.go +++ b/ctr/main.go @@ -14,7 +14,11 @@ const usage = `High performance container daemon cli` func main() { app := cli.NewApp() app.Name = "ctr" - app.Version = containerd.Version + if containerd.GitCommit != "" { + app.Version = fmt.Sprintf("%s commit: %s", containerd.Version, containerd.GitCommit) + } else { + app.Version = containerd.Version + } app.Usage = usage app.Flags = []cli.Flag{ cli.BoolFlag{ diff --git a/version.go b/version.go index f0eda81..0976245 100644 --- a/version.go +++ b/version.go @@ -1,3 +1,5 @@ package containerd const Version = "0.0.5" + +var GitCommit = ""