aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Yong Tang <yong.tang.github@outlook.com> 2017-08-11 09:47:37 -0700
committerGravatar Miek Gieben <miek@miek.nl> 2017-08-11 17:47:37 +0100
commita09f208c51e175e0b3d950e7bdfb8bfb694d61d7 (patch)
tree7e25ed1fdca0a957f61165fe33eed75d55b19fa3
parentebcbe66bbd0ecde3ea5066995389931d24453543 (diff)
downloadcoredns-a09f208c51e175e0b3d950e7bdfb8bfb694d61d7.tar.gz
coredns-a09f208c51e175e0b3d950e7bdfb8bfb694d61d7.tar.zst
coredns-a09f208c51e175e0b3d950e7bdfb8bfb694d61d7.zip
Add git commit to the version output. (#900)
Now the output would be: ``` ./coredns -version CoreDNS-010 linux/amd64, go1.8, 241e3db ``` In case the local file has been modified, then the output would be (with --dirty): ``` ./coredns -version CoreDNS-010 linux/amd64, go1.8, 241e3db-dirty ``` Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
-rw-r--r--Makefile4
-rw-r--r--Makefile.release7
-rw-r--r--coremain/run.go2
3 files changed, 8 insertions, 5 deletions
diff --git a/Makefile b/Makefile
index 8f141ba4e..328e32c89 100644
--- a/Makefile
+++ b/Makefile
@@ -1,3 +1,5 @@
+GITCOMMIT := $(shell git describe --dirty --always)
+
BUILD_VERBOSE := -v
TEST_VERBOSE := -v
@@ -8,7 +10,7 @@ all: coredns
# TODO: Add .go file dependencies.
.PHONY: coredns
coredns: check godeps
- CGO_ENABLED=0 go build $(BUILD_VERBOSE) -ldflags="-s -w"
+ CGO_ENABLED=0 go build $(BUILD_VERBOSE) -ldflags="-s -w -X github.com/coredns/coredns/coremain.gitCommit=$(GITCOMMIT)"
.PHONY: deps
deps: core/zmiddleware.go core/dnsserver/zdirectives.go godeps
diff --git a/Makefile.release b/Makefile.release
index 7f2a334db..37cffe148 100644
--- a/Makefile.release
+++ b/Makefile.release
@@ -38,6 +38,7 @@ ARCH:=$(shell uname -m)
GITHUB:=coredns
DOCKER:=coredns
DOCKER_IMAGE_NAME:=$(DOCKER)/$(NAME)
+GITCOMMIT:=$(shell git describe --dirty --always)
all:
@echo Use the 'release' target to start a release
@@ -66,17 +67,17 @@ build: build-arm build-darwin build-linux
.PHONY: build-linux
build-linux:
@echo Building: linux $(VERSION)
- mkdir -p build/Linux && CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o build/Linux/$(NAME)
+ mkdir -p build/Linux && CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w -X github.com/coredns/coredns/coremain.gitCommit=$(GITCOMMIT)" -o build/Linux/$(NAME)
.PHONY: build-darwin
build-darwin:
@echo Building: darwin $(VERSION)
- mkdir -p build/Darwin && CGO_ENABLED=0 GOOS=darwin go build -ldflags="-s -w" -o build/Darwin/$(NAME)
+ mkdir -p build/Darwin && CGO_ENABLED=0 GOOS=darwin go build -ldflags="-s -w -X github.com/coredns/coredns/coremain.gitCommit=$(GITCOMMIT)" -o build/Darwin/$(NAME)
.PHONY: build-arm
build-arm:
@echo Building: arm $(VERSION)
- mkdir -p build/Linux/Arm && CGO_ENABLED=0 GOOS=linux GOARCH=arm go build -ldflags="-s -w" -o build/Linux/Arm/$(NAME)
+ mkdir -p build/Linux/Arm && CGO_ENABLED=0 GOOS=linux GOARCH=arm go build -ldflags="-s -w -X github.com/coredns/coredns/coremain.gitCommit=$(GITCOMMIT)" -o build/Linux/Arm/$(NAME)
.PHONY: tar
diff --git a/coremain/run.go b/coremain/run.go
index 730268371..71f968c98 100644
--- a/coremain/run.go
+++ b/coremain/run.go
@@ -168,7 +168,7 @@ func showVersion() {
// versionString returns the CoreDNS version as a string.
func versionString() string {
- return fmt.Sprintf("%s-%s\n", caddy.AppName, caddy.AppVersion)
+ return fmt.Sprintf("%s-%s\n%s/%s, %s, %s\n", caddy.AppName, caddy.AppVersion, runtime.GOOS, runtime.GOARCH, runtime.Version(), gitCommit)
}
// setVersion figures out the version information