forked from libre-man/eJournal
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
240 lines (184 loc) · 7.63 KB
/
Copy pathMakefile
File metadata and controls
240 lines (184 loc) · 7.63 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
ifdef test
TOTEST=-k ${test}
else
TOTEST=
endif
ifeq (,$(wildcard ./pass.txt))
ansible_use = --ask-vault-pass
else
ansible_use = --vault-password-file pass.txt
endif
ifdef no_become
become =
else
become = --ask-become-pass
endif
ifndef branch
branch=`git rev-parse --abbrev-ref HEAD`
endif
ifndef host
host=staging
endif
vars = --extra-vars "git_branch=${branch} deploy_host=${host}"
postgres_db = ejournal
postgres_test_db = test_$(postgres_db)
postgres_dev_user = ejournal
postgres_dev_user_pass = password
##### TEST COMMANDS #####
test-back:
pep8 ./src/django --max-line-length=120 --exclude='./src/django/VLE/migrations','./src/django/VLE/settings*'
bash -c 'source ./venv/bin/activate && flake8 --max-line-length=120 src/django --exclude="src/django/VLE/migrations/*","src/django/VLE/settings/*","src/django/VLE/settings.py","src/django/VLE/tasks/__init__.py" && deactivate'
bash -c "source ./venv/bin/activate && pytest -n auto --cov=VLE --cov-config .coveragerc src/django/test ${TOTEST} && deactivate"
bash -c 'source ./venv/bin/activate && isort -rc src/django/ && deactivate'
test-front:
npm run lint --prefix ./src/vue
display-coverage:
bash -c "source ./venv/bin/activate && cd src/django/ && coverage report -m && deactivate"
test: test-front test-back
run-test:
bash -c 'source ./venv/bin/activate && cd ./src/django && python manage.py test test.test_$(arg)'
##### DEVELOP COMMANDS #####
run-front:
bash -c "source ./venv/bin/activate && npm run serve --prefix ./src/vue && deactivate"
run-back: isort
bash -c "source ./venv/bin/activate && python ./src/django/manage.py runserver && deactivate"
isort:
bash -c 'source ./venv/bin/activate && isort -rc src/django/ && deactivate'
setup:
@echo "This operation will clean old files, press enter to continue (ctrl+c to cancel)"
@read -r a
make setup-no-input
setup-no-input:
@make clean
# Install apt dependencies and ppa's.
(sudo apt-cache show python3.6 | grep "Package: python3.6") || \
(sudo add-apt-repository ppa:deadsnakes/ppa -y; sudo apt update) || echo "0"
sudo apt install npm -y
sudo npm install npm@latest -g
sudo apt install nodejs python3 python3-pip pep8 libpq-dev python3-dev postgresql postgresql-contrib rabbitmq-server python3-setuptools -y
make setup-venv requirements_file=local.txt
# Reinstall nodejs dependencies.
npm ci --prefix ./src/vue
make preset-db-no-input
bash -c 'source ./venv/bin/activate && cd ./src/django && python manage.py migrate django_celery_results && deactivate'
@echo "DONE!"
setup-travis:
(sudo apt-cache show python3.6 | grep "Package: python3.6") || (sudo add-apt-repository ppa:deadsnakes/ppa -y; sudo apt update) || echo "0"
sudo apt install npm -y
sudo apt install nodejs python3 python3-pip pep8 python3-setuptools -y
sudo pip3 install virtualenv
virtualenv -p python3 venv
bash -c 'source ./venv/bin/activate && pip install -r requirements/ci.txt && deactivate'
# Reinstall nodejs dependencies.
npm ci --prefix ./src/vue
@echo "DONE!"
setup-venv:
sudo pip3 install virtualenv
virtualenv -p python3 venv
bash -c '\
source ./venv/bin/activate && \
pip install -r requirements/$(requirements_file) && \
isort -rc src/django/ && \
ansible-playbook ./config/provision-local.yml --ask-become-pass --ask-vault-pass && \
deactivate'
##### DEPLOY COMMANDS ######
ansible-test-connection:
bash -c 'source ./venv/bin/activate && \
ansible -m ping all ${become}'
run-ansible-provision:
bash -c 'source ./venv/bin/activate && \
ansible-playbook config/provision-servers.yml ${become} ${ansible_use} ${vars}'
run-ansible-deploy:
bash -c 'source ./venv/bin/activate && \
ansible-playbook config/provision-servers.yml ${become} ${ansible_use} ${vars} --tags "deploy_front,deploy_back"'
run-ansible-deploy-front:
bash -c 'source ./venv/bin/activate && \
ansible-playbook config/provision-servers.yml ${become} ${ansible_use} ${vars} --tags "deploy_front"'
run-ansible-deploy-back:
bash -c 'source ./venv/bin/activate && \
ansible-playbook config/provision-servers.yml ${become} ${ansible_use} ${vars} --tags "deploy_back"'
run-ansible-backup:
bash -c 'source ./venv/bin/activate && \
ansible-playbook config/provision-servers.yml ${become} ${ansible_use} ${vars} --tags "backup"'
run-ansible-preset_db:
bash -c 'source ./venv/bin/activate && \
ansible-playbook config/provision-servers.yml ${become} ${ansible_use} ${vars} --tags "run_preset_db"'
##### MAKEFILE COMMANDS #####
default:
make setup-no-input
make test
clean:
rm -rf ./venv
rm -rf ./src/vue/node_modules
@if [ $(shell id "postgres" > /dev/null 2>&1; echo $$?) -eq 0 ]; then \
make postgres-reset; \
fi
##### DATABSE COMMANDS #####
postgres-reset:
@sudo su -c "psql \
-c \"DROP DATABASE IF EXISTS $(postgres_db)\" \
-c \"DROP DATABASE IF EXISTS test_$(postgres_db)\" \
-c \"DROP USER IF EXISTS $(postgres_dev_user)\" \
" postgres
postgres-drop-development-db:
@sudo su -c "psql -c \"DROP DATABASE IF EXISTS $(postgres_db)\"" postgres
postgres-init-development:
@sudo su -c "psql \
-c \"CREATE DATABASE $(postgres_db)\" \
-c \"CREATE USER $(postgres_dev_user) WITH PASSWORD '$(postgres_dev_user_pass)'\" \
-c \"ALTER ROLE $(postgres_dev_user) CREATEDB\" \
-c \"ALTER ROLE $(postgres_dev_user) SET client_encoding TO 'utf8'\" \
-c \"ALTER ROLE $(postgres_dev_user) SET default_transaction_isolation TO 'read committed'\" \
-c \"ALTER ROLE $(postgres_dev_user) SET timezone TO 'CET'\" \
-c \"GRANT ALL PRIVILEGES ON DATABASE $(postgres_db) TO $(postgres_dev_user)\" \
-c \"alter role $(postgres_dev_user) superuser\" \
" postgres
preset-db:
@echo "This operation will wipe the $(postgres_db) database, press enter to continue (ctrl+c to cancel)"
@read -r a
make preset-db-no-input
preset-db-no-input:
rm -rf src/django/media/*
make postgres-reset
make postgres-init-development
make migrate-back
bash -c 'source ./venv/bin/activate && cd ./src/django && python manage.py preset_db && deactivate'
migrate-back:
bash -c "source ./venv/bin/activate && cd ./src/django && python manage.py makemigrations VLE && python manage.py migrate && deactivate"
migrate-merge:
bash -c "source ./venv/bin/activate && cd ./src/django && python manage.py makemigrations --merge"
db-dump:
@pg_dump --dbname=postgresql://$(postgres_dev_user):$(postgres_dev_user_pass)@127.0.0.1:5432/$(dbname) > db.dump
@echo dump to file: db.dump success!
db-restore:
@echo "This operation will wipe and then restore the $(postgres_db) database from db.dump, press enter to continue (ctrl+c to cancel)"
@read -r a
@sudo su -c "psql \
-c \"DROP DATABASE IF EXISTS $(postgres_db)\" \
-c \"DROP DATABASE IF EXISTS test_$(postgres_db)\" \
-c \"CREATE DATABASE $(postgres_db)\" \
" postgres
@psql --dbname=postgresql://$(postgres_dev_user):$(postgres_dev_user_pass)@127.0.0.1:5432/$(dbname) < db.dump
##### MISC COMMANDS #####
superuser:
bash -c 'source ./venv/bin/activate && python src/django/manage.py createsuperuser && deactivate'
update-dependencies:
npm update --dev --prefix ./src/vue
npm install --prefix ./src/vue
fix-npm:
npm cache clean -f
npm config set strict-ssl false
sudo npm install -g n
npm config set strict-ssl true
sudo n stable
fix-live-reload: SHELL:=/bin/bash
fix-live-reload:
@bash -c '\
echo $$(( `sudo cat /proc/sys/fs/inotify/max_user_watches` * 2 )) | \
sudo tee /proc/sys/fs/inotify/max_user_watches'
shell:
bash -c 'source ./venv/bin/activate && cd ./src/django && python manage.py shell'
run-celery-worker-and-beat:
bash -c 'sudo rabbitmqctl purge_queue celery && source ./venv/bin/activate && cd ./src/django && celery -A VLE worker -l info -B'
encrypt_vault_var:
bash -c 'source ./venv/bin/activate && ansible-vault encrypt_string "${inp}" --vault-password-file ./pass.txt'