From 37a78902db9e968d307d0c0325612e8bef20bc69 Mon Sep 17 00:00:00 2001 From: Shawn Siefkas Date: Mon, 1 Apr 2013 13:12:56 -0500 Subject: [PATCH 1/3] Adding git commit to the version output The Makefile must be used in order to inject the git commit via -ldflags. --- Makefile | 4 +++- commands.go | 3 +++ docker/docker.go | 3 +++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index e716762d31..8bd6b72e07 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,8 @@ ifeq ($(VERBOSE), 1) GO_OPTIONS += -v endif +BUILD_OPTIONS = -ldflags "-X main.GIT_COMMIT `git rev-parse HEAD`" + SRC_DIR := $(GOPATH)/src DOCKER_DIR := $(SRC_DIR)/$(DOCKER_PACKAGE) @@ -24,7 +26,7 @@ all: $(DOCKER_BIN) $(DOCKER_BIN): $(DOCKER_DIR) @mkdir -p $(dir $@) - @(cd $(DOCKER_MAIN); go get $(GO_OPTIONS); go build $(GO_OPTIONS) -o $@) + @(cd $(DOCKER_MAIN); go get $(GO_OPTIONS); go build $(GO_OPTIONS) $(BUILD_OPTIONS) -o $@) @echo $(DOCKER_BIN_RELATIVE) is created. $(DOCKER_DIR): diff --git a/commands.go b/commands.go index 99d0c341e5..6b089bb534 100644 --- a/commands.go +++ b/commands.go @@ -21,6 +21,8 @@ import ( const VERSION = "0.1.0" +var GIT_COMMIT string + func (srv *Server) Name() string { return "docker" } @@ -128,6 +130,7 @@ func (srv *Server) CmdWait(stdin io.ReadCloser, stdout io.Writer, args ...string // 'docker version': show version information func (srv *Server) CmdVersion(stdin io.ReadCloser, stdout io.Writer, args ...string) error { fmt.Fprintf(stdout, "Version:%s\n", VERSION) + fmt.Fprintf(stdout, "Git Commit:%s\n", GIT_COMMIT) return nil } diff --git a/docker/docker.go b/docker/docker.go index 1b7e322a4f..998059b849 100644 --- a/docker/docker.go +++ b/docker/docker.go @@ -10,6 +10,8 @@ import ( "os" ) +var GIT_COMMIT string + func main() { if docker.SelfPath() == "/sbin/init" { // Running in init mode @@ -21,6 +23,7 @@ func main() { flDebug := flag.Bool("D", false, "Debug mode") flag.Parse() rcli.DEBUG_FLAG = *flDebug + docker.GIT_COMMIT = GIT_COMMIT if *flDaemon { if flag.NArg() != 0 { flag.Usage() From e566b89a5f13f36fad2e2bb37faf9079e06e051e Mon Sep 17 00:00:00 2001 From: Shawn Siefkas Date: Mon, 1 Apr 2013 16:31:33 -0500 Subject: [PATCH 2/3] Shortening the git commit used in the version command --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 8bd6b72e07..2eacedf61d 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ ifeq ($(VERBOSE), 1) GO_OPTIONS += -v endif -BUILD_OPTIONS = -ldflags "-X main.GIT_COMMIT `git rev-parse HEAD`" +BUILD_OPTIONS = -ldflags "-X main.GIT_COMMIT `git rev-parse --short HEAD`" SRC_DIR := $(GOPATH)/src From 5471f5b2ee4bd637147a1ea1dce716670b50796d Mon Sep 17 00:00:00 2001 From: Shawn Siefkas Date: Tue, 2 Apr 2013 09:38:08 -0500 Subject: [PATCH 3/3] Implementing dirty git checkout indicator --- Makefile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 2eacedf61d..06c85e7888 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,10 @@ ifeq ($(VERBOSE), 1) GO_OPTIONS += -v endif -BUILD_OPTIONS = -ldflags "-X main.GIT_COMMIT `git rev-parse --short HEAD`" +GIT_COMMIT = $(shell git rev-parse --short HEAD) +GIT_STATUS = $(shell test -n "`git status --porcelain`" && echo "+CHANGES") + +BUILD_OPTIONS = -ldflags "-X main.GIT_COMMIT $(GIT_COMMIT)$(GIT_STATUS)" SRC_DIR := $(GOPATH)/src