forked from brigadecore/brigade
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
263 lines (214 loc) · 9.42 KB
/
Makefile
File metadata and controls
263 lines (214 loc) · 9.42 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
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
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)
################################################################################
# Go build details #
################################################################################
BASE_PACKAGE_NAME := github.com/brigadecore/brigade
CLIENT_PLATFORM ?= $(shell go env GOOS)
CLIENT_ARCH ?= $(shell go env GOARCH)
################################################################################
# Containerized development environment-- or lack thereof #
################################################################################
ifneq ($(SKIP_DOCKER),true)
PROJECT_ROOT := $(dir $(realpath $(firstword $(MAKEFILE_LIST))))
GO_DEV_IMAGE := quay.io/deis/lightweight-docker-go:v0.7.0
JS_DEV_IMAGE := node:12.3.1-stretch
GO_DOCKER_CMD := docker run \
-it \
--rm \
-e SKIP_DOCKER=true \
-v $(PROJECT_ROOT):/go/src/$(BASE_PACKAGE_NAME) \
-w /go/src/$(BASE_PACKAGE_NAME) $(GO_DEV_IMAGE)
JS_DOCKER_CMD := docker run \
-it \
--rm \
-e SKIP_DOCKER=true \
-e KUBECONFIG="/code/$(BASE_PACKAGE_NAME)/brigade-worker/test/fake_kubeconfig.yaml" \
-v $(PROJECT_ROOT):/code/$(BASE_PACKAGE_NAME) \
-w /code/$(BASE_PACKAGE_NAME) $(JS_DEV_IMAGE)
endif
# Allow for users to supply a different helm cli name,
# for instance, if one has helm v3 as `helm3` and helm v2 as `helm`
HELM ?= helm
################################################################################
# Binaries and Docker images we build and publish #
################################################################################
IMAGES := brigade-api brigade-controller brigade-cr-gateway brigade-generic-gateway brigade-vacuum brig brigade-worker git-sidecar
ifdef DOCKER_REGISTRY
DOCKER_REGISTRY := $(DOCKER_REGISTRY)/
endif
ifdef DOCKER_ORG
DOCKER_ORG := $(DOCKER_ORG)/
endif
DOCKER_IMAGE_PREFIX := $(DOCKER_REGISTRY)$(DOCKER_ORG)
ifdef VERSION
MUTABLE_DOCKER_TAG := latest
else
VERSION := $(GIT_VERSION)
MUTABLE_DOCKER_TAG := edge
endif
LDFLAGS := -X github.com/brigadecore/brigade/pkg/version.Version=$(VERSION)
IMMUTABLE_DOCKER_TAG := $(VERSION)
################################################################################
# Utility targets #
################################################################################
.PHONY: dep
dep:
$(GO_DOCKER_CMD) dep ensure -v
.PHONY: format
format: format-go format-js
.PHONY: format-go
format-go:
$(GO_DOCKER_CMD) sh -c "go list -f '{{.Dir}}' ./... | xargs goimports -w -local github.com/brigadecore/brigade"
.PHONY: yarn-install
yarn-install:
$(JS_DOCKER_CMD) sh -c "cd brigade-worker && yarn install"
.PHONY: format-js
format-js:
$(JS_DOCKER_CMD) sh -c "cd brigade-worker && yarn format"
.PHONY: yarn-audit
yarn-audit:
$(JS_DOCKER_CMD) sh -c 'cd brigade-worker && yarn audit'
################################################################################
# Tests #
################################################################################
# All non-functional tests
.PHONY: test
test: verify-vendored-code lint test-unit verify-vendored-code-js test-js
# Verifies there are no discrepancies between desired dependencies and the
# tracked, vendored dependencies
.PHONY: verify-vendored-code
verify-vendored-code:
$(GO_DOCKER_CMD) dep check
.PHONY: lint
lint:
$(GO_DOCKER_CMD) golangci-lint run --config ./golangci.yml
# Unit tests. Local only.
.PHONY: test-unit
test-unit:
$(GO_DOCKER_CMD) go test -v ./...
# Verifies there are no discrepancies between desired dependencies and the
# tracked, vendored dependencies
.PHONY: verify-vendored-code-js
verify-vendored-code-js:
$(JS_DOCKER_CMD) sh -c "cd brigade-worker && yarn check --integrity && yarn check --verify-tree"
# JS test is local only
.PHONY: test-js
test-js:
$(JS_DOCKER_CMD) sh -c "cd brigade-worker && yarn build && yarn test"
################################################################################
# Build / Publish #
################################################################################
build: build-all-images build-brig
.PHONY: build-all-images
build-all-images: $(addsuffix -build-image,$(IMAGES))
%-build-image:
cp $*/.dockerignore .
docker build \
-f $*/Dockerfile \
-t $(DOCKER_IMAGE_PREFIX)$*:$(IMMUTABLE_DOCKER_TAG) \
--build-arg LDFLAGS='$(LDFLAGS)' \
.
docker tag $(DOCKER_IMAGE_PREFIX)$*:$(IMMUTABLE_DOCKER_TAG) $(DOCKER_IMAGE_PREFIX)$*:$(MUTABLE_DOCKER_TAG)
.PHONY: load-all-images
load-all-images: $(addsuffix -load-image,$(IMAGES))
%-load-image:
@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)"
# Cross-compile binaries for brig
build-brig:
$(GO_DOCKER_CMD) bash -c "LDFLAGS=\"$(LDFLAGS)\" scripts/build-brig.sh"
.PHONY: push
push: push-all-images
# You must be logged into DOCKER_REGISTRY before you can push.
.PHONY: push-all-images
push-all-images: build-all-images
push-all-images: $(addsuffix -push-image,$(IMAGES))
%-push-image:
docker push $(DOCKER_IMAGE_PREFIX)$*:$(IMMUTABLE_DOCKER_TAG)
docker push $(DOCKER_IMAGE_PREFIX)$*:$(MUTABLE_DOCKER_TAG)
################################################################################
# Helm and functional test utils #
################################################################################
# Helm chart/release defaults
BRIGADE_RELEASE ?= brigade-server
BRIGADE_NAMESPACE ?= default
BRIGADE_GITHUB_GW_SERVICE := $(BRIGADE_RELEASE)-brigade-github-app
BRIGADE_GITHUB_GW_INTERNAL_PORT := 80
BRIGADE_GITHUB_GW_EXTERNAL_PORT := 7744
BRIGADE_VERSION := $(VERSION)
# DOCKER_IMAGE_PREFIX would have a trailing slash that we won't want here
# because the charts glue the registry (registry + org, really), image name.
# and tag together themselves and do not account for the possibility of registry
# or org being "". So, we create a new variable here called BRIGADE_REGISTRY
# that is DOCKER_IMAGE_PREFIX minus any trailing slash. If DOCKER_IMAGE_PREFIX
# is the empty string, we default to "brigadecore", since, again, the charts
# cannot currently accommodate a blank registry or org.
ifeq ("$(DOCKER_IMAGE_PREFIX)","")
BRIGADE_REGISTRY := brigadecore
else
BRIGADE_REGISTRY := $(shell echo $(DOCKER_IMAGE_PREFIX) | sed 's:/*$$::')
endif
.PHONY: helm-install
helm-install: helm-upgrade
.PHONY: helm-upgrade
helm-upgrade:
$(HELM) upgrade --install $(BRIGADE_RELEASE) brigade/brigade --namespace $(BRIGADE_NAMESPACE) \
--set brigade-github-app.enabled=true \
--set controller.registry=$(BRIGADE_REGISTRY) \
--set controller.tag=$(BRIGADE_VERSION) \
--set api.registry=$(BRIGADE_REGISTRY) \
--set api.tag=$(BRIGADE_VERSION) \
--set worker.registry=$(BRIGADE_REGISTRY) \
--set worker.tag=$(BRIGADE_VERSION) \
--set cr.enabled=true \
--set cr.registry=$(BRIGADE_REGISTRY) \
--set cr.tag=$(BRIGADE_VERSION) \
--set genericGateway.enabled=true \
--set genericGateway.registry=$(BRIGADE_REGISTRY) \
--set genericGateway.tag=$(BRIGADE_VERSION) \
--set vacuum.registry=$(BRIGADE_REGISTRY) \
--set vacuum.tag=$(BRIGADE_VERSION)
# Functional tests assume access to github.com
# and Brigade chart installed with `--set brigade-github-app.enabled=true`
#
# To set this up in your local environment:
# - Make sure kubectl is pointed to the right cluster
# - Run "helm repo add brigade https://brigadecore.github.io/charts"
# - Run "helm inspect values brigade/brigade-project > myvals.yaml"
# - Set the values in myvalues.yaml to something like this:
# project: "brigadecore/empty-testbed"
# repository: "github.com/brigadecore/empty-testbed"
# secret: "MySecret"
# - Run "helm install brigade/brigade-project -f myvals.yaml"
# - Run "make test-functional"
#
# This will clone the github.com/brigadecore/empty-testbed repo and run the brigade.js
# file found there.
# Test Repo is https://github.com/brigadecore/empty-testbed
TEST_REPO_COMMIT = 589e15029e1e44dee48de4800daf1f78e64287c0
KUBECONFIG ?= ${HOME}/.kube/config
.PHONY: test-functional
test-functional:
@kubectl port-forward service/$(BRIGADE_GITHUB_GW_SERVICE) $(BRIGADE_GITHUB_GW_EXTERNAL_PORT):80 &>/dev/null & \
echo $$! > /tmp/$(BRIGADE_GITHUB_GW_SERVICE).PID
go test --tags integration ./tests -kubeconfig $(KUBECONFIG) $(TEST_REPO_COMMIT)
@kill -TERM $$(cat /tmp/$(BRIGADE_GITHUB_GW_SERVICE).PID)
.PHONY: e2e
e2e:
CLIENT_PLATFORM=$(CLIENT_PLATFORM) CLIENT_ARCH=$(CLIENT_ARCH) ./e2e/run.sh
.PHONY: e2e-docker
e2e-docker:
docker run \
-e CREATE_KIND="${CREATE_KIND}" \
-v /var/run/docker.sock:/var/run/docker.sock \
-v $(PROJECT_ROOT):/go/src/$(BASE_PACKAGE_NAME) \
-w /go/src/$(BASE_PACKAGE_NAME) brigadecore/golang-kind:1.13.7-v0.7.0 \
./e2e/run.sh