From 8f383377573000404d816f48bb83b27ef069968f Mon Sep 17 00:00:00 2001 From: emile Date: Wed, 14 Oct 2015 22:04:56 +0200 Subject: [PATCH] Adds version in binary --- circle.yml | 7 ++++--- script/binary | 11 +++++++++-- script/crossbinary | 11 +++++++++-- traefik.go | 4 ++++ 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/circle.yml b/circle.yml index f6929aae5..d46e7acdd 100644 --- a/circle.yml +++ b/circle.yml @@ -6,6 +6,7 @@ machine: environment: REPO: $CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME DOCKER_HOST: tcp://172.17.42.1:2375 + VERSION: v1.0.alpha.$CIRCLE_BUILD_NUM dependencies: pre: @@ -27,8 +28,8 @@ deployment: hub: branch: master commands: - - ghr -t $GITHUB_TOKEN -u $CIRCLE_PROJECT_USERNAME -r $CIRCLE_PROJECT_REPONAME --prerelease v1.0.alpha.$CIRCLE_BUILD_NUM dist/ + - ghr -t $GITHUB_TOKEN -u $CIRCLE_PROJECT_USERNAME -r $CIRCLE_PROJECT_REPONAME --prerelease ${VERSION} dist/ - docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS - docker push ${REPO,,}:latest - - docker tag ${REPO,,}:latest ${REPO,,}:v1.0.alpha.$CIRCLE_BUILD_NUM - - docker push ${REPO,,}:v1.0.alpha.$CIRCLE_BUILD_NUM + - docker tag ${REPO,,}:latest ${REPO,,}:${VERSION} + - docker push ${REPO,,}:${VERSION} diff --git a/script/binary b/script/binary index db71ece96..efffdf10b 100755 --- a/script/binary +++ b/script/binary @@ -8,6 +8,13 @@ fi rm -f dist/traefik -# Build binaries -CGO_ENABLED=0 go build -a -installsuffix nocgo -o dist/traefik . +if [ -z "$VERSION" ]; then + VERSION=$(git rev-parse HEAD) +fi +if [ -z "$DATE" ]; then + DATE=$(date -u '+%Y-%m-%d_%I:%M:%S%p') +fi + +# Build binaries +CGO_ENABLED=0 go build -ldflags "-X main.Version=$VERSION -X main.BuildDate=$DATE" -a -installsuffix nocgo -o dist/traefik . diff --git a/script/crossbinary b/script/crossbinary index 7099fb23f..556295532 100755 --- a/script/crossbinary +++ b/script/crossbinary @@ -20,10 +20,17 @@ else OS_ARCH_ARG=($2) fi +if [ -z "$VERSION" ]; then + VERSION=$(git rev-parse HEAD) +fi + +if [ -z "$DATE" ]; then + DATE=$(date -u '+%Y-%m-%d_%I:%M:%S%p') +fi + # Get rid of existing binaries rm -f dist/traefik_* # Build binaries -gox "${OS_PLATFORM_ARG[@]}" "${OS_ARCH_ARG[@]}" \ +gox -ldflags "-X main.Version=$VERSION -X main.BuildDate=$DATE" "${OS_PLATFORM_ARG[@]}" "${OS_ARCH_ARG[@]}" \ -output="dist/traefik_{{.OS}}-{{.Arch}}" - diff --git a/traefik.go b/traefik.go index 9b3452830..fe023583f 100644 --- a/traefik.go +++ b/traefik.go @@ -30,7 +30,10 @@ import ( ) var ( + Version = "" + BuildDate = "" globalConfigFile = kingpin.Arg("conf", "Main configration file.").Default("traefik.toml").String() + version = kingpin.Flag("version", "Get Version.").Short('v').Bool() currentConfigurations = make(configs) metrics = stats.New() oxyLogger = &OxyLogger{} @@ -50,6 +53,7 @@ type configs map[string]*Configuration func main() { runtime.GOMAXPROCS(runtime.NumCPU()) + kingpin.Version(Version + " built on the " + BuildDate) kingpin.Parse() fmtlog.SetFlags(fmtlog.Lshortfile | fmtlog.LstdFlags) var srv *manners.GracefulServer