|
| 1 | +# These env vars have to be set in the CI |
| 2 | +# GITHUB_TOKEN |
| 3 | +# DOCKER_HUB_TOKEN |
| 4 | + |
| 5 | +.PHONY: build deps test release clean push image ci-compile build-dir ci-dist dist-dir ci-release version help |
| 6 | + |
| 7 | +PROJECT := filesync |
| 8 | +PLATFORM := linux |
| 9 | +ARCH := amd64 |
| 10 | +DOCKER_IMAGE := causticlab/$(PROJECT) |
| 11 | + |
| 12 | +VERSION := $(shell cat VERSION) |
| 13 | +GITSHA := $(shell git rev-parse --short HEAD) |
| 14 | + |
| 15 | +all: help |
| 16 | + |
| 17 | +help: |
| 18 | + @echo "make build - build binary for the target environment" |
| 19 | + @echo "make deps - install build dependencies" |
| 20 | + @echo "make vet - run vet & gofmt checks" |
| 21 | + @echo "make test - run tests" |
| 22 | + @echo "make clean - Duh!" |
| 23 | + @echo "make release - tag with version and trigger CI release build" |
| 24 | + @echo "make image - build release image" |
| 25 | + @echo "make dev-image - build development image" |
| 26 | + @echo "make dockerhub - build and push image to Docker Hub" |
| 27 | + @echo "make version - show app version" |
| 28 | + |
| 29 | +build: build-dir |
| 30 | + CGO_ENABLED=1 GOOS=$(PLATFORM) GOARCH=$(ARCH) godep go build -ldflags "-X main.Version=$(VERSION) -X main.GitSHA=$(GITSHA)" -o build/$(PROJECT)-$(PLATFORM)-$(ARCH) -v |
| 31 | + |
| 32 | +deps: |
| 33 | + go get golang.org/x/sys/unix |
| 34 | + go get github.com/tools/godep |
| 35 | + go get github.com/mattn/go-sqlite3 |
| 36 | + go get github.com/bitly/go-simplejson |
| 37 | + go get github.com/howeyc/fsnotify |
| 38 | + go get github.com/codegangsta/martini |
| 39 | + go get github.com/codegangsta/martini-contrib/encoder |
| 40 | + godep save |
| 41 | + |
| 42 | +release: |
| 43 | + git tag `cat VERSION` |
| 44 | + git push origin master --tags |
| 45 | + |
| 46 | +clean: |
| 47 | + go clean |
| 48 | + rm -fr ./build |
| 49 | + rm -fr ./dist |
| 50 | + |
| 51 | +dockerhub: image |
| 52 | + @echo "Pushing $(DOCKER_IMAGE):$(VERSION)" |
| 53 | + docker push $(DOCKER_IMAGE):$(VERSION) |
| 54 | + |
| 55 | +image: |
| 56 | + docker build -t $(DOCKER_IMAGE):$(VERSION) -f Dockerfile . |
| 57 | + |
| 58 | +dev-image: |
| 59 | + docker build -t $(DOCKER_IMAGE):dev -f Dockerfile.dev . |
| 60 | + |
| 61 | +version: |
| 62 | + @echo $(VERSION) $(GITSHA) |
| 63 | + |
| 64 | +ci-compile: build-dir |
| 65 | + CGO_ENABLED=1 GOOS=$(PLATFORM) GOARCH=$(ARCH) go build -ldflags "-X main.Version=$(VERSION) -X main.GitSHA=$(GITSHA) -w -s" -a -o build/$(PROJECT)-$(PLATFORM)-$(ARCH)/$(PROJECT) |
| 66 | + |
| 67 | +build-dir: |
| 68 | + @rm -rf build && mkdir build |
| 69 | + |
| 70 | +dist-dir: |
| 71 | + @rm -rf dist && mkdir dist |
| 72 | + |
| 73 | +ci-dist: ci-compile dist-dir |
| 74 | + $(eval FILES := $(shell ls build)) |
| 75 | + @for f in $(FILES); do \ |
| 76 | + (cd $(shell pwd)/build/$$f && tar -cvzf ../../dist/$$f.tar.gz *); \ |
| 77 | + (cd $(shell pwd)/dist && shasum -a 256 $$f.tar.gz > $$f.sha256); \ |
| 78 | + (cd $(shell pwd)/dist && md5sum $$f.tar.gz > $$f.md5); \ |
| 79 | + echo $$f; \ |
| 80 | + done |
| 81 | + @cp -r $(shell pwd)/dist/* $(CIRCLE_ARTIFACTS) |
| 82 | + ls $(CIRCLE_ARTIFACTS) |
| 83 | + |
| 84 | +ci-release: |
| 85 | + @previous_tag=$$(git describe --abbrev=0 --tags $(VERSION)^); \ |
| 86 | + comparison="$$previous_tag..HEAD"; \ |
| 87 | + if [ -z "$$previous_tag" ]; then comparison=""; fi; \ |
| 88 | + changelog=$$(git log $$comparison --oneline --no-merges --reverse); \ |
| 89 | + github-release $(CIRCLE_PROJECT_USERNAME)/$(CIRCLE_PROJECT_REPONAME) $(VERSION) master "**Changelog**<br/>$$changelog" 'dist/*' |
0 commit comments