forked from gip-inclusion/les-emplois
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
116 lines (85 loc) · 3.96 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
# Global tasks.
# =============================================================================
.PHONY: run black clean cdsitepackages pylint check_code_quality
# Run a local server.
run:
docker-compose -f docker-compose-dev.yml up
clean:
find . -type d -name "__pycache__" -depth -exec rm -rf '{}' \;
cdsitepackages:
docker exec -ti -w /usr/local/lib/python3.7/site-packages itou_django /bin/bash
black:
docker exec -ti itou_django black itou/
pylint:
docker exec -ti itou_django pylint --rcfile='.pylintrc' --reports=no --output-format=colorized 'itou';
check_code_quality: black pylint
# Django.
# =============================================================================
.PHONY: django_admin populate_db
# make django_admin
# make django_admin COMMAND=dbshell
# make django_admin COMMAND=createsuperuser
# make django_admin COMMAND="dumpdata siaes.Siae" > ~/Desktop/siaes.json
django_admin:
docker exec -ti itou_django django-admin $(COMMAND)
populate_db:
make django_admin COMMAND="import_cities"
make django_admin COMMAND="loaddata itou/fixtures/jobs.json"
make django_admin COMMAND="loaddata itou/fixtures/siaes.json"
make django_admin COMMAND="loaddata itou/fixtures/prescribers.json"
make django_admin COMMAND="loaddata itou/fixtures/test_users.json"
make django_admin COMMAND="loaddata itou/fixtures/prescriber_memberships.json"
make django_admin COMMAND="loaddata itou/fixtures/siae_memberships.json"
# Tests.
# =============================================================================
.PHONY: test
# make test
# make test TARGET=itou.utils
# make test TARGET=itou.utils.tests.UtilsTemplateTagsTestCase.test_url_add_query
test:
docker exec -ti itou_django django-admin test --settings=config.settings.test --noinput --failfast --parallel=2 $(TARGET)
# Docker shell.
# =============================================================================
.PHONY: shell_on_django_container shell_on_django_container_as_root shell_on_postgres_container
shell_on_django_container:
docker exec -ti itou_django /bin/bash
shell_on_django_container_as_root:
docker exec -ti --user root itou_django /bin/bash
shell_on_postgres_container:
docker exec -ti itou_postgres /bin/bash
# Postgres CLI.
# =============================================================================
.PHONY: psql_itou psql_root
# Connect to the `itou` database as the `itou` user.
psql_itou:
docker exec -ti -e PGPASSWORD=password itou_postgres psql -U itou -d itou
# Connect to postgres client as the `root` user.
psql_root:
docker exec -ti -e PGPASSWORD=password itou_postgres psql -U postgres
# Postgres (backup / restore).
# Inspired by:
# https://cookiecutter-django.readthedocs.io/en/latest/docker-postgres-backups.html
# =============================================================================
.PHONY: postgres_backup postgres_backups_cp_locally postgres_backups_list postgres_backup_restore postgres_backups_clean
postgres_backup:
docker-compose -f docker-compose-dev.yml exec postgres backup
postgres_backups_cp_locally:
docker cp itou_postgres:/backups ~/Desktop/backups
postgres_backups_list:
docker-compose -f docker-compose-dev.yml exec postgres backups
# Note: Django must be stopped to avoid a "database "itou" is being accessed by other users" error.
# make postgres_backup_restore FILE=backup_2019_10_08T12_33_00.sql.gz
postgres_backup_restore:
docker-compose -f docker-compose-dev.yml up -d --no-deps postgres && \
docker-compose -f docker-compose-dev.yml exec postgres restore $(FILE) && \
docker-compose -f docker-compose-dev.yml stop
postgres_backups_clean:
docker-compose -f docker-compose-dev.yml exec postgres clean
# Delete and recreate the DB manually.
# =============================================================================
# docker-compose -f docker-compose-dev.yml down
# docker-compose -f docker-compose-dev.yml up --no-deps postgres
# make shell_on_postgres_container
# PGPASSWORD=password psql -h postgres -U postgres
# DROP DATABASE itou;
# CREATE DATABASE itou OWNER itou;