-
Notifications
You must be signed in to change notification settings - Fork 80
/
Makefile
465 lines (401 loc) · 20.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
453
454
455
456
457
458
459
460
461
462
463
464
465
BUILDER_TAG?="noobaa-builder"
NOOBAA_BASE_TAG?="noobaa-base"
NOOBAA_TAG?="noobaa"
TESTER_TAG?="noobaa-tester"
NOOBAA_RPM_TAG?="noobaa-rpm-build"
POSTGRES_IMAGE?="centos/postgresql-12-centos7"
MONGO_IMAGE?="centos/mongodb-36-centos7"
CENTOS_VER?=9
CONTAINER_ENGINE?=$(shell docker version >/dev/null 2>&1 && echo docker)
ifeq ($(CONTAINER_ENGINE),)
CONTAINER_ENGINE=$(shell podman version >/dev/null 2>&1 && echo podman)
endif
ifeq ($(CONTAINER_ENGINE),)
CONTAINER_ENGINE=$(shell lima nerdctl version >/dev/null 2>&1 && echo lima nerdctl)
endif
# If CONTAINER_PLATFORM is not set, then set automatically based on the host.
ifeq ($(CONTAINER_PLATFORM),)
# see https://github.com/containerd/nerdctl/blob/main/docs/multi-platform.md
# e.g use CONTAINER_PLATFORM=amd64 for building x86_64 on arm.
CONTAINER_PLATFORM=$(shell [ "`arch`" = "arm64" ] || [ "`arch`" = "aarch64" ] && echo amd64)
ifneq ($(strip $(CONTAINER_PLATFORM)),)
ifeq ($(CONTAINER_ENGINE),$(filter $(CONTAINER_ENGINE), docker podman))
CONTAINER_PLATFORM:=linux/$(CONTAINER_PLATFORM)
endif
endif
endif
CONTAINER_PLATFORM_FLAG=
ifneq ($(CONTAINER_PLATFORM),)
CONTAINER_PLATFORM_FLAG="--platform=$(CONTAINER_PLATFORM)"
endif
PLATFORM=$(shell echo ${CONTAINER_PLATFORM} | tr '/' '-')
ifneq ($(PLATFORM),)
NOOBAA_RPM_TAG := "$(NOOBAA_RPM_TAG):$(PLATFORM)"
endif
GIT_COMMIT?="$(shell git rev-parse HEAD | head -c 7)"
NAME_POSTFIX?="$(shell ${CONTAINER_ENGINE} ps -a | wc -l | xargs)"
UNAME_S?=$(shell uname -s)
ifeq ($(UNAME_S),Linux)
ifeq ($(UID),0)
HAVE_CPUSET ?= $(shell grep -c -w cpuset /sys/fs/cgroup/cgroup.controllers 2>/dev/null)
else
HAVE_CPUSET ?= $(shell grep -c -w cpuset /sys/fs/cgroup/user.slice/user-$(UID).slice/cgroup.controllers 2>/dev/null)
endif
ifeq ($(HAVE_CPUSET),1)
CPUS?=$(shell nproc --ignore=1)
CPUSET?=--cpuset-cpus=0-${CPUS}
endif
endif
SUPPRESS_LOGS?=""
REDIRECT_STDOUT=
ifeq ($(SUPPRESS_LOGS), true)
REDIRECT_STDOUT=1> /dev/null
endif
NO_CACHE?=""
CACHE_FLAG=
ifeq ($(NO_CACHE), true)
CACHE_FLAG="--no-cache"
endif
USE_HOSTNETWORK?=""
NETWORK_FLAG=
ifeq ($(USE_HOSTNETWORK), true)
NETWORK_FLAG="--network=host"
endif
# running blob mock on - all tests run OR on single test run of test_s3_ops.js
NAMESPACE_BLOB_TEST?="test_s3_ops.js"
RUN_BLOB_MOCK=true
ifdef testname
ifneq ("$(testname)", $(NAMESPACE_BLOB_TEST))
RUN_BLOB_MOCK=false
endif
endif
BUILD_S3SELECT?=1
BUILD_S3SELECT_PARQUET?=0
###############
# BUILD LOCAL #
###############
default: build
.PHNOY: default
# this target builds incrementally
build:
npm install
npm run build
.PHONY: build
clean_build:
npm run clean
.PHONY: clean_build
# this target cleans and rebuilds
rebuild: clean_build build
.PHONY: rebuild
pkg: build
npm run pkg
.PHONY: pkg
################
# BUILD IMAGES #
################
assert-container-engine:
@ if [ "${CONTAINER_ENGINE}" = "" ]; then \
echo "\n Error: You must have container engine installed\n"; \
exit 1; \
fi
.PHONY: assert-container-engine
all: tester noobaa
@echo "\033[1;32mAll done.\033[0m"
.PHONY: all
builder: assert-container-engine
@echo "\n##\033[1;32m Build image noobaa-builder ...\033[0m"
$(CONTAINER_ENGINE) build $(CONTAINER_PLATFORM_FLAG) $(CPUSET) --build-arg CENTOS_VER=$(CENTOS_VER) --build-arg BUILD_S3SELECT=$(BUILD_S3SELECT) --build-arg BUILD_S3SELECT_PARQUET=$(BUILD_S3SELECT_PARQUET) -f src/deploy/NVA_build/builder.Dockerfile $(CACHE_FLAG) $(NETWORK_FLAG) -t noobaa-builder .
$(CONTAINER_ENGINE) tag noobaa-builder $(BUILDER_TAG)
@echo "##\033[1;32m Build image noobaa-builder done.\033[0m"
.PHONY: builder
base: builder
@echo "\n##\033[1;32m Build image noobaa-base ...\033[0m"
$(CONTAINER_ENGINE) build $(CONTAINER_PLATFORM_FLAG) $(CPUSET) --build-arg BUILD_S3SELECT=$(BUILD_S3SELECT) --build-arg BUILD_S3SELECT_PARQUET=$(BUILD_S3SELECT_PARQUET) -f src/deploy/NVA_build/Base.Dockerfile $(CACHE_FLAG) $(NETWORK_FLAG) -t noobaa-base . $(REDIRECT_STDOUT)
$(CONTAINER_ENGINE) tag noobaa-base $(NOOBAA_BASE_TAG)
@echo "##\033[1;32m Build image noobaa-base done.\033[0m"
.PHONY: base
noobaa: base
@echo "\n##\033[1;32m Build image noobaa ...\033[0m"
@echo "$(CONTAINER_ENGINE) build $(CONTAINER_PLATFORM_FLAG)"
$(CONTAINER_ENGINE) build $(CONTAINER_PLATFORM_FLAG) $(CPUSET) --build-arg CENTOS_VER=$(CENTOS_VER) --build-arg BUILD_S3SELECT=$(BUILD_S3SELECT) --build-arg BUILD_S3SELECT_PARQUET=$(BUILD_S3SELECT_PARQUET) -f src/deploy/NVA_build/NooBaa.Dockerfile $(CACHE_FLAG) $(NETWORK_FLAG) -t noobaa --build-arg GIT_COMMIT=$(GIT_COMMIT) . $(REDIRECT_STDOUT)
$(CONTAINER_ENGINE) tag noobaa $(NOOBAA_TAG)
@echo "##\033[1;32m Build image noobaa done.\033[0m"
.PHONY: noobaa
executable: base
@echo "\n##\033[1;32m Build image noobaa-core-executable ...\033[0m"
$(CONTAINER_ENGINE) build $(CONTAINER_PLATFORM_FLAG) $(CPUSET) -f src/deploy/standalone/executable.Dockerfile $(CACHE_FLAG) $(NETWORK_FLAG) -t noobaa-core-executable --build-arg GIT_COMMIT=$(GIT_COMMIT) . $(REDIRECT_STDOUT)
$(CONTAINER_ENGINE) build $(CONTAINER_PLATFORM_FLAG) $(CPUSET) -f src/deploy/standalone/export.Dockerfile $(CACHE_FLAG) $(NETWORK_FLAG) --build-arg GIT_COMMIT=$(GIT_COMMIT) . $(REDIRECT_STDOUT) --output /tmp/noobaa-core-executable/
@echo "##\033[1;32m Build image noobaa-core-executable done.\033[0m"
.PHONY: executable
# This rule builds a container image that includes developer tools
# which allows to build and debug the project.
nbdev:
@echo "\n##\033[1;32m Build image nbdev ...\033[0m"
$(CONTAINER_ENGINE) build $(CONTAINER_PLATFORM_FLAG) $(CPUSET) -f src/deploy/NVA_build/dev.Dockerfile $(CACHE_FLAG) -t nbdev --build-arg CENTOS_VER=$(CENTOS_VER) --build-arg GIT_COMMIT=$(GIT_COMMIT) . $(REDIRECT_STDOUT)
@echo "##\033[1;32m Build image nbdev done.\033[0m"
@echo ""
@echo "Usage: docker run -it nbdev"
@echo ""
.PHONY: nbdev
rpm: builder
echo "\033[1;34mStarting RPM build for $${CONTAINER_PLATFORM}.\033[0m"
mkdir -p build/rpm
$(CONTAINER_ENGINE) rm -f noobaa-rpm-build-env
$(CONTAINER_ENGINE) build $(CONTAINER_PLATFORM_FLAG) $(CPUSET) -f src/deploy/RPM_build/RPM.Dockerfile $(CACHE_FLAG) -t $(NOOBAA_RPM_TAG) --build-arg CENTOS_VER=$(CENTOS_VER) --build-arg BUILD_S3SELECT=$(BUILD_S3SELECT) --build-arg BUILD_S3SELECT_PARQUET=$(BUILD_S3SELECT_PARQUET) --build-arg SRPM_ONLY=$(SRPM_ONLY) --build-arg GIT_COMMIT=$(GIT_COMMIT) . $(REDIRECT_STDOUT)
echo "\033[1;32mImage \"$(NOOBAA_RPM_TAG)\" is ready.\033[0m"
echo "Generating RPM..."
$(CONTAINER_ENGINE) run --name noobaa-rpm-build-env -t $(NOOBAA_RPM_TAG)
mkdir -p $(PWD)/build/rpm && $(CONTAINER_ENGINE) cp noobaa-rpm-build-env:/export/. $(PWD)/build/rpm/
$(CONTAINER_ENGINE) rm -f noobaa-rpm-build-env
echo "\033[1;32mRPM for platform \"$(NOOBAA_RPM_TAG)\" is ready in build/rpm.\033[0m";
.PHONY: rpm
###############
# TEST IMAGES #
###############
tester: noobaa
@echo "\n##\033[1;32m Build image noobaa-tester ...\033[0m"
$(CONTAINER_ENGINE) build $(CONTAINER_PLATFORM_FLAG) $(CPUSET) -f src/deploy/NVA_build/Tests.Dockerfile $(CACHE_FLAG) $(NETWORK_FLAG) -t noobaa-tester . $(REDIRECT_STDOUT)
$(CONTAINER_ENGINE) tag noobaa-tester $(TESTER_TAG)
@echo "\033[1;32mTester done.\033[0m"
@echo "##\033[1;32m Build image noobaa-tester done.\033[0m"
.PHONY: tester
build-ssl-postgres: tester
@echo "\n##\033[1;32m Cretaing SSL CA for image ...\033[0m"
mkdir -p -m 755 certs
openssl ecparam -name prime256v1 -genkey -noout -out certs/ca.key
openssl req -new -x509 -sha256 -key certs/ca.key -out certs/ca.crt -subj "/CN=ca.noobaa.com"
@echo "\n##\033[1;32m Build image for SSL Postgres ...\033[0m"
$(CONTAINER_ENGINE) build $(CONTAINER_PLATFORM_FLAG) $(CPUSET) --build-arg HOST=ssl-pg-$(GIT_COMMIT)-$(NAME_POSTFIX) -f src/deploy/NVA_build/SSLPostgres.Dockerfile $(CACHE_FLAG) $(NETWORK_FLAG) -t postgres:ssl . $(REDIRECT_STDOUT)
@echo "\033[1;32mBuild SSL Postgres done.\033[0m"
@echo "##\033[1;32m Build image postgres:ssl done.\033[0m"
.PHONY: build-ssl-postgres
test: tester
@echo "\033[1;34mRunning tests with Mongo.\033[0m"
@$(call create_docker_network)
@$(call run_mongo)
@$(call run_blob_mock)
@echo "\033[1;34mRunning tests\033[0m"
$(CONTAINER_ENGINE) run $(CPUSET) --network noobaa-net --name noobaa_$(GIT_COMMIT)_$(NAME_POSTFIX) --env "SUPPRESS_LOGS=$(SUPPRESS_LOGS)" --env "DB_TYPE=mongodb" --env "MONGODB_URL=mongodb://noobaa:noobaa@coretest-mongo-$(GIT_COMMIT)-$(NAME_POSTFIX)" --env "BLOB_HOST=blob-mock-$(GIT_COMMIT)-$(NAME_POSTFIX)" $(TESTER_TAG)
@$(call stop_noobaa)
@$(call stop_blob_mock)
@$(call stop_mongo)
@$(call remove_docker_network)
.PHONY: test
root-perm-test: tester
@echo "\033[1;34mRunning tests with Mongo with root permission.\033[0m"
@$(call create_docker_network)
@$(call run_mongo)
@echo "\033[1;34mRunning root permission tests\033[0m"
$(CONTAINER_ENGINE) run $(CPUSET) --network noobaa-net --privileged --user root --name noobaa_$(GIT_COMMIT)_$(NAME_POSTFIX) --env "SUPPRESS_LOGS=$(SUPPRESS_LOGS)" --env "DB_TYPE=mongodb" --env "MONGODB_URL=mongodb://noobaa:noobaa@coretest-mongo-$(GIT_COMMIT)-$(NAME_POSTFIX)" $(TESTER_TAG) ./src/test/unit_tests/run_npm_test_on_test_container.sh -s sudo_index.js
@$(call stop_noobaa)
@$(call stop_mongo)
@$(call remove_docker_network)
.PHONY: root-perm-test
run-single-test: tester
@echo "\033[1;34mRunning single test with Mongo.\033[0m"
@$(call create_docker_network)
@$(call run_mongo)
@$(call run_blob_mock)
@echo "\033[1;34mRunning tests\033[0m"
$(CONTAINER_ENGINE) run $(CPUSET) --network noobaa-net --name noobaa_$(GIT_COMMIT)_$(NAME_POSTFIX) --env "SUPPRESS_LOGS=$(SUPPRESS_LOGS)" --env "DB_TYPE=mongodb" --env "MONGODB_URL=mongodb://noobaa:noobaa@coretest-mongo-$(GIT_COMMIT)-$(NAME_POSTFIX)" --env "BLOB_HOST=blob-mock-$(GIT_COMMIT)-$(NAME_POSTFIX)" --env "NOOBAA_LOG_LEVEL=all" $(TESTER_TAG) ./src/test/unit_tests/run_npm_test_on_test_container.sh -s $(testname)
@$(call stop_noobaa)
@$(call stop_blob_mock)
@$(call stop_mongo)
@$(call remove_docker_network)
.PHONY: run-single-test
run-nc-tests: tester
@$(call create_docker_network)
@echo "\033[1;34mRunning nc tests\033[0m"
$(CONTAINER_ENGINE) run $(CPUSET) --network noobaa-net --privileged --user root --name noobaa_$(GIT_COMMIT)_$(NAME_POSTFIX) --env "NC_CORETEST=true" $(TESTER_TAG) ./src/test/unit_tests/run_npm_test_on_test_container.sh -s nc_index.js
@$(call stop_noobaa)
@$(call remove_docker_network)
.PHONY: run-nc-tests
run-single-test-postgres: tester
@echo "\033[1;34mRunning single test with Postgres.\033[0m"
@$(call create_docker_network)
@$(call run_postgres)
@$(call run_blob_mock)
@echo "\033[1;34mRunning tests\033[0m"
$(CONTAINER_ENGINE) run $(CPUSET) --network noobaa-net --name noobaa_$(GIT_COMMIT)_$(NAME_POSTFIX) --env "SUPPRESS_LOGS=$(SUPPRESS_LOGS)" --env "POSTGRES_HOST=coretest-postgres-$(GIT_COMMIT)-$(NAME_POSTFIX)" --env "POSTGRES_USER=noobaa" --env "DB_TYPE=postgres" --env "PG_ENABLE_QUERY_LOG=true" --env "PG_EXPLAIN_QUERIES=true" --env "BLOB_HOST=blob-mock-$(GIT_COMMIT)-$(NAME_POSTFIX)" $(TESTER_TAG) ./src/test/unit_tests/run_npm_test_on_test_container.sh -s $(testname)
@$(call stop_noobaa)
@$(call stop_postgres)
@$(call stop_blob_mock)
@$(call remove_docker_network)
.PHONY: run-single-test-postgres
test-postgres: tester
@echo "\033[1;34mRunning tests with Postgres.\033[0m"
@$(call create_docker_network)
@$(call run_postgres)
@$(call run_blob_mock)
@echo "\033[1;34mRunning tests\033[0m"
$(CONTAINER_ENGINE) run $(CPUSET) --network noobaa-net --name noobaa_$(GIT_COMMIT)_$(NAME_POSTFIX) --env "SUPPRESS_LOGS=$(SUPPRESS_LOGS)" --env "POSTGRES_HOST=coretest-postgres-$(GIT_COMMIT)-$(NAME_POSTFIX)" --env "BLOB_HOST=blob-mock-$(GIT_COMMIT)-$(NAME_POSTFIX)" --env "POSTGRES_USER=noobaa" --env "DB_TYPE=postgres" $(TESTER_TAG)
@$(call stop_noobaa)
@$(call stop_postgres)
@$(call stop_blob_mock)
@$(call remove_docker_network)
.PHONY: test-postgres
test-external-postgres: build-ssl-postgres
@echo "\033[1;34mRunning tests with Postgres.\033[0m"
@$(call create_docker_network)
@$(call run_external_postgres)
@$(call run_blob_mock)
@$(call create_ssl_certs)
@echo "\033[1;34mRunning tests on SSL PG(15)\033[0m"
$(CONTAINER_ENGINE) run $(CPUSET) --network noobaa-net --name noobaa_$(GIT_COMMIT)_$(NAME_POSTFIX) --env "SUPPRESS_LOGS=$(SUPPRESS_LOGS)" \
--env "POSTGRES_HOST=ssl-pg-$(GIT_COMMIT)-$(NAME_POSTFIX)" --env "POSTGRES_USER=postgres" --env "POSTGRES_DBNAME=coretest" \
--env "NODE_EXTRA_CA_CERTS=/tmp/ca.crt" --env "POSTGRES_SSL_REQUIRED=true" --env "DB_TYPE=postgres" --env "BLOB_HOST=blob-mock-$(GIT_COMMIT)-$(NAME_POSTFIX)" \
-v $(PWD)/logs:/logs -v $(PWD)/certs:/etc/external-db-secret -v $(PWD)/certs/ca.crt:/tmp/ca.crt $(TESTER_TAG)
@$(call stop_noobaa)
@$(call stop_external_postgres)
@$(call stop_blob_mock)
@$(call remove_docker_network)
.PHONY: test-external-postgres
tests: test #alias for test
.PHONY: tests
test-cephs3: tester
@echo "\033[1;34mRunning tests with Postgres.\033[0m"
@$(call create_docker_network)
@$(call run_postgres)
@echo "\033[1;34mRunning tests\033[0m"
$(CONTAINER_ENGINE) run $(CPUSET) --network noobaa-net --name noobaa_$(GIT_COMMIT)_$(NAME_POSTFIX) --env "SUPPRESS_LOGS=$(SUPPRESS_LOGS)" --env "POSTGRES_HOST=coretest-postgres-$(GIT_COMMIT)-$(NAME_POSTFIX)" --env "POSTGRES_USER=noobaa" --env "DB_TYPE=postgres" --env "POSTGRES_DBNAME=coretest" -v $(PWD)/logs:/logs $(TESTER_TAG) "./src/test/system_tests/ceph_s3_tests/run_ceph_test_on_test_container.sh"
@$(call stop_noobaa)
@$(call stop_postgres)
@$(call remove_docker_network)
.PHONY: test-cephs3
test-nsfs-cephs3: tester
@echo "\033[1;34mRunning Ceph S3 tests on NSFS Standalone platform\033[0m"
$(CONTAINER_ENGINE) run $(CPUSET) --privileged --user root --name noobaa_$(GIT_COMMIT)_$(NAME_POSTFIX) --env "SUPPRESS_LOGS=$(SUPPRESS_LOGS)" -v $(PWD)/logs:/logs $(TESTER_TAG) "./src/test/system_tests/ceph_s3_tests/run_ceph_nsfs_test_on_test_container.sh"
.PHONY: test-nsfs-cephs3
test-sanity: tester
@echo "\033[1;34mRunning tests with Postgres.\033[0m"
@$(call create_docker_network)
@$(call run_postgres)
@echo "\033[1;34mRunning sanity tests\033[0m"
$(CONTAINER_ENGINE) run $(CPUSET) --network noobaa-net --name noobaa_$(GIT_COMMIT)_$(NAME_POSTFIX) --env "SUPPRESS_LOGS=$(SUPPRESS_LOGS)" --env "POSTGRES_HOST=coretest-postgres-$(GIT_COMMIT)-$(NAME_POSTFIX)" --env "POSTGRES_USER=noobaa" --env "DB_TYPE=postgres" --env "POSTGRES_DBNAME=coretest" -v $(PWD)/logs:/logs $(TESTER_TAG) "./src/test/system_tests/run_sanity_test_on_test_container.sh"
@$(call stop_noobaa)
@$(call stop_postgres)
@$(call remove_docker_network)
.PHONY: test-sanity
test-external-pg-sanity: build-ssl-postgres
@echo "\033[1;34mRunning tests with External Postgres (v15).\033[0m"
@$(call create_docker_network)
@$(call run_external_postgres)
@$(call create_ssl_certs)
@echo "\033[1;34mRunning sanity tests on SSL PG(15)\033[0m"
$(CONTAINER_ENGINE) run $(CPUSET) --network noobaa-net --name noobaa_$(GIT_COMMIT)_$(NAME_POSTFIX) --env "SUPPRESS_LOGS=$(SUPPRESS_LOGS)" \
--env "POSTGRES_HOST=ssl-pg-$(GIT_COMMIT)-$(NAME_POSTFIX)" --env "POSTGRES_USER=postgres" --env "POSTGRES_DBNAME=postgres" \
--env "NODE_EXTRA_CA_CERTS=/tmp/ca.crt" --env "POSTGRES_SSL_REQUIRED=true" --env "DB_TYPE=postgres" \
-v $(PWD)/logs:/logs -v $(PWD)/certs:/etc/external-db-secret -v $(PWD)/certs/ca.crt:/tmp/ca.crt $(TESTER_TAG) \
"./src/test/system_tests/run_sanity_test_on_test_container.sh"
@$(call stop_noobaa)
@$(call stop_external_postgres)
@$(call remove_docker_network)
.PHONY: test-external-pg-sanity
clean:
@echo Stopping and Deleting containers
@$(CONTAINER_ENGINE) ps -a | grep noobaa_ | awk '{print $1}' | xargs $(CONTAINER_ENGINE) stop &> /dev/null
@$(CONTAINER_ENGINE) ps -a | grep noobaa_ | awk '{print $1}' | xargs $(CONTAINER_ENGINE) rm &> /dev/null
.PHONY: clean
######################
## HELPER FUNCTIONS ##
######################
##########
# NOOBAA #
##########
define stop_noobaa
@echo "\033[1;34mStopping/removing test container\033[0m"
$(CONTAINER_ENGINE) network disconnect noobaa-net noobaa_$(GIT_COMMIT)_$(NAME_POSTFIX)
$(CONTAINER_ENGINE) stop noobaa_$(GIT_COMMIT)_$(NAME_POSTFIX)
$(CONTAINER_ENGINE) rm noobaa_$(GIT_COMMIT)_$(NAME_POSTFIX)
@echo "\033[1;32mRemoving test container done.\033[0m"
endef
###########
# NETWORK #
###########
define create_docker_network
@echo "\033[1;34mCreating docker network\033[0m"
$(CONTAINER_ENGINE) network create noobaa-net || true
@echo "\033[1;32mCreate docker network done.\033[0m"
endef
define remove_docker_network
@echo "\033[1;34mRemove docker network\033[0m"
$(CONTAINER_ENGINE) network rm noobaa-net
@echo "\033[1;32mRemove docker network done.\033[0m"
endef
#########
# MONGO #
#########
define run_mongo
@echo "\033[1;34mRunning Mongo container\033[0m"
$(CONTAINER_ENGINE) run -d $(CPUSET) --network noobaa-net --name coretest-mongo-$(GIT_COMMIT)-$(NAME_POSTFIX) --env "MONGODB_ADMIN_PASSWORD=noobaa" --env "MONGODB_DATABASE=coretest" --env "MONGODB_USER=noobaa" --env "MONGODB_PASSWORD=noobaa" $(MONGO_IMAGE)
@echo "\033[1;32mRun mongo done.\033[0m"
endef
define stop_mongo
@echo "\033[1;34mStopping/removing Mongo container\033[0m"
$(CONTAINER_ENGINE) network disconnect noobaa-net coretest-mongo-$(GIT_COMMIT)-$(NAME_POSTFIX)
$(CONTAINER_ENGINE) stop coretest-mongo-$(GIT_COMMIT)-$(NAME_POSTFIX)
$(CONTAINER_ENGINE) rm coretest-mongo-$(GIT_COMMIT)-$(NAME_POSTFIX)
@echo "\033[1;32mStop mongo done.\033[0m"
endef
############
# POSTGRES #
############
define run_postgres
@echo "\033[1;34mRunning Postgres container\033[0m"
$(CONTAINER_ENGINE) run -d $(CPUSET) --network noobaa-net --name coretest-postgres-$(GIT_COMMIT)-$(NAME_POSTFIX) --env "POSTGRESQL_DATABASE=coretest" --env "POSTGRESQL_USER=noobaa" --env "POSTGRESQL_PASSWORD=noobaa" --env "LC_COLLATE=C" $(POSTGRES_IMAGE)
@echo "\033[1;34mWaiting for postgres to start..\033[0m"
sleep 20
@echo "\033[1;32mRun postgres done.\033[0m"
endef
define stop_postgres
@echo "\033[1;34mStopping/removing Postgres container\033[0m"
$(CONTAINER_ENGINE) network disconnect noobaa-net coretest-postgres-$(GIT_COMMIT)-$(NAME_POSTFIX)
$(CONTAINER_ENGINE) stop coretest-postgres-$(GIT_COMMIT)-$(NAME_POSTFIX)
$(CONTAINER_ENGINE) rm coretest-postgres-$(GIT_COMMIT)-$(NAME_POSTFIX)
@echo "\033[1;32mStop postgres done.\033[0m"
endef
#########################
# SSL EXTERNAL POSTGRES #
#########################
define run_external_postgres
@echo "\033[1;34mRunning Postgres container\033[0m"
$(CONTAINER_ENGINE) run -d $(CPUSET) --network noobaa-net --name ssl-pg-$(GIT_COMMIT)-$(NAME_POSTFIX) --env "POSTGRES_PASSWORD=noobaa" --env "LC_COLLATE=C" -v $(PWD)/certs/ca.crt:/etc/ssl/certs/ca.crt postgres:ssl
@echo "\033[1;34mWaiting for postgres to start..\033[0m"
sleep 20
@echo "\033[1;32mRun postgres done.\033[0m"
endef
define stop_external_postgres
@echo "\033[1;34mStopping/removing Postgres container\033[0m"
$(CONTAINER_ENGINE) network disconnect noobaa-net ssl-pg-$(GIT_COMMIT)-$(NAME_POSTFIX)
$(CONTAINER_ENGINE) stop ssl-pg-$(GIT_COMMIT)-$(NAME_POSTFIX)
$(CONTAINER_ENGINE) rm ssl-pg-$(GIT_COMMIT)-$(NAME_POSTFIX)
@echo "\033[1;32mStop postgres done.\033[0m"
endef
define create_ssl_certs
@echo "\033[1;34mCreating ssl client certificates for NooBaa container\033[0m"
openssl ecparam -name prime256v1 -genkey -noout -out certs/tls.key
openssl req -new -sha256 -key certs/tls.key -out certs/tls.csr -subj "/CN=postgres"
openssl x509 -req -in certs/tls.csr -CA certs/ca.crt -CAkey certs/ca.key -CAcreateserial -out certs/tls.crt -days 365 -sha256
chmod +r certs/tls.key
endef
#############
# BLOB MOCK #
#############
define run_blob_mock
@echo "\033[1;34mStarting blob mock server if RUN_BLOB_MOCK=$(RUN_BLOB_MOCK) is true.\033[0m"
@ if [ $(RUN_BLOB_MOCK) = true ]; then \
echo "\033[1;34mRunning Blob mock.\033[0m"; \
$(CONTAINER_ENGINE) run -p 10000:10000 -d --network noobaa-net --name blob-mock-$(GIT_COMMIT)-$(NAME_POSTFIX) mcr.microsoft.com/azure-storage/azurite azurite-blob --blobHost 0.0.0.0; \
fi
@echo "\033[1;32mBlob mock server done.\033[0m"
endef
define stop_blob_mock
@echo "\033[1;34mStopping blob mock server if RUN_BLOB_MOCK=$(RUN_BLOB_MOCK) is true.\033[0m"
@ if [ $(RUN_BLOB_MOCK) = true ]; then \
echo "\033[1;34mStopping tests with Blob mock.\033[0m"; \
$(CONTAINER_ENGINE) network disconnect noobaa-net blob-mock-$(GIT_COMMIT)-$(NAME_POSTFIX); \
$(CONTAINER_ENGINE) stop blob-mock-$(GIT_COMMIT)-$(NAME_POSTFIX); \
$(CONTAINER_ENGINE) rm blob-mock-$(GIT_COMMIT)-$(NAME_POSTFIX); \
fi
@echo "\033[1;32mBlob mock server stop done.\033[0m"
endef