Adds version in binary

This commit is contained in:
emile 2015-10-14 22:04:56 +02:00
parent 37438a6395
commit 8f38337757
4 changed files with 26 additions and 7 deletions

View file

@ -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}

View file

@ -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 .

View file

@ -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}}"

View file

@ -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