-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
217 lines (159 loc) · 7.16 KB
/
makefile
File metadata and controls
217 lines (159 loc) · 7.16 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
.ONESHELL:
PATH_VENV := /tmp/centurion_erp
ACTIVATE_VENV :=. ${PATH_VENV}/bin/activate
START_PWD := ${PWD}
.PHONY: clean prepare docs ansible-lint lint test
prepare-git-submodule:
git submodule update --init;
git submodule foreach git submodule update --init;
prepare-python: prepare-git-submodule
python3 -m venv ${PATH_VENV};
${ACTIVATE_VENV};
pip install -r requirements_dev.txt;
prepare-docs: prepare-git-submodule
npm install markdownlint-cli2;
npm install markdownlint-cli2-formatter-junit;
cp -f "website-template/.markdownlint.json" ".markdownlint.json";
cp -f "gitlab-ci/lint/.markdownlint-cli2.jsonc" ".markdownlint-cli2.jsonc";
markdown-mkdocs-lint: prepare-docs
PATH=${PATH}:node_modules/.bin markdownlint-cli2 docs/*.md docs/**/*.md docs/**/**/*.md docs/**/**/**/*.md docs/**/**/**/**/**/*.md !docs/pull_request_template.md !CHANGELOG.md !gitlab-ci !website-template || true
docs-lint: markdown-mkdocs-lint
docs: docs-lint
${ACTIVATE_VENV}
mkdocs build --clean
fixtures:
${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;
lint: markdown-mkdocs-lint
pip-file:
pip-compile --upgrade tools/requirements.in -o requirements.txt -vv
pip-compile --upgrade requirements.txt tools/requirements_production.in -o requirements_production.txt -vv
pip-compile --upgrade requirements.txt requirements_production.txt tools/requirements_dev.in -o requirements_dev.txt -vv
pip-compile --upgrade requirements.txt requirements_production.txt tools/requirements_docker.in -o requirements_docker.txt -vv
pip:
pip-sync requirements_dev.txt -vv
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
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/;
echo 'Stoping Gunicorn.';
docker exec -i centurion-erp supervisorctl stop gunicorn;
echo 'Cleaning artifacts dir.';
docker exec -i centurion-erp sh -c 'rm -rf /app/artifacts/* /app/artifacts/.[!.]*';
echo 'Starting Gunicorn.';
docker exec -i centurion-erp supervisorctl start gunicorn;
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 'Restarting Gunicorn.';
docker exec -i centurion-erp supervisorctl restart gunicorn;
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;
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:
rm -rf ${PATH_VENV}
rm -rf artifacts
rm -rf pages
rm -rf build
rm -rf node_modules
rm -f package-lock.json
rm -f package.json
rm -rf .pytest_cache