forked from grammarly/rocker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
115 lines (87 loc) · 3.51 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
107
108
109
110
111
112
113
114
115
VERSION ?= $(shell cat VERSION)
OSES := linux darwin
ARCHS := amd64
BINARIES := rocker
LAST_TAG = $(shell git describe --abbrev=0 --tags 2>/dev/null)
GITCOMMIT = $(shell git rev-parse HEAD 2>/dev/null)
GITBRANCH = $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null)
BUILDTIME := $(shell TZ=GMT date "+%Y-%m-%d_%H:%M_GMT")
GITHUB_USER := grammarly
GITHUB_REPO := rocker
GITHUB_RELEASE := docker run --rm -ti \
-e GITHUB_TOKEN=$(GITHUB_TOKEN) \
-v /etc/ssl/certs/ca-certificates.crt:/etc/ssl/certs/ca-certificates.crt \
-v $(shell pwd)/dist:/dist \
dockerhub.grammarly.io/tools/github-release:master
ALL_ARCHS := $(foreach os, $(OSES), $(foreach arch, $(ARCHS), $(os)/$(arch) ))
ALL_BINARIES := $(foreach arch, $(ALL_ARCHS), $(foreach bin, $(BINARIES), dist/$(VERSION)/$(arch)/$(bin) ))
OUT_BINARIES := $(foreach arch, $(ALL_ARCHS), $(foreach bin, $(BINARIES), dist/$(bin)_$(subst /,_,$(arch)) ))
ALL_TARS := $(ALL_BINARIES:%=%.tar.gz)
os = $(shell echo "$(1)" | awk -F/ '{print $$3}' )
arch = $(shell echo "$(1)" | awk -F/ '{print $$4}' )
bin = $(shell echo "$(1)" | awk -F/ '{print $$5}' )
UPLOAD_CMD = $(GITHUB_RELEASE) upload \
--user $(GITHUB_USER) \
--repo $(GITHUB_REPO) \
--tag $(VERSION) \
--name $(call bin,$(FILE))-$(VERSION)_$(call os,$(FILE))_$(call arch,$(FILE)).tar.gz \
--file $(FILE).tar.gz
SRCS = $(shell find . -name '*.go' | grep -v '^./vendor/')
PKGS := $(foreach pkg, $(sort $(dir $(SRCS))), $(pkg))
GOPATH ?= $(shell pwd):$(shell pwd)/vendor
TESTARGS ?=
all: $(ALL_BINARIES)
$(foreach BIN, $(BINARIES), $(shell cp dist/$(VERSION)/$(shell go env GOOS)/amd64/$(BIN) dist/$(BIN)))
$(OUT_BINARIES): $(ALL_BINARIES)
cp $< $@
release: $(ALL_TARS)
git pull
git push && git push --tags
$(GITHUB_RELEASE) release \
--user $(GITHUB_USER) \
--repo $(GITHUB_REPO) \
--tag $(VERSION) \
--name $(VERSION) \
--description "https://github.com/$(GITHUB_USER)/$(GITHUB_REPO)/compare/$(LAST_TAG)...$(VERSION)"
$(foreach FILE,$(ALL_BINARIES),$(UPLOAD_CMD);)
tar: $(ALL_TARS)
%.tar.gz: %
COPYFILE_DISABLE=1 tar -zcvf $@ -C dist/$(VERSION)/$(call os,$<)/$(call arch,$<) $(call bin,$<)
$(ALL_BINARIES): build_image
docker run --rm -ti -v $(shell pwd)/dist:/src/dist \
-e GOOS=$(call os,$@) -e GOARCH=$(call arch,$@) -e GOPATH=/src:/src/vendor \
rocker-build:latest go build \
-ldflags "-X main.Version=$(VERSION) -X main.GitCommit=$(GITCOMMIT) -X main.GitBranch=$(GITBRANCH) -X main.BuildTime=$(BUILDTIME)" \
-v -o $@ src/cmd/$(call bin,$@)/main.go
build_image:
rocker build -f Rockerfile.build-cross
docker_image:
rocker build -var Version=$(VERSION)
install:
cp dist/$(VERSION)/$(shell go env GOOS)/amd64/rocker /usr/local/bin/rocker
chmod +x /usr/local/bin/rocker
clean:
rm -Rf dist
local_binary:
go build \
-ldflags "-X main.Version=$(VERSION) -X main.GitCommit=$(GITCOMMIT) -X main.GitBranch=$(GITBRANCH) -X main.BuildTime=$(BUILDTIME)" \
-v -o bin/rocker src/cmd/rocker/main.go
testdeps:
@ go get github.com/GeertJohan/fgt
@ go get github.com/constabulary/gb/...
fmtcheck:
$(foreach file,$(SRCS),gofmt $(file) | diff -u $(file) - || exit;)
lint:
@ go get github.com/golang/lint/golint
$(foreach file,$(SRCS),fgt golint $(file) || exit;)
vet:
@ go get golang.org/x/tools/cmd/vet
$(foreach pkg,$(PKGS),fgt go vet $(pkg) || exit;)
gocyclo:
@ go get github.com/fzipp/gocyclo
gocyclo -over 25 ./src
test: testdeps fmtcheck vet lint
gb test rocker/... $(TESTARGS)
version:
@echo $(VERSION)
.PHONY: clean build_image test fmtcheck lint vet gocyclo version