forked from rafecolton/docker-builder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
196 lines (169 loc) · 4.65 KB
/
Makefile
File metadata and controls
196 lines (169 loc) · 4.65 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
SHELL := /bin/bash
SUDO ?= sudo
DOCKER ?= docker
B := github.com/modcloth/docker-builder
PACKAGES := \
$(B)/analyzer \
$(B)/builder \
$(B)/builderfile \
$(B)/conf \
$(B)/dclient \
$(B)/job \
$(B)/log \
$(B)/parser \
$(B)/parser/tag \
$(B)/parser/uuid \
$(B)/server \
$(B)/server/webhook \
$(B)/version
REV_VAR := $(B)/version.RevString
VERSION_VAR := $(B)/version.VersionString
BRANCH_VAR := $(B)/version.BranchString
REPO_VERSION := $(shell git describe --always --dirty --tags)
REPO_REV := $(shell git rev-parse --sq HEAD)
REPO_BRANCH := $(shell git rev-parse -q --abbrev-ref HEAD)
GOBUILD_VERSION_ARGS := -ldflags "\
-X $(REV_VAR) $(REPO_REV) \
-X $(VERSION_VAR) $(REPO_VERSION) \
-X $(BRANCH_VAR) $(REPO_BRANCH)"
BATS_INSTALL_DIR ?= /usr/local
GINKGO_PATH ?= "."
BATS_OUT_FORMAT=$(shell bash -c "echo $${CI+--tap}")
GOPATH := $(shell echo $${GOPATH%%:*})
export BATS_INSTALL_DIR
export GINKGO_PATH
export GOPATH
.PHONY: all
all: binclean clean build test
.PHONY: default help
default: help
help:
@echo "Usage: make [target]"
@echo
@echo "Some Useful Options:"
@echo
@echo " help: display this message"
@echo
@echo " all: binclean clean build test"
@echo
@echo " quick: build + invokes docker-builder a couple times (good for debugging)"
@echo
@echo " build: installing libs plus installing deps"
@echo
@echo " test: build fmtpolice, ginkgo tests, and bats tests"
@echo
@echo " dev: set up the dev toolchain (deps + gox)"
.PHONY: clean
clean:
go clean -i -r $(PACKAGES) || true
rm -f $(GOPATH)/bin/docker-builder
.PHONY: quick
quick: build
@echo "----------"
@docker-builder --version
@echo "----------"
@docker-builder --help
@echo "----------"
@docker-builder
@echo "----------"
.PHONY: binclean
binclean:
rm -f $(GOPATH)/bin/docker-builder
rm -rf ./releases/*
touch ./releases/.gitkeep
.PHONY: build
build: binclean godep
go install $(GOBUILD_VERSION_ARGS) $(GO_TAG_ARGS) $(PACKAGES) $(B)
.PHONY: release
release: binclean gox-linux gox-darwin
open ./releases
.PHONY: gox-linux
gox-linux: build dev
mkdir -p ./releases/linux/bin
gox -output="releases/linux/bin/docker-builder" -arch="amd64" -os="linux" $(GOBUILD_VERSION_ARGS) $(GO_TAG_ARGS) $(B)
pushd releases >/dev/null && \
tar -czf docker-builder-$(REPO_VERSION)-linux-amd64.tar.gz linux/ && \
popd >/dev/null
.PHONY: gox-darwin
gox-darwin: build dev
mkdir -p ./releases/darwin/bin
gox -output="releases/darwin/bin/docker-builder" -arch="amd64" -os="darwin" $(GOBUILD_VERSION_ARGS) $(GO_TAG_ARGS) $(B)
pushd releases >/dev/null && \
tar -czf docker-builder-$(REPO_VERSION)-darwin-amd64.tar.gz darwin/ && \
popd >/dev/null
.PHONY: godep
godep:
go get github.com/tools/godep
@echo "godep restoring..."
$(GOPATH)/bin/godep restore
.PHONY: deps
deps: godep
go get github.com/golang/lint/golint
go get github.com/onsi/ginkgo/ginkgo
go get github.com/onsi/gomega
@echo "installing bats..."
@if ! which bats >/dev/null ; then \
git clone https://github.com/sstephenson/bats.git && \
(cd bats && $(SUDO) ./install.sh ${BATS_INSTALL_DIR}) && \
rm -rf bats ; \
fi
.PHONY: test
test: build fmtpolice ginkgo bats
.PHONY: fmtpolice
fmtpolice: deps fmt lint
.PHONY: fmt
fmt:
@echo "----------"
@echo "checking fmt"
@set -e ; \
for f in $(shell git ls-files '*.go'); do \
gofmt $$f | diff -u $$f - ; \
done
.PHONY: linter
linter:
go get github.com/golang/lint/golint
.PHONY: lint
lint: linter
@echo "----------"
@echo "checking lint"
@for file in $(shell git ls-files '*.go') ; do \
if [[ "$$($(GOPATH)/bin/golint $$file)" =~ ^[[:blank:]]*$$ ]] ; then \
echo yayyy >/dev/null ; \
else $(MAKE) lintv && exit 1 ; fi \
done
.PHONY: lintv
lintv:
@echo "----------"
@for file in $(shell git ls-files '*.go') ; do $(GOPATH)/bin/golint $$file ; done
.PHONY: ginkgo
ginkgo:
@echo "----------"
@if [[ "$(GINKGO_PATH)" == "." ]] ; then \
echo "$(GOPATH)/bin/ginkgo -nodes=10 -noisyPendings -race -r ." && \
$(GOPATH)/bin/ginkgo -nodes=10 -noisyPendings -race -r . ; \
else echo "$(GOPATH)/bin/ginkgo -nodes=10 -noisyPendings -race --v $(GINKGO_PATH)" && \
$(GOPATH)/bin/ginkgo -nodes=10 -noisyPendings -race --v $(GINKGO_PATH) ; \
fi
.PHONY: bats
bats:
@echo "----------"
$(BATS_INSTALL_DIR)/bin/bats $(BATS_OUT_FORMAT) $(shell find . -type f -name '*.bats')
.PHONY: gox
gox:
@if which gox >/dev/null ; then \
echo "not installing gox, gox already installed." ; \
else \
go get github.com/mitchellh/gox ; \
gox -build-toolchain -osarch="linux/amd64 darwin/amd64" ; \
fi \
.PHONY: gopath
gopath:
@echo "\$$GOPATH = $(GOPATH)"
.PHONY: save
save:
godep save -copy=false ./...
.PHONY: get
get:
go get ./...
.PHONY: dev
dev: deps gox