forked from brigadecore/brigade
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
573 lines (486 loc) · 16.3 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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
SHELL ?= /bin/bash
.DEFAULT_GOAL := build
################################################################################
# Version details #
################################################################################
# This will reliably return the short SHA1 of HEAD or, if the working directory
# is dirty, will return that + "-dirty"
GIT_VERSION = $(shell git describe --always --abbrev=7 --dirty --match=NeVeRmAtCh)
################################################################################
# Containerized development environment-- or lack thereof #
################################################################################
ifneq ($(SKIP_DOCKER),true)
PROJECT_ROOT := $(dir $(realpath $(firstword $(MAKEFILE_LIST))))
GO_DEV_IMAGE := brigadecore/go-tools:v0.8.0
GO_DOCKER_CMD := docker run \
-it \
--rm \
-e SKIP_DOCKER=true \
-e GITHUB_TOKEN=$${GITHUB_TOKEN} \
-e GOCACHE=/workspaces/brigade/.gocache \
-v $(PROJECT_ROOT):/workspaces/brigade \
-w /workspaces/brigade \
$(GO_DEV_IMAGE)
JS_DEV_IMAGE := node:16.11.0-bullseye
JS_DOCKER_CMD := docker run \
-it \
--rm \
-e NPM_TOKEN=$${NPM_TOKEN} \
-e SKIP_DOCKER=true \
-v $(PROJECT_ROOT):/workspaces/brigade \
-w /workspaces/brigade \
$(JS_DEV_IMAGE)
HELM_IMAGE := brigadecore/helm-tools:v0.4.0
HELM_DOCKER_CMD := docker run \
-it \
--rm \
-e SKIP_DOCKER=true \
-e HELM_PASSWORD=$${HELM_PASSWORD} \
-v $(PROJECT_ROOT):/workspaces/brigade \
-w /workspaces/brigade \
$(HELM_IMAGE)
endif
################################################################################
# Binaries and Docker images we build and publish #
################################################################################
ifdef DOCKER_REGISTRY
DOCKER_REGISTRY := $(DOCKER_REGISTRY)/
endif
ifdef DOCKER_ORG
DOCKER_ORG := $(DOCKER_ORG)/
endif
DOCKER_IMAGE_PREFIX := $(DOCKER_REGISTRY)$(DOCKER_ORG)brigade2-
ifdef HELM_REGISTRY
HELM_REGISTRY := $(HELM_REGISTRY)/
endif
ifdef HELM_ORG
HELM_ORG := $(HELM_ORG)/
endif
HELM_CHART_PREFIX := $(HELM_REGISTRY)$(HELM_ORG)
ifdef VERSION
MUTABLE_DOCKER_TAG := latest
else
VERSION := $(GIT_VERSION)
MUTABLE_DOCKER_TAG := edge
endif
IMMUTABLE_DOCKER_TAG := $(VERSION)
################################################################################
# Tests #
################################################################################
.PHONY: lint-go
lint-go:
$(GO_DOCKER_CMD) sh -c ' \
cd sdk/v3 && \
golangci-lint run --config ../../golangci.yaml && \
cd ../../v2 && \
golangci-lint run --config ../golangci.yaml \
'
.PHONY: test-unit-go
test-unit-go:
$(GO_DOCKER_CMD) sh -c ' \
cd sdk/v3 && \
go test \
-v \
-timeout=60s \
-race \
-coverprofile=coverage.txt \
-covermode=atomic \
./... && \
cd ../../v2 && \
go test \
-v \
-timeout=60s \
-race \
-coverprofile=coverage.txt \
-covermode=atomic \
./... \
'
.PHONY: style-check-js
style-check-js:
$(JS_DOCKER_CMD) sh -c ' \
cd v2/brigadier && \
yarn install && \
yarn style:check && \
cd ../brigadier-polyfill && \
yarn install && \
yarn style:check && \
cd ../worker && \
yarn install && \
yarn style:check \
'
.PHONY: lint-js
lint-js:
$(JS_DOCKER_CMD) sh -c ' \
cd v2/brigadier && \
yarn install && \
yarn lint && \
cd ../brigadier-polyfill && \
yarn install && \
yarn lint && \
cd ../worker && \
yarn install && \
yarn lint \
'
.PHONY: yarn-audit
yarn-audit:
$(JS_DOCKER_CMD) sh -c ' \
cd v2/brigadier && \
yarn install && \
yarn audit && \
cd ../brigadier-polyfill && \
yarn install && \
yarn audit && \
cd ../worker && \
yarn install && \
yarn audit \
'
.PHONY: clean-js
clean-js:
$(JS_DOCKER_CMD) sh -c ' \
rm -rf \
v2/brigadier/dist \
v2/brigadier/node_modules \
v2/brigadier-polyfill/dist \
v2/brigadier-polyfill/node_modules \
v2/worker/dist \
v2/worker/node_modules \
'
.PHONY: test-unit-js
test-unit-js:
$(JS_DOCKER_CMD) sh -c ' \
cd v2/brigadier && \
yarn install && \
yarn test && \
yarn build && \
cd ../brigadier-polyfill && \
yarn install && \
yarn test \
'
.PHONY: lint-chart
lint-chart:
$(HELM_DOCKER_CMD) sh -c ' \
cd charts/brigade && \
helm dep up && \
helm lint . \
'
APISERVER_ADDRESS ?= "https://localhost:7000"
APISERVER_ROOT_PASSWORD ?= "F00Bar!!!"
.PHONY: test-integration
test-integration: hack-expose-apiserver
@export VERSION="$(VERSION)" \
APISERVER_ADDRESS="$(APISERVER_ADDRESS)" \
APISERVER_ROOT_PASSWORD="$(APISERVER_ROOT_PASSWORD)" && \
cd v2 && \
go test \
-v \
--count=1 \
-timeout=10m \
-tags=integration \
./tests/... || (cd - && $(MAKE) hack-unexpose-apiserver && exit 1)
@$(MAKE) hack-unexpose-apiserver
# Validates the schemas in the v2/apiserver/schemas dir
#
# Adds references to any schema that are themselves $ref'd
# in any of the others.
.PHONY: validate-schemas
validate-schemas:
$(JS_DOCKER_CMD) sh -c ' \
npm install -g [email protected] && \
for schema in $$(ls v2/apiserver/schemas/*.json); do \
ajv compile -s $$schema \
-r v2/apiserver/schemas/common.json \
-r v2/apiserver/schemas/source-state.json ; \
done \
'
# Validates the examples in the examples/ dir
#
# Currently, they are project-specific;
# we can add event, job, etc. examples and add validation here.
.PHONY: validate-examples
validate-examples:
$(JS_DOCKER_CMD) sh -c ' \
npm install -g [email protected] && \
echo "Validating example projects..." && \
for project in $$(ls examples/*/project.yaml); do \
ajv validate -d $$project \
-s v2/apiserver/schemas/project.json \
-r v2/apiserver/schemas/common.json ; \
done \
'
################################################################################
# Build #
################################################################################
.PHONY: build
build: build-brigadier build-images build-cli
.PHONY: build-brigadier
build-brigadier:
$(JS_DOCKER_CMD) sh -c ' \
cd v2/brigadier && \
yarn install && \
yarn build && \
yarn build-docs \
'
.PHONY: build-images
build-images: build-apiserver build-artemis build-git-initializer build-logger build-observer build-scheduler build-worker
.PHONY: build-apiserver
build-apiserver: build-distroless-apiserver
.PHONY: build-artemis
build-artemis: build-alpine-artemis
.PHONY: build-git-initializer
build-git-initializer: build-distroless-git-initializer
.PHONY: build-git-initializer-windows
build-git-initializer-windows:
docker build \
-f v2/git-initializer-windows/Dockerfile \
-t $(DOCKER_IMAGE_PREFIX)git-initializer-windows:$(IMMUTABLE_DOCKER_TAG) \
-t $(DOCKER_IMAGE_PREFIX)git-initializer-windows:$(MUTABLE_DOCKER_TAG) \
--build-arg VERSION=$(VERSION) \
--build-arg COMMIT=$(GIT_VERSION) \
.
.PHONY: build-logger
build-logger: build-alpine-logger
.PHONY: build-logger-windows
build-logger-windows:
docker build \
-f v2/logger-windows/Dockerfile \
-t $(DOCKER_IMAGE_PREFIX)logger-windows:$(IMMUTABLE_DOCKER_TAG) \
-t $(DOCKER_IMAGE_PREFIX)logger-windows:$(MUTABLE_DOCKER_TAG) \
--build-arg VERSION=$(VERSION) \
--build-arg COMMIT=$(GIT_VERSION) \
.
.PHONY: build-observer
build-observer: build-distroless-observer
.PHONY: build-scheduler
build-scheduler: build-distroless-scheduler
.PHONY: build-worker
build-worker: build-distroless-worker
.PHONY: build-alpine-%
build-alpine-%:
docker buildx build \
-f v2/$*/Dockerfile \
-t $(DOCKER_IMAGE_PREFIX)$*:$(IMMUTABLE_DOCKER_TAG) \
-t $(DOCKER_IMAGE_PREFIX)$*:$(MUTABLE_DOCKER_TAG) \
--build-arg VERSION=$(VERSION) \
--build-arg COMMIT=$(GIT_VERSION) \
--platform linux/amd64,linux/arm64v8 \
.
.PHONY: build-distroless-%
build-distroless-%:
docker buildx build \
-f v2/$*/Dockerfile \
-t $(DOCKER_IMAGE_PREFIX)$*:$(IMMUTABLE_DOCKER_TAG) \
-t $(DOCKER_IMAGE_PREFIX)$*:$(MUTABLE_DOCKER_TAG) \
--build-arg VERSION=$(VERSION) \
--build-arg COMMIT=$(GIT_VERSION) \
--platform linux/amd64,linux/arm64 \
.
.PHONY: build-cli
build-cli:
$(GO_DOCKER_CMD) sh -c ' \
cd v2 && \
VERSION=$(VERSION) \
COMMIT=$(GIT_VERSION) \
OSES="linux darwin windows" \
ARCHS=amd64 \
../scripts/build-cli.sh && \
VERSION=$(VERSION) \
COMMIT=$(GIT_VERSION) \
OSES="linux darwin" \
ARCHS=arm64 \
../scripts/build-cli.sh \
'
################################################################################
# Image security #
################################################################################
.PHONY: scan-%
scan-%:
grype $(DOCKER_IMAGE_PREFIX)$*:$(IMMUTABLE_DOCKER_TAG) -f medium
################################################################################
# Publish #
################################################################################
.PHONY: publish
publish: publish-brigadier push-images publish-chart publish-cli
.PHONY: publish-brigadier
publish-brigadier: build-brigadier
$(JS_DOCKER_CMD) sh -c ' \
cd v2/brigadier && \
echo '//registry.npmjs.org/:_authToken=${NPM_TOKEN}' > .npmrc && \
yarn publish \
--new-version $$(printf $(VERSION) | cut -c 2- ) \
--access public \
--no-git-tag-version \
'
.PHONY: publish-brigadier-docs
publish-brigadier-docs: build-brigadier
$(JS_DOCKER_CMD) sh -c ' \
cd v2/brigadier && \
yarn publish-docs \
'
.PHONY: push-images
push-images: push-apiserver push-artemis push-git-initializer push-logger push-observer push-scheduler push-worker
.PHONY: push-apiserver
push-apiserver: push-distroless-apiserver
.PHONY: push-artemis
push-artemis: push-alpine-artemis
.PHONY: push-git-initializer
push-git-initializer: push-distroless-git-initializer
.PHONY: push-git-initializer-windows
push-git-initializer-windows:
docker push $(DOCKER_IMAGE_PREFIX)git-initializer-windows:$(IMMUTABLE_DOCKER_TAG)
docker push $(DOCKER_IMAGE_PREFIX)git-initializer-windows:$(MUTABLE_DOCKER_TAG)
.PHONY: push-logger
push-logger: push-alpine-logger
.PHONY: push-logger-windows
push-logger-windows:
docker push $(DOCKER_IMAGE_PREFIX)logger-windows:$(IMMUTABLE_DOCKER_TAG)
docker push $(DOCKER_IMAGE_PREFIX)logger-windows:$(MUTABLE_DOCKER_TAG)
.PHONY: push-observer
push-observer: push-distroless-observer
.PHONY: push-scheduler
push-scheduler: push-distroless-scheduler
.PHONY: push-worker
push-worker: push-distroless-worker
.PHONY: push-alpine-%
push-alpine-%:
docker buildx build \
-f v2/$*/Dockerfile \
-t $(DOCKER_IMAGE_PREFIX)$*:$(IMMUTABLE_DOCKER_TAG) \
-t $(DOCKER_IMAGE_PREFIX)$*:$(MUTABLE_DOCKER_TAG) \
--build-arg VERSION=$(VERSION) \
--build-arg COMMIT=$(GIT_VERSION) \
--platform linux/amd64,linux/arm64v8 \
--push \
.
.PHONY: push-distroless-%
push-distroless-%:
docker buildx build \
-f v2/$*/Dockerfile \
-t $(DOCKER_IMAGE_PREFIX)$*:$(IMMUTABLE_DOCKER_TAG) \
-t $(DOCKER_IMAGE_PREFIX)$*:$(MUTABLE_DOCKER_TAG) \
--build-arg VERSION=$(VERSION) \
--build-arg COMMIT=$(GIT_VERSION) \
--platform linux/amd64,linux/arm64 \
--push \
.
.PHONY: publish-chart
publish-chart:
$(HELM_DOCKER_CMD) sh -c ' \
cd charts/brigade && \
helm dep up && \
helm package . --version $(VERSION) --app-version $(VERSION) && \
helm push brigade-$(VERSION).tgz oci:https://$(HELM_REGISTRY)$(HELM_ORG) \
'
.PHONY: publish-cli
publish-cli: build-cli
$(GO_DOCKER_CMD) sh -c ' \
go get github.com/tcnksm/ghr && \
ghr \
-u $(GITHUB_ORG) \
-r $(GITHUB_REPO) \
-c $$(git rev-parse HEAD) \
-t $${GITHUB_TOKEN} \
-n ${VERSION} \
${VERSION} ./bin \
'
################################################################################
# Targets to facilitate hacking on Brigade. #
################################################################################
.PHONY: hack-new-kind-cluster
hack-new-kind-cluster:
hack/kind/new-cluster.sh
.PHONY: hack-build-images
hack-build-images: hack-build-apiserver hack-build-artemis hack-build-git-initializer hack-build-logger hack-build-observer hack-build-scheduler hack-build-worker
.PHONY: hack-build-%
hack-build-%:
docker build \
-f v2/$*/Dockerfile \
-t $(DOCKER_IMAGE_PREFIX)$*:$(IMMUTABLE_DOCKER_TAG) \
--build-arg VERSION='$(VERSION)' \
--build-arg COMMIT='$(GIT_VERSION)' \
.
.PHONY: hack-build-cli
hack-build-cli:
$(GO_DOCKER_CMD) sh -c ' \
cd v2 && \
OSES=$(shell go env GOOS) \
ARCHS=$(shell go env GOARCH) \
VERSION="$(VERSION)" \
COMMIT="$(GIT_VERSION)" \
../scripts/build-cli.sh \
'
.PHONY: hack-push-images
hack-push-images: hack-push-artemis hack-push-apiserver hack-push-scheduler hack-push-observer hack-push-logger hack-push-git-initializer hack-push-worker
.PHONY: hack-push-%
hack-push-%: hack-build-%
docker push $(DOCKER_IMAGE_PREFIX)$*:$(IMMUTABLE_DOCKER_TAG)
IMAGE_PULL_POLICY ?= Always
.PHONY: hack-deploy
hack-deploy:
kubectl get namespace brigade || kubectl create namespace brigade
helm dep up charts/brigade && \
helm upgrade brigade charts/brigade \
--install \
--namespace brigade \
--wait \
--timeout 600s \
--set artemis.image.repository=$(DOCKER_IMAGE_PREFIX)artemis \
--set artemis.image.tag=$(IMMUTABLE_DOCKER_TAG) \
--set artemis.image.pullPolicy=$(IMAGE_PULL_POLICY) \
--set apiserver.image.repository=$(DOCKER_IMAGE_PREFIX)apiserver \
--set apiserver.image.tag=$(IMMUTABLE_DOCKER_TAG) \
--set apiserver.image.pullPolicy=$(IMAGE_PULL_POLICY) \
--set apiserver.service.type=NodePort \
--set apiserver.service.nodePort=31600 \
--set apiserver.rootUser.password="${APISERVER_ROOT_PASSWORD}" \
--set scheduler.image.repository=$(DOCKER_IMAGE_PREFIX)scheduler \
--set scheduler.image.tag=$(IMMUTABLE_DOCKER_TAG) \
--set scheduler.image.pullPolicy=$(IMAGE_PULL_POLICY) \
--set observer.image.repository=$(DOCKER_IMAGE_PREFIX)observer \
--set observer.image.tag=$(IMMUTABLE_DOCKER_TAG) \
--set observer.image.pullPolicy=$(IMAGE_PULL_POLICY) \
--set worker.image.repository=$(DOCKER_IMAGE_PREFIX)worker \
--set worker.image.tag=$(IMMUTABLE_DOCKER_TAG) \
--set worker.image.pullPolicy=$(IMAGE_PULL_POLICY) \
--set gitInitializer.linux.image.repository=$(DOCKER_IMAGE_PREFIX)git-initializer \
--set gitInitializer.linux.image.tag=$(IMMUTABLE_DOCKER_TAG) \
--set gitInitializer.linux.image.pullPolicy=$(IMAGE_PULL_POLICY) \
--set logger.linux.image.repository=$(DOCKER_IMAGE_PREFIX)logger\
--set logger.linux.image.tag=$(IMMUTABLE_DOCKER_TAG) \
--set logger.linux.image.pullPolicy=$(IMAGE_PULL_POLICY)
.PHONY: hack
hack: hack-push-images hack-build-cli hack-deploy
.PHONY: hack-expose-apiserver
hack-expose-apiserver:
@kubectl --namespace brigade port-forward service/brigade-apiserver 7000:443 &>/dev/null & \
echo $$! > /tmp/brigade-apiserver.PID
.PHONY: hack-unexpose-apiserver
hack-unexpose-apiserver:
@kill -TERM $$(cat /tmp/brigade-apiserver.PID)
# Convenience targets for loading images into a KinD cluster
.PHONY: hack-load-images
hack-load-images: load-artemis load-apiserver load-scheduler load-observer load-logger load-git-initializer load-worker
load-%:
@echo "Loading $(DOCKER_IMAGE_PREFIX)$*:$(IMMUTABLE_DOCKER_TAG)"
@kind load docker-image $(DOCKER_IMAGE_PREFIX)$*:$(IMMUTABLE_DOCKER_TAG) \
|| echo >&2 "kind not installed or error loading image: $(DOCKER_IMAGE_PREFIX)$*:$(IMMUTABLE_DOCKER_TAG)"
################################################################################
# Docs Preview targets. #
################################################################################
docs-stop-preview:
@docker rm -f brigade-docs &> /dev/null || true
docs-preview: docs-stop-preview
@docker run -d -v $$PWD:/src -p 1313:1313 --name brigade-docs -w /src/docs \
klakegg/hugo:0.54.0-ext-alpine server -D -F --noHTTPCache --watch --bind=0.0.0.0
# Wait for the documentation web server to finish rendering
@until docker logs brigade-docs | grep -m 1 "Web Server is available"; do : ; done
@open "https://localhost:1313"
.PHONY: stop-brigadier-docs-preview
stop-brigadier-docs-preview:
@docker rm -f brigadier-docs &> /dev/null || true
.PHONY: brigadier-docs-preview
brigadier-docs-preview: stop-brigadier-docs-preview build-brigadier
@docker run -d \
-v $$PWD/v2/brigadier/docs:/srv/jekyll \
-p 4000:4000 \
--name brigadier-docs \
jekyll/jekyll:latest jekyll serve