forked from noobaa/noobaa-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
130 lines (112 loc) · 5.24 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
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
GIT_COMMIT?="$(shell git rev-parse HEAD | head -c 7)"
NAME_POSTFIX?="$(shell ${CONTAINER_ENGINE} ps -a | wc -l | xargs)"
BUILDER_TAG?="noobaa-builder"
TESTER_TAG?="noobaa-tester"
POSTGRES_IMAGE?="centos/postgresql-12-centos7"
NOOBAA_TAG?="noobaa"
NOOBAA_BASE_TAG?="noobaa-base"
SUPPRESS_LOGS?=""
NO_CACHE?=""
USE_HOSTNETWORK?=""
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
REDIRECT_STDOUT=
ifeq ($(SUPPRESS_LOGS), true)
REDIRECT_STDOUT=1> /dev/null
endif
CACHE_FLAG=
ifeq ($(NO_CACHE), true)
CACHE_FLAG="--no-cache"
endif
NETWORK_FLAG=
ifeq ($(USE_HOSTNETWORK), true)
NETWORK_FLAG="--network=host"
endif
#passing DOCKER_BUILDKIT="DOCKER_BUILDKIT=0" will disable buildkit (and 1 will enable it). It will not work with podman
DOCKER_BUILDKIT?=DOCKER_BUILDKIT=1
ifeq ($(CONTAINER_ENGINE), podman)
DOCKER_BUILDKIT=
endif
export
assert-container-engine:
@ if [ "${CONTAINER_ENGINE}" = "" ]; then \
echo "\n Error: You must have container engine installed\n"; \
exit 1; \
fi
all: tester noobaa
@echo "\033[1;32mAll done.\033[0m"
.PHONY: all
builder: assert-container-engine
@echo "\033[1;34mStarting Builder $(CONTAINER_ENGINE) build.\033[0m"
$(DOCKER_BUILDKIT) $(CONTAINER_ENGINE) build $(CPUSET) -f src/deploy/NVA_build/builder.Dockerfile $(CACHE_FLAG) $(NETWORK_FLAG) -t noobaa-builder .
$(CONTAINER_ENGINE) tag noobaa-builder $(BUILDER_TAG)
@echo "\033[1;32mBuilder done.\033[0m"
.PHONY: builder
base: builder
@echo "\033[1;34mStarting Base $(CONTAINER_ENGINE) build.\033[0m"
$(DOCKER_BUILDKIT) $(CONTAINER_ENGINE) build $(CPUSET) -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;32mBase done.\033[0m"
.PHONY: base
tester: noobaa
@echo "\033[1;34mStarting Tester $(CONTAINER_ENGINE) build.\033[0m"
$(DOCKER_BUILDKIT) $(CONTAINER_ENGINE) build $(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"
.PHONY: tester
test: tester
@echo "\033[1;34mRunning tests.\033[0m"
$(CONTAINER_ENGINE) run $(CPUSET) --name noobaa_$(GIT_COMMIT)_$(NAME_POSTFIX) --env "SUPPRESS_LOGS=$(SUPPRESS_LOGS)" $(TESTER_TAG)
.PHONY: test
test-postgres: tester
@echo "\033[1;34mRunning tests with Postgres.\033[0m"
@echo "\033[1;34mCreating docker network\033[0m"
$(CONTAINER_ENGINE) network create noobaa-net || true
@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" $(POSTGRES_IMAGE)
@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" $(TESTER_TAG)
.PHONY: test-postgres
tests: test #alias for test
.PHONY: tests
noobaa: base
@echo "\033[1;34mStarting NooBaa $(CONTAINER_ENGINE) build.\033[0m"
$(DOCKER_BUILDKIT) $(CONTAINER_ENGINE) build $(CPUSET) -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;32mNooBaa done.\033[0m"
.PHONY: noobaa
verify-fe-lib: builder
@echo "\033[1;Verifying Frontend Library $(CONTAINER_ENGINE) build.\033[0m"
$(DOCKER_BUILDKIT) $(CONTAINER_ENGINE) build $(CPUSET) -f src/deploy/NVA_build/FrontendLib.Dockerfile $(CACHE_FLAG) $(NETWORK_FLAG) -t frontend-lib . $(REDIRECT_STDOUT)
@echo "\033[1;32mFrontend Library build verified.\033[0m"
.PHONY: verify-fe-lib
fe-test: base
@echo "\033[1;34mRunning frontend tests.\033[0m"
$(CONTAINER_ENGINE) run $(CPUSET) --name noobaa_$(GIT_COMMIT)_$(NAME_POSTFIX) noobaa-base npm run test --prefix ./frontend
.PHONY: fe-test
# This rule builds a container image that includes developer tools
# which allows to build and debug the project.
nbdev:
$(DOCKER_BUILDKIT) $(CONTAINER_ENGINE) build $(CPUSET) -f src/deploy/NVA_build/dev.Dockerfile $(CACHE_FLAG) -t nbdev --build-arg GIT_COMMIT=$(GIT_COMMIT) . $(REDIRECT_STDOUT)
@echo "\033[1;32mImage 'nbdev' is ready.\033[0m"
@echo "Usage: docker run -it nbdev"
.PHONY: nbdev
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