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