This repository has been archived by the owner on Sep 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
106 lines (84 loc) · 3.17 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# 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-gen
PLATFORM := linux
ARCH := amd64
DOCKER_IMAGE := causticlab/$(PROJECT)
VERSION := $(shell cat VERSION)
GITSHA := $(shell git rev-parse --short HEAD)
all: help
help:
@echo "make build - build binary for the target 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 release image"
@echo "make dev-image - build development image"
@echo "make dockerhub - build and push image to Docker Hub"
@echo "make version - show app version"
@echo "make travis-ci-dist - Build distribution files with for travis"
build: build-dir
CGO_ENABLED=0 GOOS=$(PLATFORM) GOARCH=$(ARCH) godep go build -ldflags "-X main.Version=$(VERSION) -X main.GitSHA=$(GITSHA)" -o build/$(PROJECT)-$(PLATFORM)-$(ARCH)
deps:
go get github.com/tools/godep
go get github.com/c4milo/github-release
go get github.com/BurntSushi/toml
go get github.com/Sirupsen/logrus
go get github.com/rancher/go-rancher-metadata/metadata
go get github.com/fatih/structs
vet:
scripts/vet
test:
godep go test -v ./...
package: clean build
tar -zcvf build/rancher-gen-linux-amd64.tar.gz build/rancher-gen-linux-amd64
release:
git tag `cat VERSION`
git push origin master --tags
clean:
go clean
rm -fr ./build
rm -fr ./dist
dockerhub: image
@echo "Pushing $(DOCKER_IMAGE):$(VERSION)"
docker push $(DOCKER_IMAGE):$(VERSION)
image:
docker build -t $(DOCKER_IMAGE):$(VERSION) -f Dockerfile .
dev-image:
docker build -t $(DOCKER_IMAGE):dev -f Dockerfile.dev .
version:
@echo $(VERSION) $(GITSHA)
ci-compile: build-dir
CGO_ENABLED=0 GOOS=$(PLATFORM) GOARCH=$(ARCH) godep go build -ldflags "-X main.Version=$(VERSION) -X main.GitSHA=$(GITSHA) -w -s" -a -o build/$(PROJECT)-$(PLATFORM)-$(ARCH)/$(PROJECT)
build-dir:
@rm -rf build && mkdir build
dist-dir:
@rm -rf dist && mkdir dist
travis-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.sha256); \
(cd $(shell pwd)/dist && md5sum $$f.tar.gz > $$f.md5); \
echo $$f; \
done
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.sha256); \
(cd $(shell pwd)/dist && md5sum $$f.tar.gz > $$f.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/*'