forked from jetstack/tarmak
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
323 lines (246 loc) · 13.1 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
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
# Copyright Jetstack Ltd. See LICENSE for details.
PACKAGE_NAME ?= github.com/jetstack/tarmak
CONTAINER_DIR := /go/src/$(PACKAGE_NAME)
GO_VERSION := 1.11.5
BINDIR ?= $(CURDIR)/bin
PATH := $(BINDIR):$(PATH)
CI_COMMIT_TAG ?= dev
CI_COMMIT_SHA ?= unknown
# A list of all types.go files in pkg/apis
TYPES_FILES = $(shell find pkg/apis -name types.go)
# List of dependent gofiles
TARMAK_GO_FILES := pkg/tarmak/binaries/binaries_bindata.go pkg/tarmak/assets/assets_bindata.go $(shell go list -f '{{ join .Deps "\n" }}' ./cmd/tarmak | xargs go list -f '{{ $$global := .}}{{ range .GoFiles }}{{ printf "%s/%s\n" $$global.Dir . }}{{ end}}')
WING_GO_FILES := $(shell go list -f '{{ join .Deps "\n" }}' ./cmd/wing | xargs go list -f '{{ $$global := .}}{{ range .GoFiles }}{{ printf "%s/%s\n" $$global.Dir . }}{{ end}}')
TAGGING_CONTROL_GO_FILES := $(shell go list -f '{{ join .Deps "\n" }}' ./cmd/tagging_control | xargs go list -f '{{ $$global := .}}{{ range .GoFiles }}{{ printf "%s/%s\n" $$global.Dir . }}{{ end}}')
HACK_DIR ?= hack
GOPATH ?= /tmp/go
# Source URLs / hashes based on OS
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
TAR_EXT := tar.xz
SHASUM := sha256sum -c
DEP_URL := https://github.com/golang/dep/releases/download/v0.5.0/dep-linux-amd64
DEP_HASH := 287b08291e14f1fae8ba44374b26a2b12eb941af3497ed0ca649253e21ba2f83
NODE_NAME := node-v8.12.0-linux-x64
NODE_URL := https://nodejs.org/dist/v8.12.0/${NODE_NAME}.$(TAR_EXT)
NODE_HASH := 29a20479cd1e3a03396a4e74a1784ccdd1cf2f96928b56f6ffa4c8dae40c88f2
SONOBUOY_HASH := 0b10d412bfc3777267ffd83f161a8ce4a7fba321f28241574639dc9c2cad8150
SONOBUOY_URL := https://github.com/heptio/sonobuoy/releases/download/v0.13.0/sonobuoy_0.13.0_linux_amd64.tar.gz
endif
ifeq ($(UNAME_S),Darwin)
TAR_EXT := tar.gz
SHASUM := shasum -a 256 -c
DEP_URL := https://github.com/golang/dep/releases/download/v0.5.0/dep-darwin-amd64
DEP_HASH := 1a7bdb0d6c31ecba8b3fd213a1170adf707657123e89dff234871af9e0498be2
NODE_NAME := node-v8.12.0-darwin-x64
NODE_URL := https://nodejs.org/dist/v8.12.0/${NODE_NAME}.$(TAR_EXT)
NODE_HASH := ca131b84dfcf2b6f653a6521d31f7a108ad7d83f4d7e781945b2eca8172064aa
SONOBUOY_HASH := 2209ad3a736ebce59a70535d5915061e710e0094626bcc0c6ab744db0ad8f482
SONOBUOY_URL := https://github.com/heptio/sonobuoy/releases/download/v0.13.0/sonobuoy_0.13.0_darwin_amd64.tar.gz
endif
# from https://suva.sh/posts/well-documented-makefiles/
.PHONY: help
help: ## Display this help
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n\nTargets:\n"} /^[a-zA-Z0-9_-]+:.*?##/ { printf " \033[36m%-20s\033[0m %s\n", $$1, $$2 }' $(MAKEFILE_LIST)
help1:
# test - runs go_test target
# build - runs generate, and then go_build targets
# generate - generates mocks and assets files
# verify - verifies generated files & scripts
.PHONY: all test verify
all: verify test build ## runs verify, test and build targets
depend: $(BINDIR)/go-bindata $(BINDIR)/mockgen $(BINDIR)/defaulter-gen $(BINDIR)/defaulter-gen $(BINDIR)/deepcopy-gen $(BINDIR)/conversion-gen $(BINDIR)/client-gen $(BINDIR)/lister-gen $(BINDIR)/informer-gen $(BINDIR)/dep $(BINDIR)/upx $(BINDIR)/openapi-gen $(BINDIR)/gen-apidocs $(BINDIR)/node $(BINDIR)/ghr $(BINDIR)/sonobuoy ## download all dependencies necessary for build
verify: generate go_verify verify_boilerplate verify_codegen verify_vendor verify_gen_docs ## verifies generated files & scripts
test: go_test ## runs all defined tests, no puppet tests
generate: go_generate ## generates mocks and assets files
build: generate go_build ## runs generate, and then go_build targets
go_verify: go_fmt go_vet
go_test:
go test $$(go list ./pkg/... ./cmd/... ./puppet | grep -v e2e)
go_fmt:
@set -e; \
GO_FMT=$$(git ls-files *.go | grep -v 'vendor/' | xargs gofmt -d); \
if [ -n "$${GO_FMT}" ] ; then \
echo "Please run go fmt"; \
echo "$$GO_FMT"; \
exit 1; \
fi
clean:
rm -rf \
$(BINDIR) \
_output/ \
_release/ \
pkg/tarmak/binaries/binaries_bindata.go \
pkg/tarmak/assets/assets_bindata.go \
pkg/wing/mocks/http_client.go \
pkg/wing/mocks/command.go \
pkg/wing/mocks/client.go
go_vet:
go vet $$(go list ./pkg/... ./cmd/...| grep -v pkg/wing/client/clientset/internalversion/fake | grep -v pkg/wing/client/clientset/versioned/fake)
go_build: _output/tarmak _output/tagging_control_linux_amd64 _output/wing_linux_amd64
$(BINDIR)/mockgen:
mkdir -p $(BINDIR)
go build -o $(BINDIR)/mockgen ./vendor/github.com/golang/mock/mockgen
$(BINDIR)/ghr:
mkdir -p $(BINDIR)
go build -o $@ ./vendor/github.com/tcnksm/ghr
$(BINDIR)/go-bindata:
mkdir -p $(BINDIR)
go build -o $(BINDIR)/go-bindata ./vendor/github.com/kevinburke/go-bindata/go-bindata
$(BINDIR)/defaulter-gen:
mkdir -p $(BINDIR)
go build -o $@ ./vendor/k8s.io/code-generator/cmd/defaulter-gen
$(BINDIR)/deepcopy-gen:
mkdir -p $(BINDIR)
go build -o $@ ./vendor/k8s.io/code-generator/cmd/deepcopy-gen
$(BINDIR)/conversion-gen:
mkdir -p $(BINDIR)
go build -o $@ ./vendor/k8s.io/code-generator/cmd/conversion-gen
$(BINDIR)/client-gen:
mkdir -p $(BINDIR)
go build -o $@ ./vendor/k8s.io/code-generator/cmd/client-gen
$(BINDIR)/lister-gen:
mkdir -p $(BINDIR)
go build -o $@ ./vendor/k8s.io/code-generator/cmd/lister-gen
$(BINDIR)/informer-gen:
mkdir -p $(BINDIR)
go build -o $@ ./vendor/k8s.io/code-generator/cmd/informer-gen
$(BINDIR)/dep:
curl -sL -o $@ $(DEP_URL)
echo "$(DEP_HASH) $@" | $(SHASUM)
chmod +x $@
$(BINDIR)/node:
curl -sL -o $(BINDIR)/$(NODE_NAME).$(TAR_EXT) $(NODE_URL)
echo "$(NODE_HASH) $(BINDIR)/$(NODE_NAME).$(TAR_EXT)" | $(SHASUM)
cd $(BINDIR) && tar xf $(NODE_NAME).$(TAR_EXT)
rm $(BINDIR)/$(NODE_NAME).$(TAR_EXT)
ln -s $(BINDIR)/$(NODE_NAME)/bin/node $(BINDIR)/node
ln -s $(BINDIR)/$(NODE_NAME)/bin/npm $(BINDIR)/npm
$(BINDIR)/sonobuoy:
curl -sL -o $(BINDIR)/sonobuoy.tar.gz $(SONOBUOY_URL)
echo "$(SONOBUOY_HASH) $(BINDIR)/sonobuoy.tar.gz" | $(SHASUM)
cd $(BINDIR) && tar xf sonobuoy.tar.gz
rm $(BINDIR)/sonobuoy.tar.gz
$(BINDIR)/npm: $(BINDIR)/node
# upx binary packer, only supported on Linux
$(BINDIR)/upx:
ifeq ($(UNAME_S),Linux)
# Do not upgrade to 3.95 as it produces wrong binaries for darwin
curl -sL -o [email protected] https://github.com/upx/upx/releases/download/v3.94/upx-3.94-amd64_linux.tar.xz
echo "e1fc0d55c88865ef758c7e4fabbc439e4b5693b9328d219e0b9b3604186abe20 [email protected]" | $(SHASUM)
which xz || ( apt-get update && apt-get -y install xz-utils)
cd $(BINDIR) && tar xvf $(shell basename $@).tar.xz upx-3.94-amd64_linux/upx --strip-components=1
else
echo -e "#/bin/sh\nexit 0" > $@
chmod +x $@
endif
$(BINDIR)/openapi-gen:
mkdir -p $(BINDIR)
go build -o $@ ./vendor/k8s.io/kube-openapi/cmd/openapi-gen
$(BINDIR)/gen-apidocs:
mkdir -p $(BINDIR)
go build -o $@ ./vendor/github.com/kubernetes-incubator/reference-docs/gen-apidocs
go_generate: pkg/wing/mocks/http_client.go pkg/wing/mocks/command.go pkg/wing/mocks/client.go pkg/tarmak/binaries/binaries_bindata.go pkg/tarmak/assets/assets_bindata.go pkg/tarmak/mocks/tarmak.go pkg/tarmak/mocks/amazon.go
go_codegen: depend $(TYPES_FILES)
$(HACK_DIR)/update-codegen.sh
go_reference_docs_gen: depend
$(HACK_DIR)/update-reference-docs.sh
go_cmd_docs_gen: depend
$(HACK_DIR)/update-cmd-docs.sh
verify_boilerplate:
$(HACK_DIR)/verify-boilerplate.sh
verify_codegen: depend
$(HACK_DIR)/verify-codegen.sh
verify_vendor: $(BINDIR)/dep
dep ensure -no-vendor -dry-run -v
verify_gen_docs: verify_reference_docs verify_cmd_docs
verify_reference_docs: $(BINDIR)/node
$(HACK_DIR)/verify-reference-docs.sh
verify_cmd_docs:
$(HACK_DIR)/verify-cmd-docs.sh
SUBTREES = etcd calico aws_ebs kubernetes kubernetes_addons prometheus tarmak vault_client
subtrees:
for module in $(SUBTREES); do \
echo $$module; \
git subtree pull --prefix puppet/modules/$$module git://github.com/jetstack/puppet-module-$$module.git master; \
done
prepare_release:
ifndef VERSION
$(error VERSION is undefined)
endif
# replace wing version in terraform
sed -i 's/Environment=WING_VERSION=[[:digit:]].*$$/Environment=WING_VERSION=$(VERSION)/g' terraform/amazon/templates/bastion_user_data.yaml.template terraform/amazon/templates/puppet_agent_user_data.yaml.template
# replace major version in docs
sed -i 's#^version = u.*$$#version = u"$(shell echo "$(VERSION)" | grep -oe "^[0-9]\{1,\}\\.[0-9]\{1,\}")"#g' docs/conf.py
sed -i 's#^release = u.*$$#release = u"$(shell echo "$(VERSION)" | grep -oe "^[0-9]\{1,\}\\.[0-9]\{1,\}")"#g' docs/conf.py
# replace version in README
sed -i 's#wget https://github.com/jetstack/tarmak/releases/download/.*$$#wget https://github.com/jetstack/tarmak/releases/download/$(VERSION)/tarmak_$(VERSION)_linux_amd64#g' README.md
sed -i 's/mv tarmak_.*$$/mv tarmak_$(VERSION)_linux_amd64 tarmak/g' README.md
git add -p docs/conf.py terraform/amazon/templates/bastion_user_data.yaml.template terraform/amazon/templates/puppet_agent_user_data.yaml.template README.md
git commit -m "Release $(VERSION)"
git tag $(VERSION)
_output/wing_linux_amd64: $(WING_GO_FILES)
mkdir -p _output/
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -tags netgo -o $@ -ldflags '-w $(shell hack/version-ldflags.sh)' ./cmd/wing
_output/tagging_control_linux_amd64: $(TAGGING_CONTROL_GO_FILES)
mkdir -p _output/
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -tags netgo -o $@ -ldflags '-w $(shell hack/version-ldflags.sh)' ./cmd/tagging_control
_output/tarmak: $(TARMAK_GO_FILES)
mkdir -p _output/
CGO_ENABLED=0 go build -tags netgo -o $@ -ldflags '-w $(shell hack/version-ldflags.sh)' ./cmd/tarmak
_output/tarmak_linux_amd64: $(TARMAK_GO_FILES)
mkdir -p _output/
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -tags netgo -o $@ -ldflags '-w $(shell hack/version-ldflags.sh)' ./cmd/tarmak
_output/tarmak_darwin_amd64: $(TARMAK_GO_FILES)
mkdir -p _output/
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -tags netgo -o $@ -ldflags '-w $(shell hack/version-ldflags.sh)' ./cmd/tarmak
pkg/tarmak/mocks/tarmak.go: pkg/tarmak/interfaces/interfaces.go $(BINDIR)/mockgen
mockgen -package=mocks -source=pkg/tarmak/interfaces/interfaces.go -destination $@
pkg/tarmak/mocks/amazon.go: pkg/tarmak/provider/amazon/amazon.go $(BINDIR)/mockgen
mockgen -package=mocks -source=pkg/tarmak/provider/amazon/amazon.go -destination $@
pkg/tarmak/binaries/binaries_bindata.go: _output/wing_linux_amd64 _output/tagging_control_linux_amd64 pkg/tarmak/binaries/binaries.go $(BINDIR)/go-bindata
go generate ./pkg/tarmak/binaries
pkg/tarmak/assets/assets_bindata.go: $(shell find packer/ puppet/ terraform/ -type f) pkg/tarmak/assets/assets.go $(BINDIR)/go-bindata
go generate ./pkg/tarmak/assets
pkg/wing/mocks/http_client.go: vendor/k8s.io/client-go/rest/request.go $(BINDIR)/mockgen
mockgen -package=mocks -source=vendor/k8s.io/client-go/rest/request.go -destination $@
pkg/wing/mocks/command.go: pkg/wing/command.go $(BINDIR)/mockgen
mockgen -package=mocks -source=pkg/wing/command.go -destination $@
pkg/wing/mocks/client.go: $(shell go list -f '{{ $$global := .}}{{ range .GoFiles }}{{ printf "%s/%s\n" $$global.Dir . }}{{ end}}' ./vendor/k8s.io/client-go/rest) $(BINDIR)/mockgen
mockgen -destination $@ -package=mocks k8s.io/client-go/rest Interface
## Release instructions
.PHONY: release
release: _output/tarmak_linux_amd64 _output/tarmak_darwin_amd64 _output/wing_linux_amd64 _output/tagging_control_linux_amd64 $(BINDIR)/upx $(BINDIR)/ghr ## Build release binaries and publish them to github
hack/release-github.sh
docker_%:
# create a container
$(eval CONTAINER_ID := $(shell docker create \
-i \
-w $(CONTAINER_DIR) \
golang:${GO_VERSION} \
/bin/bash -c "make $*" \
))
# copy stuff into container
(git ls-files && git ls-files --others --exclude-standard) | tar cf - -T - | docker cp - $(CONTAINER_ID):$(CONTAINER_DIR)
# run build inside container
docker start -a -i $(CONTAINER_ID)
# copy artifacts over
docker cp $(CONTAINER_ID):$(CONTAINER_DIR)/wing_linux_amd64 wing_linux_amd64
docker cp $(CONTAINER_ID):$(CONTAINER_DIR)/tarmak_linux_amd64 tarmak_linux_amd64
docker cp $(CONTAINER_ID):$(CONTAINER_DIR)/tarmak_darwin_amd64 tarmak_darwin_amd64
# remove container
docker rm $(CONTAINER_ID)
.PHONY: e2e-all e2e-all-conformance e2e-single-cluster e2e-multi-cluster e2e-upgrade-cluster e2e-upgrade-kubernetes
e2e-all: build ## Run all quick end to end tests
go test -v -timeout 1h github.com/jetstack/tarmak/cmd/tarmak/e2e -e2e -ldflags '-w $(shell hack/version-ldflags.sh)'
e2e-all-conformance: build ## Run all slow end to end tests with conformance
go test -v -timeout 1h github.com/jetstack/tarmak/cmd/tarmak/e2e -e2e -ldflags '-w $(shell hack/version-ldflags.sh) -X \'github.com/jetstack/tarmak/cmd/tarmak/e2e.mode=Conformance\''
e2e-single-cluster: build
go test -v -timeout 1h github.com/jetstack/tarmak/cmd/tarmak/e2e -e2e -ldflags '-w $(shell hack/version-ldflags.sh)' -run Single
e2e-multi-cluster: build
go test -v -timeout 1h github.com/jetstack/tarmak/cmd/tarmak/e2e -e2e -ldflags '-w $(shell hack/version-ldflags.sh)' -run Multi
e2e-upgrade-cluster: build
go test -v -timeout 1h github.com/jetstack/tarmak/cmd/tarmak/e2e -e2e -ldflags '-w $(shell hack/version-ldflags.sh)' -run UpgradeTarmak
e2e-upgrade-kubernetes: build
go test -v -timeout 1h github.com/jetstack/tarmak/cmd/tarmak/e2e -e2e -ldflags '-w $(shell hack/version-ldflags.sh)' -run UpgradeKubernetes