forked from evergreen-ci/evergreen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
423 lines (381 loc) · 18.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
# start project configuration
name := evergreen
buildDir := bin
nodeDir := public
packages := $(name) agent agent-command agent-util agent-internal agent-internal-client agent-internal-testutil operations cloud cloud-userdata
packages += db util plugin units graphql thirdparty thirdparty-docker auth scheduler model validator service repotracker cmd-codegen-core mock
packages += model-annotations model-patch model-artifact model-host model-pod model-pod-definition model-pod-dispatcher model-build model-event model-task model-user model-distro model-manifest model-testresult
packages += model-commitqueue
packages += rest-client rest-data rest-route rest-model migrations trigger model-alertrecord model-notification model-taskstats model-reliability
lintOnlyPackages := api apimodels testutil model-manifest model-testutil service-testutil service-graphql db-mgo db-mgo-bson db-mgo-internal-json rest
testOnlyPackages := service-graphql # has only test files so can't undergo all operations
orgPath := github.com/evergreen-ci
projectPath := $(orgPath)/$(name)
evghome := $(abspath .)
ifeq ($(OS),Windows_NT)
evghome := $(shell cygpath -m $(evghome))
endif
lobsterTempDir := $(abspath $(buildDir))/lobster-temp
# end project configuration
# start go runtime settings
gobin := go
ifneq (,$(GOROOT))
gobin := $(GOROOT)/bin/go
endif
goCache := $(GOCACHE)
ifeq (,$(goCache))
goCache := $(abspath $(buildDir)/.cache)
endif
goModCache := $(GOMODCACHE)
ifeq (,$(goModCache))
goModCache := $(abspath $(buildDir)/.mod-cache)
endif
lintCache := $(GOLANGCI_LINT_CACHE)
ifeq (,$(lintCache))
lintCache := $(abspath $(buildDir)/.lint-cache)
endif
ifeq ($(OS),Windows_NT)
gobin := $(shell cygpath $(gobin))
goCache := $(shell cygpath -m $(goCache))
goModCache := $(shell cygpath -m $(goModCache))
lintCache := $(shell cygpath -m $(lintCache))
export GOROOT := $(shell cygpath -m $(GOROOT))
endif
ifneq ($(goCache),$(GOCACHE))
export GOCACHE := $(goCache)
endif
ifneq ($(goModCache),$(GOMODCACHE))
export GOMODCACHE := $(goModCache)
endif
ifneq ($(lintCache),$(GOLANGCI_LINT_CACHE))
export GOLANGCI_LINT_CACHE := $(lintCache)
endif
ifneq (,$(RACE_DETECTOR))
# cgo is required for using the race detector.
export CGO_ENABLED := 1
else
export CGO_ENABLED := 0
endif
# end go runtime settings
# Ensure the build directory exists, since most targets require it.
$(shell mkdir -p $(buildDir))
# start evergreen specific configuration
goos := $(GOOS)
goarch := $(GOARCH)
ifeq ($(goos),)
goos := $(shell $(gobin) env GOOS 2> /dev/null)
endif
ifeq ($(goarch),)
goarch := $(shell $(gobin) env GOARCH 2> /dev/null)
endif
clientBuildDir := clients
macOSPlatforms := darwin_amd64 $(if $(STAGING_ONLY),,darwin_arm64)
linuxPlatforms := linux_amd64 $(if $(STAGING_ONLY),,linux_s390x linux_arm64 linux_ppc64le)
windowsPlatforms := windows_amd64
unixBinaryBasename := evergreen
windowsBinaryBasename := evergreen.exe
macOSBinaries := $(foreach platform,$(macOSPlatforms),$(clientBuildDir)/$(platform)/$(unixBinaryBasename))
linuxBinaries := $(foreach platform,$(linuxPlatforms),$(clientBuildDir)/$(platform)/$(unixBinaryBasename))
windowsBinaries := $(foreach platform,$(windowsPlatforms),$(clientBuildDir)/$(platform)/$(windowsBinaryBasename))
clientBinaries := $(macOSBinaries) $(linuxBinaries) $(windowsBinaries)
clientSource := cmd/evergreen/evergreen.go
uiFiles := $(shell find public/static -not -path "./public/static/app" -name "*.js" -o -name "*.css" -o -name "*.html")
distArtifacts := ./public ./service/templates
distContents := $(clientBinaries) $(distArtifacts)
srcFiles := makefile $(shell find . -name "*.go" -not -path "./$(buildDir)/*" -not -name "*_test.go" -not -path "./scripts/*" -not -path "*\#*")
testSrcFiles := makefile $(shell find . -name "*.go" -not -path "./$(buildDir)/*" -not -path "*\#*")
currentHash := $(shell git rev-parse HEAD)
agentVersion := $(shell grep "AgentVersion" config.go | tr -d '\tAgentVersion = ' | tr -d '"')
ldFlags := $(if $(DEBUG_ENABLED),,-w -s )-X=github.com/evergreen-ci/evergreen.BuildRevision=$(currentHash)
gcFlags := $(if $(STAGING_ONLY),-N -l,)
karmaFlags := $(if $(KARMA_REPORTER),--reporters $(KARMA_REPORTER),)
goLintInstallerVersion := "v1.51.2"
goLintInstallerChecksum := "0e09dedc7e35f511b7924b885e50d7fe48eef25bec78c86f22f5b5abd24976cc"
# end evergreen specific configuration
######################################################################
##
## Build rules and instructions for building evergreen binaries and targets.
##
######################################################################
# start rules for building services and clients
ifeq ($(OS),Windows_NT)
localClientBinary := $(clientBuildDir)/$(goos)_$(goarch)/$(windowsBinaryBasename)
else
localClientBinary := $(clientBuildDir)/$(goos)_$(goarch)/$(unixBinaryBasename)
endif
cli:$(localClientBinary)
clis:$(clientBinaries)
$(clientBuildDir)/%/$(unixBinaryBasename) $(clientBuildDir)/%/$(windowsBinaryBasename):$(buildDir)/build-cross-compile $(srcFiles) go.mod go.sum
@./$(buildDir)/build-cross-compile -buildName=$* -ldflags="$(ldFlags)" -gcflags="$(gcFlags)" -goBinary="$(gobin)" -directory=$(clientBuildDir) -source=$(clientSource) -output=$@
# Targets to upload the CLI binaries to S3.
$(buildDir)/upload-s3:cmd/upload-s3/upload-s3.go
@$(gobin) build -o $@ $<
upload-clis:$(buildDir)/upload-s3 clis
$(buildDir)/upload-s3 -bucket="${BUCKET_NAME}" -local="${LOCAL_PATH}" -remote="${REMOTE_PATH}" -exclude="${EXCLUDE_PATTERN}"
phony += cli clis upload-clis
# end client build directives
# start smoke test specific rules
$(buildDir)/load-smoke-data:cmd/load-smoke-data/load-smoke-data.go
$(gobin) build -ldflags="-w" -o $@ $<
$(buildDir)/set-var:cmd/set-var/set-var.go
$(gobin) build -o $@ $<
$(buildDir)/set-project-var:cmd/set-project-var/set-project-var.go
$(gobin) build -o $@ $<
set-var:$(buildDir)/set-var
set-project-var:$(buildDir)/set-project-var
set-smoke-vars:$(buildDir)/.load-smoke-data $(buildDir)/set-project-var $(buildDir)/set-var
@$(buildDir)/set-project-var -dbName mci_smoke -key aws_key -value $(AWS_KEY)
@$(buildDir)/set-project-var -dbName mci_smoke -key aws_secret -value $(AWS_SECRET)
@$(buildDir)/set-var -dbName=mci_smoke -collection=hosts -id=localhost -key=agent_revision -value=$(agentVersion)
@$(buildDir)/set-var -dbName=mci_smoke -collection=pods -id=localhost -key=agent_version -value=$(agentVersion)
load-smoke-data:$(buildDir)/.load-smoke-data
load-local-data:$(buildDir)/.load-local-data
$(buildDir)/.load-smoke-data:$(buildDir)/load-smoke-data
./$<
@touch $@
$(buildDir)/.load-local-data:$(buildDir)/load-smoke-data
./$< -path testdata/local -dbName evergreen_local -amboyDBName amboy_local
@touch $@
smoke-test-agent-monitor:$(localClientBinary) load-smoke-data
# Start the smoke test's Evergreen app server.
./$< service deploy start-evergreen --web --binary ./$< &
# Start the smoke test's agent monitor, which will run the Evergreen agent based on the locally-compiled Evergreen
# executable. This agent will coordinate with the app server to run the smoke test's tasks.
# It is necessary to set up this locally-running agent because the app server can't actually start hosts to run
# tasks.
# Note that the distro comes from the smoke test's DB files.
./$< service deploy start-evergreen --monitor --binary ./$< --distro localhost &
# Run the smoke test's actual tests.
# The username/password to is used to authenticate to the app server, and these credentials come from the smoke
# test's DB files.
./$< service deploy test-endpoints --check-build --username admin --key abb623665fdbf368a1db980dde6ee0f0
# Clean up all smoke test Evergreen executable processes.
pkill -f $<
smoke-test-host-task:$(localClientBinary) load-smoke-data
./$< service deploy start-evergreen --web --binary ./$< &
./$< service deploy start-evergreen --mode host --agent --binary ./$< &
./$< service deploy test-endpoints --check-build --mode host --username admin --key abb623665fdbf368a1db980dde6ee0f0
pkill -f $<
smoke-test-container-task:$(localClientBinary) load-smoke-data
./$< service deploy start-evergreen --web --binary ./$< &
./$< service deploy start-evergreen --mode pod --agent --binary ./$< &
./$< service deploy test-endpoints --check-build --mode pod --username admin --key abb623665fdbf368a1db980dde6ee0f0
pkill -f $<
smoke-test-endpoints:$(localClientBinary) load-smoke-data
./$< service deploy start-evergreen --web --binary ./$< &
./$< service deploy test-endpoints --username admin --key abb623665fdbf368a1db980dde6ee0f0
pkill -f $<
local-evergreen:$(localClientBinary) load-local-data
./$< service deploy start-local-evergreen
# end smoke test rules
######################################################################
##
## Build, Test, and Dist targets and mechisms.
##
######################################################################
# most of the targets and variables in this section are generic
# instructions for go programs of all kinds, and are not particularly
# specific to evergreen; though the dist targets are more specific than the rest.
# start output files
testOutput := $(foreach target,$(packages) $(testOnlyPackages),$(buildDir)/output.$(target).test)
lintOutput := $(foreach target,$(packages) $(lintOnlyPackages),$(buildDir)/output.$(target).lint)
coverageOutput := $(foreach target,$(packages),$(buildDir)/output.$(target).coverage)
coverageHtmlOutput := $(foreach target,$(packages),$(buildDir)/output.$(target).coverage.html)
# end output files
# lint setup targets
$(buildDir)/.lintSetup:$(buildDir)/golangci-lint
@touch $@
$(buildDir)/golangci-lint:
@curl --retry 10 --retry-max-time 120 -sSfL -o "$(buildDir)/install.sh" https://raw.githubusercontent.com/golangci/golangci-lint/$(goLintInstallerVersion)/install.sh
@echo "$(goLintInstallerChecksum) $(buildDir)/install.sh" | sha256sum --check
@bash $(buildDir)/install.sh -b $(buildDir) $(goLintInstallerVersion) >/dev/null 2>&1 && touch $@
$(buildDir)/run-linter:cmd/run-linter/run-linter.go $(buildDir)/.lintSetup
$(gobin) build -ldflags "-w" -o $@ $<
# end lint setup targets
# generate lint JSON document for evergreen
generate-lint:$(buildDir)/generate-lint.json
$(buildDir)/generate-lint.json:$(buildDir)/generate-lint $(srcFiles)
./$(buildDir)/generate-lint
$(buildDir)/generate-lint:cmd/generate-lint/generate-lint.go
$(gobin) build -ldflags "-w" -o $@ $<
# end generate lint
# generate rest model
# build-codegen is a special target to build all packages before performing code generation so that goimports can
# properly locate package imports.
build-codegen:
$(gobin) build $(subst $(name),,$(subst -,/,$(foreach target,$(packages),./$(target))))
generate-rest-model:$(buildDir)/codegen build-codegen
./$(buildDir)/codegen --config "rest/model/schema/type_mapping.yml" --schema "rest/model/schema/rest_model.graphql" --model "rest/model/generated.go" --helper "rest/model/generated_converters.go"
$(buildDir)/codegen:
$(gobin) build -o $(buildDir)/codegen cmd/codegen/entry.go
# end generate rest model
# parse a host.create file and set expansions
parse-host-file:$(buildDir)/parse-host-file
./$(buildDir)/parse-host-file --file $(HOST_FILE)
$(buildDir)/parse-host-file:cmd/parse-host-file/parse-host-file.go
$(gobin) build -o $@ $<
$(buildDir)/expansions.yml:$(buildDir)/parse-host-file
# end host.create file parsing
# npm setup
$(buildDir)/.npmSetup:
cd $(nodeDir) && $(if $(NODE_BIN_PATH),export PATH=${PATH}:$(NODE_BIN_PATH) && ,)npm install
touch $@
# end npm setup
# distribution targets and implementation
$(buildDir)/build-cross-compile:cmd/build-cross-compile/build-cross-compile.go makefile
GOOS="" GOARCH="" $(gobin) build -o $@ $<
$(buildDir)/make-tarball:cmd/make-tarball/make-tarball.go
GOOS="" GOARCH="" $(gobin) build -o $@ $<
$(buildDir)/sign-executable:cmd/sign-executable/sign-executable.go
$(gobin) build -o $@ $<
$(buildDir)/macnotary:$(buildDir)/sign-executable
./$< get-client --download-url $(NOTARY_CLIENT_URL) --destination $@
$(clientBuildDir)/%/.signed:$(buildDir)/sign-executable $(clientBuildDir)/%/$(unixBinaryBasename) $(buildDir)/macnotary
./$< sign --client $(buildDir)/macnotary --executable $(@D)/$(unixBinaryBasename) --server-url $(NOTARY_SERVER_URL) --bundle-id $(EVERGREEN_BUNDLE_ID)
touch $@
dist-staging:
STAGING_ONLY=1 DEBUG_ENABLED=1 SIGN_MACOS= $(MAKE) dist
dist-unsigned:
SIGN_MACOS= $(MAKE) dist
dist:$(buildDir)/dist.tar.gz
$(buildDir)/dist.tar.gz:$(buildDir)/make-tarball $(clientBinaries) $(uiFiles) $(if $(SIGN_MACOS),$(foreach platform,$(macOSPlatforms),$(clientBuildDir)/$(platform)/.signed))
./$< --name $@ --prefix $(name) $(foreach item,$(distContents),--item $(item)) --exclude "public/node_modules" --exclude "clients/.cache"
# end main build
# userfacing targets for basic build and development operations
build:cli
lint:$(foreach target,$(packages) $(lintOnlyPackages),$(buildDir)/output.$(target).lint)
test:$(foreach target,$(packages) $(testOnlyPackages),test-$(target))
js-test:$(buildDir)/.npmSetup
cd $(nodeDir) && $(if $(NODE_BIN_PATH),export PATH=${PATH}:$(NODE_BIN_PATH) && ,)./node_modules/.bin/karma start static/js/tests/conf/karma.conf.js $(karmaFlags)
coverage:$(coverageOutput)
coverage-html:$(coverageHtmlOutput)
list-tests:
@echo -e "test targets:" $(foreach target,$(packages),\\n\\ttest-$(target))
phony += lint build test coverage coverage-html list-tests
.PRECIOUS:$(testOutput) $(lintOutput) $(coverageOutput) $(coverageHtmlOutput)
# end front-ends
# start module management targets
mod-tidy:
$(gobin) mod tidy
verify-mod-tidy:
$(gobin) run cmd/verify-mod-tidy/verify-mod-tidy.go -goBin="$(gobin)"
phony += mod-tidy verify-mod-tidy
# end module management targets
# convenience targets for runing tests and coverage tasks on a
# specific package.
test-%:$(buildDir)/output.%.test
@grep -s -q -e "^PASS" $< && ! grep -s -q "^WARNING: DATA RACE" $<
dlv-%:$(buildDir)/output-dlv.%.test
@grep -s -q -e "^PASS" $< && ! grep -s -q "^WARNING: DATA RACE" $<
coverage-%:$(buildDir)/output.%.coverage
@grep -s -q -e "^PASS" $(subst coverage,test,$<)
html-coverage-%:$(buildDir)/output.%.coverage $(buildDir)/output.%.coverage.html
@grep -s -q -e "^PASS" $(subst coverage,test,$<)
lint-%:$(buildDir)/output.%.lint
@grep -v -s -q "^--- FAIL" $<
# end convienence targets
# start test and coverage artifacts
# This varable includes everything that the tests actually need to
# run. (The "build" target is intentional and makes these targetsb
# rerun as expected.)
testRunDeps := $(name)
testArgs := -v
dlvArgs := -test.v
testRunEnv := EVGHOME=$(evghome)
ifeq (,$(GOCONVEY_REPORTER))
testRunEnv += GOCONVEY_REPORTER=silent
endif
ifneq (,$(SETTINGS_OVERRIDE))
testRunEnv += SETTINGS_OVERRIDE=$(SETTINGS_OVERRIDE)
endif
ifneq (,$(RUN_TEST))
testArgs += -run='$(RUN_TEST)'
dlvArgs += -test.run='$(RUN_TEST)'
endif
ifneq (,$(SKIP_LONG))
testArgs += -short
dlvArgs += -test.short
endif
ifneq (,$(RUN_COUNT))
testArgs += -count='$(RUN_COUNT)'
dlvArgs += -test.count='$(RUN_COUNT)'
endif
ifneq (,$(RACE_DETECTOR))
testArgs += -race
dlvArgs += -test.race
endif
ifneq (,$(TEST_TIMEOUT))
testArgs += -timeout=$(TEST_TIMEOUT)
else
testArgs += -timeout=10m
endif
testArgs += -ldflags="$(ldFlags) -X=github.com/evergreen-ci/evergreen/testutil.ExecutionEnvironmentType=test"
# targets to run any tests in the top-level package
$(buildDir):
mkdir -p $@
$(buildDir)/output.%.test: .FORCE
$(testRunEnv) $(gobin) test $(testArgs) ./$(if $(subst $(name),,$*),$(subst -,/,$*),) 2>&1 | tee $@
# Codegen is special because it requires that the repository be compiled for goimports to resolve imports properly.
$(buildDir)/output.cmd-codegen-core.test: build-codegen .FORCE
$(testRunEnv) $(gobin) test $(testArgs) ./$(if $(subst $(name),,$*),$(subst -,/,$*),) 2>&1 | tee $@
$(buildDir)/output-dlv.%.test: .FORCE
$(testRunEnv) dlv test $(testArgs) ./$(if $(subst $(name),,$*),$(subst -,/,$*),) -- $(dlvArgs) 2>&1 | tee $@
$(buildDir)/output.%.coverage: .FORCE
$(testRunEnv) $(gobin) test $(testArgs) ./$(if $(subst $(name),,$*),$(subst -,/,$*),) -covermode=count -coverprofile $@ | tee $(buildDir)/output.$*.test
@-[ -f $@ ] && go tool cover -func=$@ | sed 's%$(projectPath)/%%' | column -t
# targets to generate gotest output from the linter.
ifneq (go,$(gobin))
# We have to handle the PATH specially for linting in CI, because if the PATH has a different version of the Go
# binary in it, the linter won't work properly.
lintEnvVars := PATH="$(shell dirname $(gobin)):$(PATH)"
endif
$(buildDir)/output.%.lint: $(buildDir)/run-linter .FORCE
@$(lintEnvVars) ./$< --output=$@ --lintBin=$(buildDir)/golangci-lint -customLinters="$(gobin) run github.com/evergreen-ci/evg-lint/evg-lint -set_exit_status" --lintArgs="--timeout=5m" --packages='$*'
$(buildDir)/output.%.coverage.html:$(buildDir)/output.%.coverage
$(gobin) tool cover -html=$< -o $@
# end test and coverage artifacts
clean-lobster:
rm -rf $(lobsterTempDir)
phony += clean-lobster
update-lobster: clean-lobster
EVGHOME=$(evghome) LOBSTER_TEMP_DIR=$(lobsterTempDir) scripts/update-lobster.sh
# clean and other utility targets
clean: clean-lobster
rm -rf $(buildDir) $(clientBuildDir)
phony += clean
gqlgen:
go run github.com/99designs/gqlgen generate
# sanitizes a json file by hashing string values. Note that this will not work well with
# string data that only has a subset of valid values
ifneq (,$(multi))
multiarg = --multi
endif
scramble:
python cmd/scrambled-eggs/scramble.py $(file) $(multiarg)
# mongodb utility targets
mongodb/.get-mongodb:
rm -rf mongodb
mkdir -p mongodb
cd mongodb && curl "$(MONGODB_URL)" -o mongodb.tgz && $(DECOMPRESS) mongodb.tgz && chmod +x ./mongodb-*/bin/*
cd mongodb && mv ./mongodb-*/bin/* . && rm -rf db_files && rm -rf db_logs && mkdir -p db_files && mkdir -p db_logs
get-mongodb:mongodb/.get-mongodb
@touch $<
start-mongod:mongodb/.get-mongodb
ifdef AUTH_ENABLED
echo "replica set key" > ./mongodb/keyfile.txt
chmod 600 ./mongodb/keyfile.txt
endif
./mongodb/mongod $(if $(AUTH_ENABLED),--auth --keyFile ./mongodb/keyfile.txt,) --dbpath ./mongodb/db_files --port 27017 --replSet evg --oplogSize 10
configure-mongod:mongodb/.get-mongodb
./mongodb/mongo --nodb --eval "assert.soon(function(x){try{var d = new Mongo(\"localhost:27017\"); return true}catch(e){return false}}, \"timed out connecting\")"
@echo "mongod is up"
./mongodb/mongo --eval 'rs.initiate()'
ifdef AUTH_ENABLED
./mongodb/mongo --host `./mongodb/mongo --quiet --eval "db.isMaster()['primary']"` cmd/mongo-auth/create_auth_user.js
endif
@echo "configured mongod"
# end mongodb targets
# configure special (and) phony targets
.FORCE:
.PHONY:$(phony) .FORCE
.DEFAULT_GOAL := build