Improve build identification

New example:

2015/06/09 09:20:13 Versions: boulder=(generate_ocsp +0c101f2 Tue Jun  9 16:20:06 UTC 2015) Golang=(devel +46b4f67 Thu Apr 16 20:01:13 2015 +0000) BuildHost=(user@vm.local)
This commit is contained in:
J.C. Jones 2015-06-09 09:20:42 -07:00
parent 17e9e6d1d8
commit 76f7b1c1e4
3 changed files with 41 additions and 5 deletions

View File

@ -14,21 +14,33 @@ OBJECTS = activity-monitor \
ocsp-updater \
ocsp-responder
REVID = $(shell git symbolic-ref --short HEAD):$(shell git rev-parse --short HEAD)
# Build environment variables (referencing core/util.go)
BUILD_ID = $(shell git symbolic-ref --short HEAD) +$(shell git rev-parse --short HEAD)
BUILD_ID_VAR = github.com/letsencrypt/boulder/core.BuildID
BUILD_HOST = $(shell whoami)@$(shell hostname)
BUILD_HOST_VAR = github.com/letsencrypt/boulder/core.BuildHost
BUILD_TIME = $(shell date -u)
BUILD_TIME_VAR = github.com/letsencrypt/boulder/core.BuildTime
.PHONY: all build
all: build
build: $(OBJECTS)
pre:
mkdir -p $(OBJDIR)
go install ./Godeps/_workspace/src/github.com/mattn/go-sqlite3
@mkdir -p $(OBJDIR)
@echo [go] lib/github.com/mattn/go-sqlite3
@go install ./Godeps/_workspace/src/github.com/mattn/go-sqlite3
# Compile each of the binaries
$(OBJECTS): pre
go build -tags pkcs11 -o ./bin/$@ -ldflags "-X $(BUILD_ID_VAR) $(REVID)" cmd/$@/main.go
@echo [go] bin/$@
@go build -tags pkcs11 -o ./bin/$@ -ldflags \
"-X $(BUILD_ID_VAR) '$(BUILD_ID)' -X $(BUILD_TIME_VAR) '$(BUILD_TIME)' \
-X $(BUILD_HOST_VAR) '$(BUILD_HOST)'" \
cmd/$@/main.go
clean:
rm -f $(OBJDIR)/*

View File

@ -179,7 +179,7 @@ func (as *AppShell) Run() {
// VersionString produces a friendly Application version string
func (as *AppShell) VersionString() string {
return fmt.Sprintf("%s (build %s)", as.App.Name, core.GetBuildID())
return fmt.Sprintf("Versions: %s=(%s %s) Golang=(%s) BuildHost=(%s)", as.App.Name, core.GetBuildID(), core.GetBuildTime(), runtime.Version(), core.GetBuildHost())
}
// FailOnError exits and prints an error message if we encountered a problem

View File

@ -34,6 +34,12 @@ import (
// and is used by GetBuildID
var BuildID string
// BuildHost is set by the compiler and is used by GetBuildHost
var BuildHost string
// BuildTime is set by the compiler and is used by GetBuildTime
var BuildTime string
// Errors
type InternalServerError string
@ -255,6 +261,24 @@ func GetBuildID() (retID string) {
return
}
// GetBuildTime identifies when this build was made
func GetBuildTime() (retID string) {
retID = BuildTime
if retID == "" {
retID = "Unspecified"
}
return
}
// GetBuildHost identifies the building host
func GetBuildHost() (retID string) {
retID = BuildHost
if retID == "" {
retID = "Unspecified"
}
return
}
func UniqueNames(names []string) (unique []string) {
nameMap := make(map[string]int, len(names))
for _, name := range names {