-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmakefile
More file actions
461 lines (297 loc) · 12.1 KB
/
Copy pathmakefile
File metadata and controls
461 lines (297 loc) · 12.1 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
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
.ONESHELL:
.PHONY: build build-pip clean clean-docs clean-make clean-test clean-ui docs-lint prepare-python prepare-ui
.SILENT:
# ANSI Terminal Colours
BLACK := \033[30m
BLACK_BRIGHT := \033[90m
BLUE := \033[34m
BLUE_BRIGHT := \033[94m
CYAN := \033[36m
CYAN_BRIGHT := \033[96m
GREEN := \033[32m
GREEN_BRIGHT := \033[92m
MAGENTA := \033[35m
MAGENTA_BRIGHT := \033[95m
RED := \033[31m
RED_BRIGHT := \033[91m
RESET := \033[0m
WHITE := \033[37m
WHITE_BRIGHT := \033[97m
YELLOW := \033[33m
YELLOW_BRIGHT := \033[93m
# ANSI Terminal Background colours.
BG_BLACK := \033[40m
BG_BLACK_BRIGHT := \033[100m
BG_BLUE := \033[44m
BG_BLUE_BRIGHT := \033[104m
BG_CYAN := \033[46m
BG_CYAN_BRIGHT := \033[106m
BG_GREEN := \033[42m
BG_GREEN_BRIGHT := \033[102m
BG_MAGENTA := \033[45m
BG_MAGENTA_BRIGHT := \033[105m
BG_RED := \033[41m
BG_RED_BRIGHT := \033[101m
# ANSI Terminal Text formatting
BOLD := \033[1m
DIM := \033[2m
ITALIC := \033[3m
UNDERLINE := \033[4m
BLINK := \033[5m
REVERSE := \033[7m
HIDDEN := \033[8m
STRIKETHROUGH := \033[9m
RESET := \033[0m
RESET_BOLD := \033[21m
RESET_DIM := \033[22m
RESET_ITALIC := \033[23m
RESET_UNDERLINE := \033[24m
RESET_BLINK := \033[25m
RESET_REVERSE := \033[27m
RESET_HIDDEN := \033[28m
RESET_STRIKETHROUGH := \033[29m
PATH_VENV := ${PWD}/.venv
ACTIVATE_VENV :=. ${PATH_VENV}/bin/activate
# See dockerfile arg `PYTHON_VERSION` for current version
PYTHON_BIN := python3.11
START_PWD := ${PWD}
WORKDIR := ${PWD}/.tmp
build: prepare-python clean-build
echo "${BLUE}Building Centurion ERP PIP Package${RESET}";
${ACTIVATE_VENV};
python -m build --wheel;
build-pip: prepare-python
echo "${BLUE}Compiling pip files in tools/${RESET}";
${ACTIVATE_VENV};
echo "${BLUE} tools/requirements.in...${RESET}";
pip-compile --upgrade tools/requirements.in -o requirements.txt -vv || echo "${RED} tools/requirements.in FAILED${RESET}";
echo "${BLUE} tools/requirements_production.in...${RESET}";
pip-compile --upgrade requirements.txt tools/requirements_production.in -o requirements_production.txt -vv || echo "${RED} tools/requirements_production.in FAILED${RESET}";
echo "${BLUE} tools/requirements_dev.in...${RESET}";
pip-compile --upgrade requirements.txt requirements_production.txt tools/requirements_dev.in -o requirements_dev.txt -vv || echo "${RED} tools/requirements_dev.in FAILED${RESET}";
echo "${BLUE} tools/requirements_docker.in...${RESET}";
pip-compile --upgrade requirements.txt requirements_production.txt tools/requirements_docker.in -o requirements_docker.txt -vv || echo "${RED} tools/requirements_docker.in FAILED${RESET}";
echo "${BLUE} build-pip complete${RESET}";
check-docker-installed: dir-make-tmp
echo -n "${BLUE}Checking if docker is installed: ${RESET}";
if [ `which docker` ]; then
echo "${GREEN}Yes${RESET}";
touch ${WORKDIR}/DOCKER_IS_INSTALLED;
else
echo "${RED}No${RESET}";
rm -f ${WORKDIR}/DOCKER_IS_INSTALLED;
fi;
check-git-installed: dir-make-tmp
echo -n "${BLUE}Checking if git is installed: ${RESET}";
if [ `which git` ]; then
echo "${GREEN}Yes${RESET}";
touch ${WORKDIR}/GIT_IS_INSTALLED;
else
echo "${RED}No${RESET}";
rm -f ${WORKDIR}/GIT_IS_INSTALLED;
fi;
dir-make-tmp:
echo "${BLUE}Creating temp working directory [${WORKDIR}]: ${RESET}";
mkdir -p ${WORKDIR} || echo "${RED}Failed to create temp working directory. ${RESET}";
docs-lint: check-docker-installed
echo "${BLUE}Lint document files${RESET}";
if [ -f ${WORKDIR}/DOCKER_IS_INSTALLED ]; then
docker run -t --rm \
-e IS_BUILD=1 \
-ti \
--entrypoint "" \
--volume ${PWD}:/workdir \
--workdir /workdir \
nofusscomputing/mkdocs-ci:latest \
markdownlint-cli2 \
docs/*.md \
docs/**/*.md \
docs/**/**/*.md \
docs/**/**/**/*.md \
docs/**/**/**/**/**/*.md \
!CHANGELOG.md \
!docs/pull_request_template.md\
!docs-template \
!.venv \
|| echo " ${RED}Check above for errors${RESET}";
else
echo " ${YELLOW}No linting will occur as docker is not installed${RESET}";
fi;
fixtures: prepare-python
${ACTIVATE_VENV}
mv app/db.sqlite3 app/db.sqlite3-current
if [ ! -f app/db.sqlite3-current ]; then echo "failed to save current db"; exit 1; fi;
python app/manage.py migrate;
python app/manage.py dumpdata \
--natural-foreign \
--natural-primary \
--exclude=contenttypes \
--exclude=auth.permission \
--exclude=access.centurionuser \
--exclude=settings.usersettings \
--indent 2 > app/fixtures/fresh_db.json;
sqlite3 app/db.sqlite3 .dump | \
grep -a -v 'INSERT INTO django_migrations' | \
grep -a -v 'INSERT INTO django_content_type' | \
grep -a -v 'INSERT INTO auth_permission' | \
grep -a -v 'INSERT INTO settings_appsettings' | \
grep -a -v 'INSERT INTO access_centurionuser' | \
grep -a -v 'INSERT INTO settings_usersettings' | \
grep -a -v 'CREATE UNIQUE INDEX' | \
grep -a -v 'CREATE INDEX' \
> app/fixtures/fresh_db.sql;
rm -f app/db.sqlite3
if [ ! -f app/db.sqlite3 ]; then cp app/db.sqlite3-current app/db.sqlite3; fi;
if [ -f app/db.sqlite3 ]; then rm -f app/db.sqlite3-current; fi;
pip: prepare-python
echo "${BLUE}Syncing Python packages from repository requirements._dev.txt to Virtual Environment...${RESET}";
${ACTIVATE_VENV};
pip-sync requirements_dev.txt -vv;
echo "${BLUE} pip complete.${RESET}";
prepare-python:
echo "${BLUE}Checking for Python Virtual Environment...${RESET}";
if [ ! -f ${PATH_VENV}/bin/activate ]; then
echo " ${BLUE}Setting up Python Virtual Environment...${RESET}";
${PYTHON_BIN} -m venv ${PATH_VENV} || echo "${RED}Failed to create Virtual Environment. ${RESET}";
echo " ${BLUE}Activating Python Virtual Environment...${RESET}";
${ACTIVATE_VENV} || echo "${RED}Failed to activate Virtual Environment. ${RESET}";
echo " ${BLUE}Installing Python dependencies in Virtual Environment...${RESET}";
pip install -r requirements_dev.txt || echo "${RED}Failed to install Python Dependencies in Virtual Environment. ${RESET}";
else
echo " ${GREEN}Python Virtual Environment already setup. Nothing to do.${RESET}";
fi;
echo " ${BLUE}prepare-python complete.${RESET}";
prepare-ui: check-git-installed
echo "${BLUE}Preparing Centurion UI...${RESET}";
if [ -f ${WORKDIR}/GIT_IS_INSTALLED ]; then
echo -n " ${BLUE}Centurion UI already cloned: ${RESET}";
if [ ! -d ${WORKDIR}/centurion-ui/.git ]; then
echo "${YELLOW}No${RESET}";
echo " ${BLUE}Cloning...${RESET}";
git clone https://github.com/nofusscomputing/centurion_erp_ui.git ${WORKDIR}/centurion-ui \
|| echo " ${RED}Check above for errors${RESET}";
else
echo "${GREEN}Yes${RESET}";
fi;
echo " ${BLUE}prepare-ui complete.${RESET}";
echo "${MAGENTA}To activate the ui, do the following:${RESET}";
echo " ${CYAN_BRIGHT}1. cd ${WORKDIR}/centurion-ui${RESET}";
echo " ${CYAN_BRIGHT}2. run npm start${RESET}";
echo " ${CYAN_BRIGHT}3. UI can be viewed at http://127.0.0.1:3000/${RESET}";
else
echo " ${YELLOW}Unable to prepare the UI as git is not installed${RESET}";
fi;
test:
pytest --cov-report xml:artifacts/coverage_unit_functional.xml --cov-report html:artifacts/coverage/unit_functional/ --junit-xml=artifacts/unit_functional.JUnit.xml app/**/tests/unit app/**/tests/functional
#
# Do not make this user friendly. This primarily exists for CI jobs.
# It can be run locally, however ensure that the venv as been activated prior
# to running this target
#
test-integration:
export exit_code=0;
cp pyproject.toml app/;
sed -i 's|^source = \[ "./app" \]|source = [ "." ]|' app/pyproject.toml;
cp -f requirements_dev.txt test/requirements_dev.txt;
cd "${START_PWD}/test";
if [ ! -n "$CENTURION_IMAGE_TAG" ]; then
export CENTURION_IMAGE_TAG=$$(git log -1 --format=%H);
fi
if docker-compose up -d; then
docker ps -a;
chmod +x setup-integration.sh;
if [ "0${GITHUB_SHA}"!="0" ]; then
sudo chmod 777 -R "${START_PWD}/test"
fi;
if ./setup-integration.sh; then
cd "${START_PWD}";
ls -laR test/;
docker exec -i centurion-erp sh -c 'rm -rf /app/artifacts/* /app/artifacts/.[!.]*';
sleep 60;
docker ps -a;
curl --trace-ascii - http://localhost:8003/api;
echo '--------------------------------------------------------------------';
curl --trace-ascii - http://127.0.0.1:8003/api;
docker logs centurion-erp;
echo 'Starting integration tests.';
pytest --override-ini addopts= --no-migrations --reuse-db --tb=long --verbosity=2 --showlocals --junit-xml="${START_PWD}/integration.JUnit.xml" app/*/tests/integration;
echo 'Creating Coverage reports.';
docker exec -i centurion-erp sh -c 'coverage combine; coverage report --skip-covered; coverage html -d artifacts/html/;';
else
cd "${START_PWD}";
ls -la;
echo 'Error: could not setup containers for testing';
echo '';
echo '';
ls -lar "${START_PWD}/test";
echo '';
docker ps -a;
docker logs centurion-erp-init > "${START_PWD}/test/volumes/log/docker-log-centurion-erp-init.log";
docker logs centurion-erp> "${START_PWD}/test/volumes/log/docker-log-centurion-erp.log";
docker logs postgres > "${START_PWD}/test/volumes/log/docker-log-postgres.log";
docker exec -i postgres psql -Uadmin -c "\l" > "${START_PWD}/test/volumes/log/postgres-database.log";
docker exec -i postgres psql -Uadmin -d itsm -c "\dt" > "${START_PWD}/test/volumes/log/postgres-tables.log";
docker logs rabbitmq > "${START_PWD}/test/volumes/log/docker-log-rabbitmq.log";
export exit_code=10;
fi;
else
cd "${START_PWD}";
if [ "0${GITHUB_SHA}"!="0" ]; then
sudo chmod 777 -R "${START_PWD}/test"
fi;
echo 'Error: Failed to launch containers.';
echo '';
echo '';
ls -lar "${START_PWD}/test";
echo '';
docker ps -a;
docker logs centurion-erp-init > "${START_PWD}/test/volumes/log/docker-log-centurion-erp-init.log";
docker logs centurion-erp> "${START_PWD}/test/volumes/log/docker-log-centurion-erp.log";
docker logs postgres > "${START_PWD}/test/volumes/log/docker-log-postgres.log";
docker exec -i postgres psql -Uadmin -c "\l" > "${START_PWD}/test/volumes/log/postgres-database.log";
docker exec -i postgres psql -Uadmin -d itsm -c "\dt" > "${START_PWD}/test/volumes/log/postgres-tables.log";
docker logs rabbitmq > "${START_PWD}/test/volumes/log/docker-log-rabbitmq.log";
export exit_code=20;
fi;
if [ "0${GITHUB_SHA}"!="0" ]; then
sudo chmod 777 -R "${START_PWD}/test"
fi;
echo '';
docker ps -a;
docker logs centurion-erp-init > "${START_PWD}/test/volumes/log/docker-log-centurion-erp-init.log";
docker logs centurion-erp> "${START_PWD}/test/volumes/log/docker-log-centurion-erp.log";
docker logs postgres > "${START_PWD}/test/volumes/log/docker-log-postgres.log";
docker exec -i postgres psql -Uadmin -c "\l" > "${START_PWD}/test/volumes/log/postgres-database.log";
docker exec -i postgres psql -Uadmin -d itsm -c "\dt" > "${START_PWD}/test/volumes/log/postgres-tables.log";
docker logs rabbitmq > "${START_PWD}/test/volumes/log/docker-log-rabbitmq.log";
export exit_code=0;
cd "${START_PWD}/test";
rm -f requirements_dev.txt;
echo 'REmoving containers.';
docker-compose down -v;
cd "${START_PWD}";
exit ${exit_code};
test-functional:
pytest --cov-report xml:${PWD}/artifacts/coverage_functional.xml --cov-report html:${PWD}/artifacts/coverage/functional/ --junit-xml=${PWD}/artifacts/functional.JUnit.xml app/**/tests/functional
test-unit:
pytest --cov-report xml:${PWD}/artifacts/coverage_unit.xml --cov-report html:${PWD}/artifacts/coverage/unit/ --junit-xml=${PWD}/artifacts/unit.JUnit.xml app/**/tests/unit
clean-build:
echo "${BLUE}Cleaning build${RESET}";
rm -rf *.egg-info/;
rm -rf dist/;
clean-docs:
echo "${BLUE}Cleaning docs${RESET}";
rm -rf pages;
rm -rf build;
clean-make:
echo "${BLUE}Cleaning make temp dir${RESET}";
rm -rf ${PWD}/.tmp;
clean-test:
echo "${BLUE}Cleaning tests${RESET}";
rm -rf artifacts;
rm -rf .pytest_cache;
clean-ui:
echo "${BLUE}Cleaning UI${RESET}";
rm -rf ${WORKDIR}/centurion-ui;
clean: clean-docs clean-make clean-test clean-ui
echo "${BLUE}Full Clean complete${RESET}";