Commit f48ef319 authored by Sergey Lyubka's avatar Sergey Lyubka Committed by GitHub

Merge pull request #110 from cesanta/version

Version-tag builds
parents 237b91de 986e23f6
ca-certificates.crt ca-certificates.crt
auth_server auth_server
Godeps/ Godeps/
version.*
...@@ -2,6 +2,7 @@ MAKEFLAGS += --warn-undefined-variables ...@@ -2,6 +2,7 @@ MAKEFLAGS += --warn-undefined-variables
IMAGE ?= cesanta/docker_auth IMAGE ?= cesanta/docker_auth
COMPRESS_BINARY ?= false COMPRESS_BINARY ?= false
CA_BUNDLE = /etc/ssl/certs/ca-certificates.crt CA_BUNDLE = /etc/ssl/certs/ca-certificates.crt
VERSION = $(shell cat version.txt)
BUILDER_IMAGE ?= centurylink/golang-builder BUILDER_IMAGE ?= centurylink/golang-builder
BUILDER_IMAGE_EXTRA-build-cross = -cross BUILDER_IMAGE_EXTRA-build-cross = -cross
...@@ -15,12 +16,12 @@ local: build-local ...@@ -15,12 +16,12 @@ local: build-local
update-deps: update-deps:
go get -v -u -f github.com/tools/godep github.com/jteeuwen/go-bindata/... go get -v -u -f github.com/tools/godep github.com/jteeuwen/go-bindata/...
go generate ./...
godep: godep:
godep save godep save
build-local: update-deps build-local: update-deps
go generate ./...
go build go build
ca-certificates.crt: ca-certificates.crt:
...@@ -28,11 +29,18 @@ ca-certificates.crt: ...@@ -28,11 +29,18 @@ ca-certificates.crt:
docker-build: docker-build:
docker run --rm -v $(PWD):/src -e COMPRESS_BINARY=$(COMPRESS_BINARY) $(BUILDER_OPTS-$@) $(BUILDER_IMAGE)$(BUILDER_IMAGE_EXTRA-$@) $(IMAGE) docker run --rm -v $(PWD):/src -e COMPRESS_BINARY=$(COMPRESS_BINARY) $(BUILDER_OPTS-$@) $(BUILDER_IMAGE)$(BUILDER_IMAGE_EXTRA-$@) $(IMAGE)
@echo === Built version $(VERSION) ===
build build-cross: update-deps godep ca-certificates.crt docker-build build build-cross: update-deps godep ca-certificates.crt docker-build
docker-tag:
docker tag $(IMAGE):latest $(IMAGE):$(VERSION)
docker-tag-%: docker-tag-%:
docker tag -f $(IMAGE):latest $(IMAGE):$* docker tag $(IMAGE):latest $(IMAGE):$*
docker-push:
docker push $(IMAGE):latest $(IMAGE):$(VERSION)
docker-push-%: docker-tag-% docker-push-%: docker-tag-%
docker push $(IMAGE):$* docker push $(IMAGE):$*
......
#!/usr/bin/env python
import datetime
import sys
# Debian/Ubuntu: apt-get install python-git
# PIP: pip install GitPython
import git
repo = git.Repo('.', search_parent_directories=True)
def get_tag_for_commit(repo, commit):
for tag in repo.tags:
if tag.commit == commit:
return tag.name
return None
if repo.head.is_detached:
branch_or_tag = get_tag_for_commit(repo, repo.head.commit)
if branch_or_tag is None:
branch_or_tag = '?'
else:
branch_or_tag = repo.active_branch
dirty = repo.is_dirty()
ts = datetime.datetime.utcnow()
build_id = '%s/%s@%s%s' % (ts.strftime('%Y%m%d-%H%M%S'),
branch_or_tag,
str(repo.head.commit)[:8],
'+' if dirty else '')
version = None
if not dirty:
version = get_tag_for_commit(repo, repo.head.commit)
if version is None:
version = ts.strftime('%Y%m%d%H%M%S')
if len(sys.argv) == 1 or sys.argv[1] == '-':
f = sys.stdout
else:
f = open(sys.argv[1], 'w')
with open('version.go', 'w') as f:
f.write("""\
package main
const (
\tVersion = "{version}"
\tBuildId = "{build_id}"
)
""".format(version=version, build_id=build_id))
with open('version.txt', 'w') as f:
f.write(version)
f.close()
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
limitations under the License. limitations under the License.
*/ */
//go:generate ./gen_version.py
package main // import "github.com/cesanta/docker_auth/auth_server" package main // import "github.com/cesanta/docker_auth/auth_server"
import ( import (
...@@ -158,6 +160,8 @@ func main() { ...@@ -158,6 +160,8 @@ func main() {
rand.Seed(time.Now().UnixNano()) rand.Seed(time.Now().UnixNano())
glog.CopyStandardLogTo("INFO") glog.CopyStandardLogTo("INFO")
glog.Infof("docker_auth %s build %s", Version, BuildId)
cf := flag.Arg(0) cf := flag.Arg(0)
if cf == "" { if cf == "" {
glog.Exitf("Config file not specified") glog.Exitf("Config file not specified")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment