forked from banzaicloud/pipeline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.plz
246 lines (200 loc) · 8.87 KB
/
Makefile.plz
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
# A Self-Documenting Makefile: http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
SHELL = /bin/bash
OS = $(shell uname | tr A-Z a-z)
export PATH := $(abspath bin/):${PATH}
# Build variables
BUILD_DIR ?= build
VERSION ?= $(shell git describe --tags --exact-match 2>/dev/null || git symbolic-ref -q --short HEAD)
COMMIT_HASH ?= $(shell git rev-parse --short HEAD 2>/dev/null)
BUILD_DATE ?= $(shell date +%FT%T%z)
HELM_VERSION = $(shell cat go.mod | grep helm.sh/helm/v3 | grep -v "=>" | cut -d" " -f2 | sed s/^v//)
LDFLAGS += -X main.version=${VERSION} -X main.commitHash=${COMMIT_HASH} -X main.buildDate=${BUILD_DATE} -X main.helmVersion=${HELM_VERSION}
export CGO_ENABLED ?= 0
ifeq ($(VERBOSE), 1)
ifeq ($(filter -v,${GOARGS}),)
GOARGS += -v
endif
TEST_FORMAT = short-verbose
endif
.PHONY: up
up: ## Set up the development environment
./pleasew up
.PHONY: down
down: ## Destroy the development environment
./pleasew down
# No replacement: not really useful
.PHONY: reset
reset: down up ## Reset the development environment
# No replacement: binaries will be stored in plz-out
.PHONY: clean
clean: ## Clean the working area and the project
rm -rf bin/ ${BUILD_DIR}/
rm -rf pipeline
.PHONY: start
start: ## Start docker development environment
./pleasew start
.PHONY: stop
stop: ## Stop docker development environment
./pleasew stop
config/config.yaml:
./pleasew make //config:config.yaml
config/ui/feature-set.json:
./pleasew make //config/ui:feature-set.json
etc/config/dex.yml:
./pleasew make //etc/config:dex.yml
.PHONY: run
run: GOTAGS += dev
run: ## Build and execute a binary
PIPELINE_CONFIG_DIR=$${PWD}/config VAULT_ADDR="http://127.0.0.1:8200" ./pleasew run --rebuild //cmd/pipeline ${ARGS}
.PHONY: debug
debug: GOTAGS += dev
debug:
PIPELINE_CONFIG_DIR=$${PWD}/config VAULT_ADDR="http://127.0.0.1:8200" dlv --listen=:40000 --log --headless=true --api-version=2 exec $(shell ./pleasew build --rebuild -c dbg //cmd/pipeline && ./pleasew query output -c dbg //cmd/pipeline) -- $(ARGS)
.PHONY: debug-worker
debug-worker: GOTAGS += dev
debug-worker:
PIPELINE_CONFIG_DIR=$${PWD}/config VAULT_ADDR="http://127.0.0.1:8200" dlv --listen=:40000 --log --headless=true --api-version=2 exec $(shell ./pleasew build --rebuild -c dbg //cmd/worker && ./pleasew query output -c dbg //cmd/worker) -- $(ARGS)
.PHONY: run-worker
run-worker: GOTAGS += dev
run-worker: ## Build and execute a binary
PIPELINE_CONFIG_DIR=$${PWD}/config VAULT_ADDR="http://127.0.0.1:8200" ./pleasew run --rebuild //cmd/worker ${ARGS}
.PHONY: runall ## Run worker and pipeline in foreground. Use with make -j.
runall:
PIPELINE_CONFIG_DIR=$${PWD}/config VAULT_ADDR="http://127.0.0.1:8200" ./pleasew run --rebuild parallel //cmd/pipeline //cmd/worker
.PHONY: build
build: ## Build all binaries
@mkdir -p ${BUILD_DIR}
./pleasew build --rebuild //cmd/...
./pleasew export outputs -o ${BUILD_DIR} //cmd/...
.PHONY: build-release
build-release: ## Build all binaries without debug information
@${MAKE} BUILD_DIR="${BUILD_DIR}/release" build
.PHONY: build-debug
build-debug: ## Build all binaries with remote debugging capabilities
@${MAKE} BUILD_DIR="${BUILD_DIR}/debug" build
.PHONY: docker
docker: ## Build a Docker image
@${MAKE} GOOS=linux GOARCH=amd64 build-release
docker build -t banzaicloud/pipeline:local -f Dockerfile.local .
.PHONY: docker-debug
docker-debug: ## Build a Docker image with remote debugging capabilities
@${MAKE} GOOS=linux GOARCH=amd64 build-debug
docker build -t banzaicloud/pipeline:debug -f Dockerfile.debug .
.PHONY: check
check: test lint ## Run tests and linters
# Remove once fully migrated
bin/golangci-lint:
./pleasew build ///pleasings2//tools/go:golangci-lint
cp $(shell ./pleasew query output ///pleasings2//tools/go:golangci-lint) bin/golangci-lint
.PHONY: lint
lint: export CGO_ENABLED = 1
lint: ## Run linter
./pleasew lint
cd pkg/sdk && ../../$(shell ./pleasew query output ///pleasings2//tools/go:golangci-lint) run
.PHONY: fix
fix: export CGO_ENABLED = 1
fix: ## Fix lint violations
./pleasew lint --fix
cd pkg/sdk && ../../$(shell ./pleasew query output ///pleasings2//tools/go:golangci-lint) run --fix
bin/licensei:
./pleasew build ///pleasings2//tools/misc:licensei
cp $(shell ./pleasew query output ///pleasings2//tools/misc:licensei) bin/licensei
.PHONY: license-check
license-check: ## Run license check
./pleasew run ///pleasings2//tools/misc:licensei -- check
./pleasew run ///pleasings2//tools/misc:licensei -- header
.PHONY: license-cache
license-cache: ## Generate license cache
./pleasew run ///pleasings2//tools/misc:licensei -- cache
# Remove once fully migrated
bin/gotestsum:
./pleasew build ///pleasings2//tools/go:gotestsum
cp $(shell ./pleasew query output ///pleasings2//tools/go:gotestsum) bin/gotestsum
.PHONY: test
TEST_PKGS ?= ./...
TEST_REPORT_NAME ?= results.xml
.PHONY: test
test: TEST_REPORT ?= main
test: TEST_FORMAT ?= short
test: SHELL = /bin/bash
test: export CGO_ENABLED = 1
test: ## Run tests
@mkdir -p ${BUILD_DIR}/test_results/${TEST_REPORT}
./pleasew run ///pleasings2//tools/go:gotestsum -- --no-summary=skipped --junitfile ${BUILD_DIR}/test_results/${TEST_REPORT}/${TEST_REPORT_NAME} --format ${TEST_FORMAT} -- $(filter-out -v,${GOARGS}) $(if ${TEST_PKGS},${TEST_PKGS},./...)
cd pkg/sdk && ../../$(shell ./pleasew query output ///pleasings2//tools/go:gotestsum) --no-summary=skipped --junitfile ../../${BUILD_DIR}/test_results/${TEST_REPORT}/${TEST_REPORT_NAME} --format ${TEST_FORMAT} -- $(filter-out -v,${GOARGS}) $(if ${TEST_PKGS},${TEST_PKGS},./...)
.PHONY: test-all
test-all: ## Run all tests
@${MAKE} GOARGS="${GOARGS} -run .\*" TEST_REPORT=all test
.PHONY: test-integration
test-integration: bin/test/kube-apiserver bin/test/etcd ## Run integration tests
@${MAKE} TEST_ASSET_KUBE_APISERVER=$(abspath bin/test/kube-apiserver) TEST_ASSET_ETCD=$(abspath bin/test/etcd) GOARGS="${GOARGS} -run ^TestIntegration\$$\$$" TEST_REPORT=integration test
bin/test/kube-apiserver:
if ! echo "amd64 arm64" | grep -q -w "$(ARCH)"; then \
printf >&2 "unsupported kube-apiserver architecture %s\n" "$(ARCH)" ; \
exit 1 ; \
fi
if ! echo "linux" | grep -q -w "$(OS)"; then \
printf >&2 "unsupported kube-apiserver operating system %s\n" "$(OS)" ; \
exit 1 ; \
fi
@mkdir -p bin/test
curl -L -o bin/test/kube-apiserver https://dl.k8s.io/v$(KUBE_APISERVER_VERSION)/bin/$(OS)/$(ARCH)/kube-apiserver
chmod +x bin/test/kube-apiserver
bin/test/etcd:
if ! echo "amd64 arm64" | grep -q -w "$(ARCH)"; then \
printf >&2 "unsupported etcd architecture %s\n" "$(ARCH)" ; \
exit 1 ; \
fi
if ! echo "darwin linux" | grep -q -w "$(OS)"; then \
printf >&2 "unsupported etcd operating system %s\n" "$(OS)" ; \
exit 1 ; \
fi
@mkdir -p bin/test
if [ "$(OS)" == "darwin" ] ; then \
curl -L https://github.com/etcd-io/etcd/releases/download/v$(ETCD_VERSION)/etcd-v$(ETCD_VERSION)-$(OS)-$(ARCH).zip | tar -xv -C bin/test ; \
elif [ "$(OS)" == "linux" ] ; then \
curl -L https://github.com/etcd-io/etcd/releases/download/v$(ETCD_VERSION)/etcd-v$(ETCD_VERSION)-$(OS)-$(ARCH).tar.gz | tar -xvz -C bin/test ; \
fi
mv bin/test/etcd-v$(ETCD_VERSION)-$(OS)-$(ARCH)/etcd bin/test/etcd
chmod +x bin/test/etcd
rm -fr bin/test/etcd-v$(ETCD_VERSION)-$(OS)-$(ARCH)
bin/migrate:
./pleasew build ///pleasings2//tools/misc:migrate
cp $(shell ./pleasew query output ///pleasings2//tools/misc:migrate) bin/migrate
# Remove once fully migrated
bin/mga:
./pleasew build ///pleasings2//tools/go:mga
cp $(shell ./pleasew query output ///pleasings2//tools/go:mga) bin/mga
.PHONY: generate
generate: ## Generate code
go generate -x ./...
./pleasew run ///pleasings2//tools/go:mga gen kit endpoint ./...
./pleasew run ///pleasings2//tools/go:mga gen ev dispatcher ./...
./pleasew run ///pleasings2//tools/go:mga gen ev handler ./...
./pleasew run ///pleasings2//tools/go:mga gen testify mock ./...
.PHONY: validate-openapi
validate-openapi: ## Validate the openapi description
./pleasew test //apis/pipeline:validate
.PHONY: generate-openapi
generate-openapi: ## Generate go server based on openapi description
./pleasew make //apis/pipeline
apis/cloudinfo/openapi.yaml:
./pleasew make //apis/cloudinfo:spec
.PHONY: generate-cloudinfo-client
generate-cloudinfo-client: ## Generate client from Cloudinfo OpenAPI spec
./pleasew make //apis/cloudinfo
apis/anchore/swagger.yaml:
./pleasew make //apis/anchore:spec
.PHONY: generate-anchore-client
generate-anchore-client: ## Generate client from Anchore OpenAPI spec
./pleasew make //apis/anchore
.PHONY: list
list: ## List all make targets
@$(MAKE) -pRrn : -f $(MAKEFILE_LIST) 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | sort
.PHONY: help
.DEFAULT_GOAL := help
help:
@grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
# Variable outputting/exporting rules
var-%: ; @echo $($*)
varexport-%: ; @echo $*=$($*)