forked from Nitrate/Nitrate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
117 lines (96 loc) · 3.34 KB
/
Copy pathMakefile
File metadata and controls
117 lines (96 loc) · 3.34 KB
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
.PHONY: sdist
sdist: # Build source distribution package.
@python3 -m build --sdist
ifeq ($(strip $(DB)),)
DB_ENVS=NITRATE_DB_ENGINE=sqlite
else ifeq ($(strip $(DB)), sqlite)
DB_ENVS=NITRATE_DB_ENGINE=sqlite
else ifeq ($(strip $(DB)), mysql)
DB_ENVS=NITRATE_DB_ENGINE=mysql NITRATE_DB_NAME=nitrate
else ifeq ($(strip $(DB)), pgsql)
DB_ENVS=NITRATE_DB_ENGINE=pgsql NITRATE_DB_NAME=nitrate NITRATE_DB_USER=postgres
else
$(error Unknown DB engine $(DB). Available choices are sqlite, mysql, pgsql)
endif
MANAGE_PY=./src/manage.py
.PHONY: runserver
runserver: # Run local Django development server.
@if [ "$(DB)" == "mysql" ]; then \
mysql -uroot -e "CREATE DATABASE IF NOT EXISTS nitrate CHARACTER SET utf8mb4;"; \
elif [ "$(DB)" == "pgsql" ]; then \
psql -U postgres -c "CREATE DATABASE nitrate" || :; \
fi
$(DB_ENVS) $(MANAGE_PY) runserver $(args)
.PHONY: db_envs
db_envs: # Print environment variables for a specific database engine set by DB.
@for env in $(DB_ENVS); do \
echo "export $$env"; \
done
.PHONY: format-code
format-code: # Format Python code with black.
@black --line-length $(shell grep "^max_line_length" tox.ini | cut -d' ' -f3) src/tcms tests
ifeq ($(strip $(detach)),yes)
detach_opt=-d
else
detach_opt=
endif
db_engine ?=
common_health_options = --health-interval=5s --health-timeout=2s --health-retries=3
mariadb_image = mariadb:10.11.8@sha256:75f6e61397758489d1dccf95db33b6b49ebfc7ec1253d40060fdf8ceb7f938a3
mysql_image = mysql:8.0.22@sha256:0fd2898dc1c946b34dceaccc3b80d38b1049285c1dab70df7480de62265d6213
postgres_image = postgres:16.3@sha256:0aafd2ae7e6c391f39fb6b7621632d79f54068faebc726caf469e87bd1d301c0
# MariaDB setup for testenv
.PHONY: start-testdb-mariadb
start-testdb-mariadb:
podman run --rm $(detach_opt) \
--name=testdb-mariadb \
-p 33061:3306 \
-e MYSQL_ROOT_PASSWORD=pass \
--health-cmd="mysqladmin ping -uroot -ppass" \
$(common_health_options) \
$(mariadb_image)
.PHONY: stop-testdb-mariadb
stop-testdb-mariadb:
podman stop testdb-mariadb || :
# MySQL setup for testenv
.PHONY: start-testdb-mysql
start-testdb-mysql:
podman run --rm $(detach_opt) \
--name=testdb-mysql \
-p 33062:3306 \
-e MYSQL_ROOT_PASSWORD=pass \
--health-cmd="mysqladmin ping -uroot -ppass" \
$(common_health_options) \
$(mysql_image)
.PHONY: stop-testdb-mysql
stop-testdb-mysql:
podman stop testdb-mysql || :
# PostgreSQL setup for testenv
.PHONY: start-testdb-postgres
start-testdb-postgres:
podman run --rm $(detach_opt) \
--name=testdb-postgres \
-p 54321:5432 \
-e POSTGRES_PASSWORD=pass \
--health-cmd="PGPASSWORD=pass psql -h 127.0.0.1 -U postgres -c 'SELECT 1'" \
$(common_health_options) \
$(postgres_image)
.PHONY: stop-testdb-postgres
stop-testdb-postgres:
podman stop testdb-postgres || :
.PHONY: check-testdb-health
check-testdb-health:
@retries=10; for i in $$(seq 1 $$retries); do \
health_status=$$(podman inspect testdb-$(db_engine) | jq -r '.[].State.Health.Status'); \
[ "x$$health_status" = "xhealthy" ] && break; \
if [ $$i -gt $$retries ]; then \
echo "testdb $(db_engine) container is not healthy. Seems failed to start." >&2; \
echo "container inspect:" >&2; \
podman inspect testdb-$(db_engine) | jq '.[].State' >&2; \
exit 1; \
else \
echo "Sleep 2s then have another health check" >&2; \
sleep 2s; \
fi; \
done; \
echo "Test database $(db_engine) is healthy."