forked from spacemeshos/go-spacemesh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
452 lines (324 loc) · 12.1 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
BINARY := go-spacemesh
VERSION ?= $(shell cat version.txt)
COMMIT = $(shell git rev-parse HEAD)
SHA = $(shell git rev-parse --short HEAD)
CURR_DIR = $(shell pwd)
CURR_DIR_WIN = $(shell cd)
BIN_DIR = $(CURR_DIR)/build
BIN_DIR_WIN ?= $(CURR_DIR_WIN)/build
export GO111MODULE = on
# These commands cause problems on Windows
ifeq ($(OS),Windows_NT)
# Just assume we're in interactive mode on Windows
INTERACTIVE = 1
VERSION ?= $(shell type version.txt)
else
INTERACTIVE := $(shell [ -t 0 ] && echo 1)
endif
# Read branch from git if running make manually
# Also allows BRANCH to be manually set
BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
# Add an indicator to the branch name if dirty and use commithash if running in detached mode
ifeq ($(BRANCH),HEAD)
BRANCH = $(SHA)
endif
$(shell git diff --quiet)
ifneq ($(.SHELLSTATUS),0)
BRANCH := $(BRANCH)-dirty
endif
# Setup the -ldflags option to pass vars defined here to app vars
LDFLAGS = -ldflags "-X main.version=${VERSION} -X main.commit=${COMMIT} -X main.branch=${BRANCH}"
PKGS = $(shell go list ./...)
PLATFORMS := windows linux darwin freebsd
os = $(word 1, $@)
ifeq ($(BRANCH),develop)
DOCKER_IMAGE_REPO := go-spacemesh
else
DOCKER_IMAGE_REPO := go-spacemesh-dev
endif
# setting extra command line params for the CI tests pytest commands
ifdef namespace
EXTRA_PARAMS:=$(EXTRA_PARAMS) --namespace=$(namespace)
endif
ifdef delns
EXTRA_PARAMS:=$(EXTRA_PARAMS) --delns=$(delns)
endif
ifdef dump
EXTRA_PARAMS:=$(EXTRA_PARAMS) --dump=$(dump)
endif
# This prevents "the input device is not a TTY" error from docker in CI
DOCKERRUNARGS := --rm -e ES_PASSWD="$(ES_PASSWD)" \
-e GOOGLE_APPLICATION_CREDENTIALS=./spacemesh.json \
-e CLUSTER_NAME_ELK=$(CLUSTER_NAME_ELK) \
-e CLUSTER_ZONE_ELK=$(CLUSTER_ZONE_ELK) \
-e PROJECT_NAME=$(PROJECT_NAME) \
-e ES_USER=$(ES_USER) \
-e ES_PASS=$(ES_PASS) \
-e MAIN_ES_IP=$(MAIN_ES_IP) \
-e TD_QUEUE_NAME=$(TD_QUEUE_NAME) \
-e TD_QUEUE_ZONE=$(TD_QUEUE_ZONE) \
-e DUMP_QUEUE_NAME=$(DUMP_QUEUE_NAME) \
-e DUMP_QUEUE_ZONE=$(DUMP_QUEUE_ZONE)
DOCKER_IMAGE = $(DOCKER_IMAGE_REPO):$(BRANCH)
# We use a docker image corresponding to the commithash for staging and trying, to be safe
# filter here is used as a logical OR operation
ifeq ($(BRANCH),$(filter $(BRANCH),staging trying))
DOCKER_IMAGE = $(DOCKER_IMAGE_REPO):$(SHA)
endif
DOCKERRUNARGS := $(DOCKERRUNARGS) -e CLIENT_DOCKER_IMAGE=spacemeshos/$(DOCKER_IMAGE)
ifdef INTERACTIVE
DOCKERRUN := docker run -it $(DOCKERRUNARGS) go-spacemesh-python:$(BRANCH)
else
DOCKERRUN := docker run -i $(DOCKERRUNARGS) go-spacemesh-python:$(BRANCH)
endif
all: install build
.PHONY: all
install:
ifeq ($(OS),Windows_NT)
setup_env.bat
else
./setup_env.sh
endif
.PHONY: install
build:
ifeq ($(OS),Windows_NT)
go build ${LDFLAGS} -o $(BIN_DIR_WIN)/$(BINARY).exe
else
go build ${LDFLAGS} -o $(BIN_DIR)/$(BINARY)
endif
.PHONY: build
hare:
ifeq ($(OS),Windows_NT)
cd cmd/hare ; go build -o $(BIN_DIR_WIN)/go-hare.exe
else
cd cmd/hare ; go build -o $(BIN_DIR)/go-hare
endif
.PHONY: hare
p2p:
ifeq ($(OS),WINDOWS_NT)
cd cmd/p2p ; go build -o $(BIN_DIR_WIN)/go-p2p.exe
else
cd cmd/p2p ; go build -o $(BIN_DIR)/go-p2p
endif
.PHONY: p2p
sync:
ifeq ($(OS),WINDOWS_NT)
cd cmd/sync ; go build -o $(BIN_DIR_WIN)/go-sync.exe
else
cd cmd/sync ; go build -o $(BIN_DIR)/go-sync
endif
.PHONY: sync
harness:
ifeq ($(OS),WINDOWS_NT)
cd cmd/integration ; go build -o $(BIN_DIR_WIN)/go-harness.exe
else
cd cmd/integration ; go build -o $(BIN_DIR)/go-harness
endif
.PHONY: harness
tidy:
go mod tidy
.PHONY: tidy
$(PLATFORMS):
ifeq ($(OS),Windows_NT)
set GOOS=$(os)&&set GOARCH=amd64&&go build ${LDFLAGS} -o $(CURR_DIR)/$(BINARY).exe
else
GOOS=$(os) GOARCH=amd64 go build ${LDFLAGS} -o $(CURR_DIR)/$(BINARY)
endif
.PHONY: $(PLATFORMS)
docker-local-build:
GOOS=linux GOARCH=amd64 go build ${LDFLAGS} -o $(BIN_DIR)/$(BINARY)
cd cmd/hare ; GOOS=linux GOARCH=amd64 go build -o $(BIN_DIR)/go-hare
cd cmd/p2p ; GOOS=linux GOARCH=amd64 go build -o $(BIN_DIR)/go-p2p
cd cmd/sync ; GOOS=linux GOARCH=amd64 go build -o $(BIN_DIR)/go-sync
cd cmd/integration ; GOOS=linux GOARCH=amd64 go build -o $(BIN_DIR)/go-harness
cd build ; docker build -f ../DockerfilePrebuiltBinary -t $(DOCKER_IMAGE) .
.PHONY: docker-local-build
arm6:
GOOS=linux GOARCH=arm GOARM=6 go build ${LDFLAGS} -o $(CURR_DIR)/$(BINARY)
.PHONY: pi
test:
ulimit -n 9999; go test -timeout 0 -p 1 ./...
.PHONY: test
test-no-app-test:
ulimit -n 9999; go test -timeout 0 -p 1 -tags exclude_app_test ./...
.PHONY: test
test-only-app-test:
ulimit -n 9999; go test -timeout 0 -p 1 -tags !exclude_app_test ./cmd/node
.PHONY: test
test-tidy:
# Working directory must be clean, or this test would be destructive
git diff --quiet || (echo "\033[0;31mWorking directory not clean!\033[0m" && git --no-pager diff && exit 1)
# We expect `go mod tidy` not to change anything, the test should fail otherwise
make tidy
git diff --exit-code || (git --no-pager diff && git checkout . && exit 1)
.PHONY: test-tidy
test-fmt:
git diff --quiet || (echo "\033[0;31mWorking directory not clean!\033[0m" && git --no-pager diff && exit 1)
# We expect `go fmt` not to change anything, the test should fail otherwise
go fmt ./...
git diff --exit-code || (git --no-pager diff && git checkout . && exit 1)
.PHONY: test-fmt
lint:
golint --set_exit_status ./...
go vet ./...
.PHONY: lint
cover:
@echo "mode: count" > cover-all.out
@$(foreach pkg,$(PKGS),\
go test -coverprofile=cover.out -covermode=count $(pkg);\
tail -n +2 cover.out >> cover-all.out;)
go tool cover -html=cover-all.out
.PHONY: cover
tag-and-build:
git diff --quiet || (echo "\033[0;31mWorking directory not clean!\033[0m" && git --no-pager diff && exit 1)
printf "${VERSION}" > version.txt
git commit -m "bump version to ${VERSION}" version.txt
git tag ${VERSION}
git push origin ${VERSION}
docker build -t go-spacemesh:${VERSION} .
docker tag go-spacemesh:${VERSION} spacemeshos/go-spacemesh:${VERSION}
docker push spacemeshos/go-spacemesh:${VERSION}
.PHONY: tag-and-build
list-versions:
@echo "Latest 5 tagged versions:\n"
@git for-each-ref --sort=-creatordate --count=5 --format '%(creatordate:short): %(refname:short)' refs/tags
.PHONY: list-versions
dockerbuild-go:
docker build -t $(DOCKER_IMAGE) .
.PHONY: dockerbuild-go
dockerbuild-test:
docker build -f DockerFileTests --build-arg GCLOUD_KEY="$(GCLOUD_KEY)" \
--build-arg PROJECT_NAME="$(PROJECT_NAME)" \
--build-arg CLUSTER_NAME="$(CLUSTER_NAME)" \
--build-arg CLUSTER_ZONE="$(CLUSTER_ZONE)" \
-t go-spacemesh-python:$(BRANCH) .
.PHONY: dockerbuild-test
dockerbuild-test-elk:
docker build -f DockerFileTests --build-arg GCLOUD_KEY="$(GCLOUD_KEY)" \
--build-arg PROJECT_NAME="$(PROJECT_NAME)" \
--build-arg CLUSTER_NAME="$(CLUSTER_NAME_ELK)" \
--build-arg CLUSTER_ZONE="$(CLUSTER_ZONE_ELK)" \
-t go-spacemesh-python:$(BRANCH) .
.PHONY: dockerbuild-test-elk
dockerpush: dockerbuild-go dockerpush-only
.PHONY: dockerpush
dockerpush-only:
echo "$(DOCKER_PASSWORD)" | docker login -u "$(DOCKER_USERNAME)" --password-stdin
docker tag $(DOCKER_IMAGE) spacemeshos/$(DOCKER_IMAGE)
docker push spacemeshos/$(DOCKER_IMAGE)
# for develop, we push an additional copy of the image using the commithash for archival
ifeq ($(BRANCH),develop)
docker tag $(DOCKER_IMAGE) spacemeshos/$(DOCKER_IMAGE_REPO):$(SHA)
docker push spacemeshos/$(DOCKER_IMAGE_REPO):$(SHA)
endif
.PHONY: dockerpush-only
docker-local-push: docker-local-build dockerpush-only
.PHONY: docker-local-push
ifdef TEST
DELIM=::
endif
dockerrun-p2p-elk:
ifndef ES_PASS
$(error ES_PASS is not set)
endif
$(DOCKERRUN) pytest -s -v p2p/test_p2p.py --tc-file=p2p/config.yaml --tc-format=yaml $(EXTRA_PARAMS)
.PHONY: dockerrun-p2p-elk
dockertest-p2p-elk: dockerbuild-test-elk dockerrun-p2p-elk
.PHONY: dockertest-p2p-elk
dockerrun-mining-elk:
ifndef ES_PASS
$(error ES_PASS is not set)
endif
$(DOCKERRUN) pytest -s -v test_bs.py --tc-file=config.yaml --tc-format=yaml $(EXTRA_PARAMS)
.PHONY: dockerrun-mining-elk
dockertest-mining-elk: dockerbuild-test-elk dockerrun-mining-elk
.PHONY: dockertest-mining-elk
dockerrun-hare-elk:
ifndef ES_PASS
$(error ES_PASS is not set)
endif
$(DOCKERRUN) pytest -s -v hare/test_hare.py::test_hare_sanity --tc-file=hare/config.yaml --tc-format=yaml $(EXTRA_PARAMS)
.PHONY: dockerrun-hare-elk
dockertest-hare-elk: dockerbuild-test-elk dockerrun-hare-elk
.PHONY: dockertest-hare-elk
dockerrun-sync-elk:
ifndef ES_PASS
$(error ES_PASS is not set)
endif
$(DOCKERRUN) pytest -s -v sync/test_sync.py --tc-file=sync/config.yaml --tc-format=yaml $(EXTRA_PARAMS)
.PHONY: dockerrun-sync-elk
dockertest-sync-elk: dockerbuild-test-elk dockerrun-sync-elk
.PHONY: dockertest-sync-elk
dockerrun-late-nodes-elk:
ifndef ES_PASS
$(error ES_PASS is not set)
endif
$(DOCKERRUN) pytest -s -v late_nodes/test_delayed.py --tc-file=late_nodes/delayed_config.yaml --tc-format=yaml $(EXTRA_PARAMS)
.PHONY: dockerrun-late-nodes-elk
dockertest-late-nodes-elk: dockerbuild-test-elk dockerrun-late-nodes-elk
.PHONY: dockertest-late-nodes-elk
dockerrun-genesis-voting-elk:
ifndef ES_PASS
$(error ES_PASS is not set)
endif
$(DOCKERRUN) pytest -s -v sync/genesis/test_genesis_voting.py --tc-file=sync/genesis/config.yaml --tc-format=yaml $(EXTRA_PARAMS)
.PHONY: dockerrun-genesis-voting-elk
dockertest-genesis-voting-elk: dockerbuild-test-elk dockerrun-genesis-voting-elk
.PHONY: dockertest-genesis-voting-elk
dockerrun-blocks-add-node-elk:
ifndef ES_PASS
$(error ES_PASS is not set)
endif
$(DOCKERRUN) pytest -s -v block_atx/add_node/test_blocks_add_node.py --tc-file=block_atx/add_node/config.yaml --tc-format=yaml $(EXTRA_PARAMS)
.PHONY: dockerrun-blocks-add-node-elk
dockertest-blocks-add-node-elk: dockerbuild-test-elk dockerrun-blocks-add-node-elk
.PHONY: dockertest-blocks-add-node-elk
dockerrun-blocks-remove-node-elk:
ifndef ES_PASS
$(error ES_PASS is not set)
endif
$(DOCKERRUN) pytest -s -v block_atx/remove_node/test_blocks_remove_node.py --tc-file=block_atx/remove_node/config.yaml --tc-format=yaml $(EXTRA_PARAMS)
.PHONY: dockerrun-blocks-remove-node-elk
dockertest-blocks-remove-node-elk: dockerbuild-test-elk dockerrun-blocks-remove-node-elk
.PHONY: dockertest-blocks-remove-node-elk
dockerrun-blocks-stress:
ifndef ES_PASSWD
$(error ES_PASSWD is not set)
endif
$(DOCKERRUN) pytest -s -v stress/blocks_stress/test_stress_blocks.py --tc-file=stress/blocks_stress/config.yaml --tc-format=yaml
.PHONY: dockerrun-blocks-stress
dockertest-blocks-stress: dockerbuild-test dockerrun-blocks-stress
.PHONY: dockertest-blocks-stress
dockerrun-grpc-stress:
ifndef ES_PASSWD
$(error ES_PASSWD is not set)
endif
$(DOCKERRUN) pytest -s -v stress/grpc_stress/test_stress_grpc.py --tc-file=stress/grpc_stress/config.yaml --tc-format=yaml
.PHONY: dockerrun-grpc-stress
dockertest-grpc-stress: dockerbuild-test dockerrun-grpc-stress
.PHONY: dockertest-grpc-stress
dockerrun-sync-stress:
ifndef ES_PASSWD
$(error ES_PASSWD is not set)
endif
$(DOCKERRUN) pytest -s -v stress/sync_stress/test_sync.py --tc-file=stress/sync_stress/config.yaml --tc-format=yaml
.PHONY: dockerrun-sync-stress
dockertest-sync-stress: dockerbuild-test dockerrun-sync-stress
.PHONY: dockertest-sync-stress
dockerrun-tx-stress:
ifndef ES_PASSWD
$(error ES_PASSWD is not set)
endif
$(DOCKERRUN) pytest -s -v stress/tx_stress/test_stress_txs.py --tc-file=stress/tx_stress/config.yaml --tc-format=yaml
.PHONY: dockerrun-tx-stress
dockertest-tx-stress: dockerbuild-test dockerrun-tx-stress
.PHONY: dockertest-tx-stress
# The following is used to run tests one after the other locally
dockerrun-test: dockerbuild-test-elk dockerrun-p2p-elk dockerrun-mining-elk dockerrun-hare-elk dockerrun-sync-elk dockerrun-late-nodes-elk dockerrun-blocks-add-node-elk dockerrun-blocks-remove-node-elk
.PHONY: dockerrun-test
dockerrun-all: dockerpush dockerrun-test
.PHONY: dockerrun-all
dockerrun-stress: dockerbuild-test dockerrun-blocks-stress dockerrun-grpc-stress dockerrun-sync-stress dockerrun-tx-stress
.PHONY: dockerrun-stress
dockertest-stress: dockerpush dockerrun-stress
.PHONY: dockertest-stress