-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
200 lines (156 loc) · 6.17 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
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
.PHONY: docs coverage fixtures
.SILENT: clean
.PRECIOUS: lint
COMPOSE := docker-compose -f docker-compose.yml -f compose/docker-compose.dev.yml
COMPOSE_TEST := $(COMPOSE) -f compose/docker-compose.test.yml
ARG=
help:
@echo
@echo ----------------------------------------------------------------------
@echo " Development commands file "
@echo ----------------------------------------------------------------------
@echo "> R U N N I N G"
@echo " - build Build the containers for development"
@echo " - up Run & Up development server"
@echo " - superuser Create a super user in the database"
@echo " - clean Stop & Destroy project containers"
@echo " - stop Stop compose runing"
@echo " - restart Restart compose running"
@echo " - clean_volumes Destroy compose projet volumes"
@echo " - show_urls Show available routes"
@echo ----------------------------------------------------------------------
@echo "> D E B U G I N G"
@echo " - debug Run & Up development server with ports for debuging"
@echo " - printenv Show all environmeent variables"
@echo " - settings Show computed django settings"
@echo " - console Open a Django shell console"
@echo " - dbshell Open a Database shell console"
@echo ----------------------------------------------------------------------
@echo "> D A T A B A S E"
@echo " - fixtures Load testing data"
@echo " - dumpdata Generate testing data"
@echo " - migrate Apply unapplied migrations"
@echo " - migrations ARG={app} Create deetected migrations automatically"
@echo " - squashmigrations Squash existent migrations"
@echo " - flushdb Drop database registries"
@echo ----------------------------------------------------------------------
@echo "> T E S T I N G"
@echo " - tests Run tests"
@echo " - selenium Open selenium session to see them with VNC"
@echo " - pytest Run tests with pytest engine"
@echo " - clean_tests Running tests with pytest cleaning cache"
@echo " - coverage_tests Generate the coverage"
@echo " - coverage_report Generate coverage html report"
@echo ----------------------------------------------------------------------
@echo "> L I N T I N G"
@echo " - lint Build the containers for development"
build:
$(COMPOSE) build
@echo "Building..."
up:
@echo "Server up..."
$(COMPOSE) up
run:
$(COMPOSE) run --rm django $(ARG)
debug:
@echo "Launchings Server for debbugging..."
$(COMPOSE) run --service-ports django
loaddata:
@echo "Loading fixtures..."
$(COMPOSE) run --rm django python manage.py loaddata $(ARG)
fixtures:
@echo "Loading fixtures..."
$(COMPOSE) run --rm django python manage.py loaddata users
dumpdata:
@echo "Getting fixtures..."
$(COMPOSE) run --rm django python manage.py dumpdata $(ARG)
superuser:
@echo "Creating superuser..."
$(COMPOSE) run --rm django python manage.py createsuperuser
migrate:
@echo "Applying migrations ..."
$(COMPOSE) run --rm django python manage.py migrate $(ARG)
migrations:
@echo "Creating migrations ..."
$(COMPOSE) run --rm django python manage.py makemigrations $(ARG)
squashmigrations:
@echo "Creating migrations ..."
$(COMPOSE) run --rm django python manage.py squashmigrations $(APP)
settings:
@echo "Opening django compiled settings ..."
$(COMPOSE) run --rm django python manage.py diffsettings
flushdb:
@echo "Flushing database ..."
$(COMPOSE) run --rm django python manage.py flush
# Window version: docker ps -aq | %{docker stop $_}
clean:
@echo "Cleaning containers ..."
docker ps -aq | xargs docker stop
docker ps -aq | xargs docker rm
console:
@echo "Opening django shell for testing and debbugging"
$(COMPOSE) run --rm django python manage.py shell_plus
shell:
@echo "Opening container bash session"
$(COMPOSE) run --rm django bash
dbshell:
@echo "Opening database shell"
$(COMPOSE) run --rm django python manage.py dbshell
stop:
@echo "Stopping containers"
docker ps -qa | xargs docker stop
restart: stop up
@echo "Containers restarted"
clean_volumes:
@echo "Cleaning volumes ..."
docker volume ls -q | grep django-wise | xargs docker volume rm
docker images | grep "^<none>" | awk '{print $3}' | xargs docker rmi
show_urls:
@echo "Show api routes"
$(COMPOSE) run --rm django python manage.py show_urls
selenium:
@echo "Starting selenium..."
$(COMPOSE) start selenium
printenv:
$(COMPOSE) run --rm django python merge_envs.py
@echo "New [.env] file generated"
test:
@echo "Running tests with pytest cleaning cache..."
$(COMPOSE_TEST) run --rm django bash -c "DJANGO_ENV=testing pytest --pyargs $(ARG)"
clean_tests:
$(COMPOSE_TEST) run --rm django pytest -n auto --pyargs --cache-clear
coverage:
$(COMPOSE_TEST) run django coverage run -m pytest
$(COMPOSE_TEST) run --rm django coverage report
$(COMPOSE_TEST) run --rm django coverage html
$(COMPOSE_TEST) run --rm django rm -f web/badges/coverage.svg
$(COMPOSE_TEST) run --rm django coverage-badge -o web/badges/coverage.svg
coverage_tests:
$(COMPOSE_TEST) run django coverage run -m pytest
$(COMPOSE_TEST) run --rm django coverage html
$(COMPOSE_TEST) run --rm django coverage json
lint:
@echo "Verifying the code"
$(COMPOSE) run --rm django flake8 $(ARG)
bash:
@echo "Opening a shell session"
$(COMPOSE) run --rm django sh
isort:
@echo "Opening a shell session"
$(COMPOSE) run --rm django isort .
locales:
@echo "Generate traslations"
$(COMPOSE) run --rm django python manage.py makemessages -l en
$(COMPOSE) run --rm django python manage.py makemessages -l es
compile_locales:
@echo "Compile traslations"
$(COMPOSE) run --rm django python manage.py compilemessages
production_up:
@echo "Server up..."
docker-compose -f docker-compose.yml -f docker-compose.prod.yml up
report_coverage:
@echo "Running coverage report"
cd reports/coverage && python -m SimpleHTTPServer 3000
report_lint:
@echo "Running coverage report"
$(COMPOSE) run --rm django flake8 --format=html && cd reports/flake8 && python -m SimpleHTTPServer 3001