forked from openshift/ci-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
300 lines (257 loc) · 10.8 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
# Old-skool build tools.
#
# Targets (see each target for more information):
# all: Build code.
# build: Build code.
# test: Run all tests.
# clean: Clean up.
#
OUT_DIR = _output
OS_OUTPUT_GOPATH ?= 1
SHELL=/usr/bin/env bash -eo pipefail
export GOFLAGS
export TESTFLAGS
# Tests run using `make` are most often run by the CI system, so we are OK to
# assume the user wants jUnit output and will turn it off if they don't.
JUNIT_REPORT ?= true
all build: install
.PHONY: all build
# Verify code conventions are properly setup.
#
# Example:
# make verify
verify:
{ \
hack/verify-gofmt.sh ||r=1;\
hack/verify-govet.sh ||r=1;\
make verify-gen || rc=1;\
exit $$r ;\
}
.PHONY: verify
# Verify code conventions are properly setup.
#
# Example:
# make lint
lint:
./hack/lint.sh
.PHONY: lint
# Run unit tests.
#
# Args:
# GOFLAGS: Extra flags to pass to 'go' when building.
#
# Example:
# make test
test: cmd/vault-secret-collection-manager/index.js
TESTFLAGS="$(TESTFLAGS)" hack/test-go.sh
.PHONY: test
# Remove all build artifacts.
#
# Example:
# make clean
clean:
rm -rf $(OUT_DIR)
.PHONY: clean
# Format all Go source code.
#
# Example:
# make format
format: cmd/vault-secret-collection-manager/index.js
gofmt -s -w $(shell go list -f '{{ .Dir }}' ./... )
.PHONY: format
# Update vendored code and manifests to ensure formatting.
#
# Example:
# make update-vendor
update-vendor:
docker run --rm \
--user=$$UID \
-v $$(go env GOCACHE):/.cache:Z \
-v $$PWD:/go/src/github.com/openshift/ci-tools:Z \
-w /go/src/github.com/openshift/ci-tools \
-e GO111MODULE=on \
-e GOPROXY=https://proxy.golang.org \
-e GOCACHE=/tmp/go-build-cache \
golang:1.16 \
/bin/bash -c "go mod tidy && go mod vendor"
.PHONY: update-vendor
# Validate vendored code and manifests to ensure formatting.
#
# Example:
# make validate-vendor
validate-vendor:
go version
GO111MODULE=on GOPROXY=https://proxy.golang.org go mod tidy
GO111MODULE=on GOPROXY=https://proxy.golang.org go mod vendor
git status -s ./vendor/ go.mod go.sum
test -z "$$(git status -s ./vendor/ go.mod go.sum | grep -v vendor/modules.txt)"
.PHONY: validate-vendor
# Use verbosity by default, allow users to opt out
VERBOSE := $(if $(QUIET),,-v )
# Install Go binaries to $GOPATH/bin.
#
# Example:
# make install
install: cmd/vault-secret-collection-manager/index.js
go install $(VERBOSE)./cmd/...
.PHONY: install
cmd/vault-secret-collection-manager/index.js: cmd/vault-secret-collection-manager/index.ts
hack/compile-typescript.sh
# Install Go binaries to $GOPATH/bin.
# Set version and name variables.
#
# Example:
# make production-install
production-install: cmd/vault-secret-collection-manager/index.js
hack/install.sh
.PHONY: production-install
# Install Go binaries with enabled race detector to $GOPATH/bin.
# Set version and name variables.
#
# Example:
# make production-install
race-install: cmd/vault-secret-collection-manager/index.js
hack/install.sh race
# Run integration tests.
#
# Accepts a specific suite to run as an argument.
#
# Example:
# make integration
# make integration SUITE=multi-stage
integration:
@set -e; \
if [[ -n $$OPENSHIFT_CI ]]; then count=25; else count=1; fi && \
for try in $$(seq $$count); do \
echo "Try $$try" && \
test/entrypoint-wrapper-integration.sh && \
hack/test-integration.sh $(SUITE) ; \
done
.PHONY: integration
TMPDIR ?= /tmp
TAGS ?= e2e,e2e_framework
# Run e2e tests.
#
# Accepts a specific suite to run as an argument.
#
# Example:
# make e2e
# make e2e SUITE=multi-stage
e2e: $(TMPDIR)/.boskos-credentials
BOSKOS_CREDENTIALS_FILE="$(TMPDIR)/.boskos-credentials" PACKAGES="./test/e2e/..." TESTFLAGS="$(TESTFLAGS) -tags $(TAGS) -timeout 70m -parallel 100" hack/test-go.sh
.PHONY: e2e
$(TMPDIR)/.boskos-credentials:
echo -n "u:p" > $(TMPDIR)/.boskos-credentials
CLUSTER ?= build01
# Dependencies required to execute the E2E tests outside of the CI environment.
local-e2e: \
$(TMPDIR)/.ci-operator-kubeconfig \
$(TMPDIR)/hive-kubeconfig \
$(TMPDIR)/local-secret/.dockerconfigjson \
$(TMPDIR)/remote-secret/.dockerconfigjson \
$(TMPDIR)/gcs/service-account.json \
$(TMPDIR)/boskos \
$(TMPDIR)/prometheus \
$(TMPDIR)/promtool
$(eval export KUBECONFIG=$(TMPDIR)/.ci-operator-kubeconfig)
$(eval export HIVE_KUBECONFIG=$(TMPDIR)/hive-kubeconfig)
$(eval export LOCAL_REGISTRY_SECRET_DIR=$(TMPDIR)/local-secret)
$(eval export REMOTE_REGISTRY_SECRET_DIR=$(TMPDIR)/remote-secret)
$(eval export GCS_CREDENTIALS_FILE=$(TMPDIR)/gcs/service-account.json)
$(eval export PATH=${PATH}:$(TMPDIR))
@$(MAKE) e2e
.PHONY: local-e2e
# Update golden output files for integration tests.
#
# Example:
# make update-integration
# make update-integration SUITE=multi-stage
update-integration:
go run ./cmd/determinize-prow-config -prow-config-dir test/integration/repo-init/expected/core-services/prow/02_config -sharded-plugin-config-base-dir test/integration/repo-init/expected/core-services/prow/02_config
UPDATE=true make integration
.PHONY: update-integration
kubeExport := "jq 'del(.metadata.namespace,.metadata.resourceVersion,.metadata.uid,.metadata.creationTimestamp)'"
pr-deploy-configresolver:
$(eval USER=$(shell curl --fail -Ss https://api.github.com/repos/openshift/ci-tools/pulls/$(PULL_REQUEST)|jq -r .head.user.login))
$(eval BRANCH=$(shell curl --fail -Ss https://api.github.com/repos/openshift/ci-tools/pulls/$(PULL_REQUEST)|jq -r .head.ref))
oc --context app.ci --as system:admin process -p USER=$(USER) -p BRANCH=$(BRANCH) -p PULL_REQUEST=$(PULL_REQUEST) -f hack/pr-deploy.yaml | oc --context app.ci --as system:admin apply -f -
for cm in ci-operator-master-configs step-registry config; do oc --context app.ci --as system:admin get configmap $${cm} -n ci -o json | eval $(kubeExport)|oc --context app.ci --as system:admin create -f - -n ci-tools-$(PULL_REQUEST); done
echo "server is at https://$$( oc --context app.ci --as system:admin get route server -n ci-tools-$(PULL_REQUEST) -o jsonpath={.spec.host} )"
.PHONY: pr-deploy
pr-deploy-backporter:
$(eval USER=$(shell curl --fail -Ss https://api.github.com/repos/openshift/ci-tools/pulls/$(PULL_REQUEST)|jq -r .head.user.login))
$(eval BRANCH=$(shell curl --fail -Ss https://api.github.com/repos/openshift/ci-tools/pulls/$(PULL_REQUEST)|jq -r .head.ref))
oc --context app.ci --as system:admin process -p USER=$(USER) -p BRANCH=$(BRANCH) -p PULL_REQUEST=$(PULL_REQUEST) -f hack/pr-deploy-backporter.yaml | oc --context app.ci --as system:admin apply -f -
oc --context app.ci --as system:admin get configmap plugins -n ci -o json | eval $(kubeExport) | oc --context app.ci --as system:admin create -f - -n ci-tools-$(PULL_REQUEST)
oc --context app.ci --as system:admin get secret bugzilla-credentials-openshift-bugzilla-robot -n ci -o json | eval $(kubeExport) | oc --context app.ci --as system:admin create -f - -n ci-tools-$(PULL_REQUEST)
echo "server is at https://$$( oc --context app.ci --as system:admin get route bp-server -n ci-tools-$(PULL_REQUEST) -o jsonpath={.spec.host} )"
.PHONY: pr-deploy-backporter
pr-deploy-vault-secret-manager:
$(eval USER=$(shell curl --fail -Ss https://api.github.com/repos/openshift/ci-tools/pulls/$(PULL_REQUEST)|jq -r .head.user.login))
$(eval BRANCH=$(shell curl --fail -Ss https://api.github.com/repos/openshift/ci-tools/pulls/$(PULL_REQUEST)|jq -r .head.ref))
oc --context app.ci --as system:admin process -p USER=$(USER) -p BRANCH=$(BRANCH) -p PULL_REQUEST=$(PULL_REQUEST) -f hack/pr-deploy-vault-secret-manager.yaml | oc --context app.ci --as system:admin apply -f -
kubectl patch -n vault rolebinding registry-viewer --type=json --patch='[{"op":"replace", "path":"/subjects/1/namespace", "value":"ci-tools-$(PULL_REQUEST)"}]'
echo "server is at https://$$( oc --context app.ci --as system:admin get route vault-secret-collection-manager -n ci-tools-$(PULL_REQUEST) -o jsonpath={.spec.host} )"
.PHONY: pr-deploy-backporter
check-breaking-changes:
test/validate-prowgen-breaking-changes.sh
.PHONY: check-breaking-changes
.PHONY: generate
generate: imports
hack/update-codegen.sh
hack/generate-ci-op-reference.sh
.PHONY: imports
imports:
go run ./vendor/github.com/coreydaley/openshift-goimports/ -m github.com/openshift/ci-tools
.PHONY: verify-gen
verify-gen: generate
@# Don't add --quiet here, it disables --exit code in the git 1.7 we have in CI, making this unusuable
if ! git diff --exit-code; then \
echo "generated files are out of date, run make generate"; exit 1; \
fi
update-unit:
UPDATE=true go test ./...
.PHONY: update-unit
validate-registry-metadata:
generate-registry-metadata -registry test/multistage-registry/registry
git status -s ./test/multistage-registry/registry
test -z "$$(git status -s ./test/multistage-registry/registry | grep registry)"
.PHONY: validate-registry-metadata
validate-checkconfig:
test/validate-checkconfig.sh
.PHONY: validate-checkconfig
$(TMPDIR)/.ci-operator-kubeconfig:
oc --context $(CLUSTER) --as system:admin --namespace ci serviceaccounts create-kubeconfig ci-operator > $(TMPDIR)/.ci-operator-kubeconfig
$(TMPDIR)/hive-kubeconfig:
oc --context $(CLUSTER) --as system:admin --namespace test-credentials get secret hive-hive-credentials -o 'jsonpath={.data.kubeconfig}' | base64 --decode > "$@"
$(TMPDIR)/local-secret/.dockerconfigjson:
mkdir -p $(TMPDIR)/local-secret
oc --context $(CLUSTER) --as system:admin --namespace test-credentials get secret registry-pull-credentials -o 'jsonpath={.data.\.dockerconfigjson}' | base64 --decode | jq > $(TMPDIR)/local-secret/.dockerconfigjson
$(TMPDIR)/remote-secret/.dockerconfigjson:
mkdir -p $(TMPDIR)/remote-secret
oc --context $(CLUSTER) --as system:admin --namespace test-credentials get secret ci-pull-credentials -o 'jsonpath={.data.\.dockerconfigjson}' | base64 --decode | jq > $(TMPDIR)/remote-secret/.dockerconfigjson
$(TMPDIR)/gcs/service-account.json:
mkdir -p $(TMPDIR)/gcs
oc --context $(CLUSTER) --as system:admin --namespace test-credentials get secret gce-sa-credentials-gcs-publisher -o 'jsonpath={.data.service-account\.json}' | base64 --decode | jq > $(TMPDIR)/gcs/service-account.json
$(TMPDIR)/boskos:
mkdir -p $(TMPDIR)/image
oc image extract registry.ci.openshift.org/ci/boskos:latest --path /:$(TMPDIR)/image
mv $(TMPDIR)/image/app $(TMPDIR)/boskos
chmod +x $(TMPDIR)/boskos
rm -rf $(TMPDIR)/image
local-pod-scaler: $(TMPDIR)/prometheus $(TMPDIR)/promtool
$(eval export PATH=${PATH}:$(TMPDIR))
go run -tags e2e,e2e_framework ./test/e2e/pod-scaler/local/main.go
.PHONY: local-pod-scaler
$(TMPDIR)/prometheus:
mkdir -p $(TMPDIR)/image
oc image extract quay.io/prometheus/prometheus:latest --path /bin/prometheus:$(TMPDIR)/image
mv $(TMPDIR)/image/prometheus $(TMPDIR)/prometheus
chmod +x $(TMPDIR)/prometheus
rm -rf $(TMPDIR)/image
$(TMPDIR)/promtool:
mkdir -p $(TMPDIR)/image
oc image extract quay.io/prometheus/prometheus:main --path /bin/promtool:$(TMPDIR)/image
mv $(TMPDIR)/image/promtool $(TMPDIR)/promtool
chmod +x $(TMPDIR)/promtool
rm -rf $(TMPDIR)/image