-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMakefile
163 lines (133 loc) · 3.63 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
# Loading environment variables
ifneq (,$(wildcard ./.env))
include .env
export
endif
# Aliases
PYTHON := .venv/bin/python
DJANGO_ADMIN := $(PYTHON) manage.py
PYTEST := $(PYTHON) -m pytest
DB_URL := postgres://qfdmo:qfdmo@localhost:6543/qfdmo # pragma: allowlist secret
# Makefile config
.PHONY: check
check:
@source .venv/bin/activate; python --version; pip --version
@npm --version
@node --version
# Setup development environment
.PHONY: update-requirements
update-requirements:
$(PYTHON) -m pip install --no-deps -r requirements.txt -r dev-requirements.txt
.PHONY: init-venv
init-venv:
python -m venv .venv --prompt $(basename $(CURDIR)) --clear
.PHONY: init-dev
init-dev:
# git
git config blame.ignoreRevsFile .git-blame-ignore-revs
pre-commit install
# python
make init-venv
$(PYTHON) -m pip install pip-tools
$(PYTHON) -m pip install --no-deps -r requirements.txt -r dev-requirements.txt
# javascript
npm install
npx playwright install --with-deps
# environment
cp .env.template .env
cp ./dags/.env.template ./dags/.env
# prepare django
make migrate
make createcachetable
make createsuperuser
.PHONY: fix
fix:
$(PYTHON) -m ruff check . --fix
$(PYTHON) -m black --exclude=.venv .
# Run development servers
.PHONY: run-airflow
run-airflow:
docker compose --profile airflow up -d
.PHONY: run-django
run-django:
rm -rf .parcel-cache
honcho start -f Procfile.dev
run-all:
docker compose --profile airflow up -d
rm -rf .parcel-cache
$(DJANGO_ADMIN) runserver 0.0.0.0:8000
npm run watch
# Local django operations
.PHONY: migrate
migrate:
$(DJANGO_ADMIN) migrate
.PHONY: makemigrations
makemigrations:
$(DJANGO_ADMIN) makemigrations
.PHONY: merge-migrations
merge-migrations:
$(DJANGO_ADMIN) makemigrations --merge
.PHONY: createcachetable
createcachetable:
$(DJANGO_ADMIN) createcachetable
.PHONY: createsuperuser
createsuperuser:
$(DJANGO_ADMIN) createsuperuser
.PHONY: seed-database
seed-database:
$(DJANGO_ADMIN) loaddata categories actions acteur_services acteur_types acteurs objets
.PHONY: drop-db
drop-db:
docker compose exec lvao-db dropdb -f -i -U qfdmo -e qfdmo
.PHONY: create-db
create-db:
docker compose exec lvao-db createdb -U qfdmo -e qfdmo
.PHONY: restore-prod
restore-prod:
./scripts/restore_prod_locally.sh
.PHONY: clear-cache
clear-cache:
$(DJANGO_ADMIN) clear_cache --all
# Dependencies management
.PHONY: pip-update
pip-update:
$(PYTHON) -m pip-compile dev-requirements.in --generate-hashes
$(PYTHON) -m pip-compile requirements.in --generate-hashes
.PHONY: npm-upgrade
npm-upgrade:
npx npm-upgrade
# Happy testing
.PHONY: unit-test
unit-test:
$(PYTEST) ./unit_tests
.PHONY: e2e-test
e2e-test:
npx playwright test
$(PYTEST) ./integration_tests
.PHONY: js-test
js-test:
npm run test
.PHONY: test
test:
@make unit-test
@make e2e-test
# DSFR
.PHONY: extract-dsfr
extract-dsfr:
$(PYTHON) ./dsfr_hacks/extract_dsfr_colors.py
$(PYTHON) ./dsfr_hacks/extract_used_colors.py
$(PYTHON) ./dsfr_hacks/extract_used_icons.py
# RESTORE DB LOCALLY
.PHONY: db-restore
db-restore:
mkdir -p tmpbackup
scalingo --app quefairedemesobjets --addon postgresql backups-download --output tmpbackup/backup.tar.gz
tar xfz tmpbackup/backup.tar.gz --directory tmpbackup
@DUMP_FILE=$$(find tmpbackup -type f -name "*.pgsql" -print -quit); \
for table in $$(psql "$(DB_URL)" -t -c "SELECT tablename FROM pg_tables WHERE schemaname='public'"); do \
psql "$(DB_URL)" -c "DROP TABLE IF EXISTS $$table CASCADE"; \
done || true
@DUMP_FILE=$$(find tmpbackup -type f -name "*.pgsql" -print -quit); \
pg_restore -d "$(DB_URL)" --clean --no-acl --no-owner --no-privileges "$$DUMP_FILE" || true
rm -rf tmpbackup
$(DJANGO_ADMIN) migrate