forked from MTES-MCT/qualicharge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
153 lines (124 loc) · 5.13 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
# -- General
SHELL := /bin/bash
# -- Docker
COMPOSE = bin/compose
COMPOSE_RUN = $(COMPOSE) run --rm --no-deps
COMPOSE_RUN_API = $(COMPOSE_RUN) api
COMPOSE_RUN_API_PIPENV = $(COMPOSE_RUN_API) pipenv run
# -- Tools
CURL = $(COMPOSE_RUN) curl
# -- Ressources
IRVE_STATIC_DATASET_URL = https://www.data.gouv.fr/fr/datasets/r/eb76d20a-8501-400e-b336-d85724de5435
AFIREV_CHARGING_DATASET_URL = https://afirev.fr/en/liste-des-identifiants-attribues/
# ==============================================================================
# RULES
default: help
# -- Files
data:
mkdir data
data/irve-statique.csv: data
$(CURL) -L -o /work/data/irve-statique.csv $(IRVE_STATIC_DATASET_URL)
data/afirev-charging.csv: data
@echo "You should download CSV file from $(AFIREV_CHARGING_DATASET_URL)"
# -- Docker/compose
bootstrap: ## bootstrap the project for development
bootstrap: \
data/irve-statique.csv \
build \
migrate-api \
create-api-test-db \
seed-oidc \
create-superuser
.PHONY: bootstrap
build: ## build the app container(s)
$(COMPOSE) build
.PHONY: build
down: ## stop and remove all containers
@$(COMPOSE) down
.PHONY: down
logs: ## display all services logs (follow mode)
@$(COMPOSE) logs -f
.PHONY: logs
logs-api: ## display API server logs (follow mode)
@$(COMPOSE) logs -f api
.PHONY: logs-api
run: ## run the whole stack
$(COMPOSE) up -d
.PHONY: run
status: ## an alias for "docker compose ps"
@$(COMPOSE) ps
.PHONY: status
stop: ## stop all servers
@$(COMPOSE) stop
.PHONY: stop
# -- Provisioning
create-api-test-db: ## create API test database
@echo "Creating api service test database…"
@$(COMPOSE) exec postgresql bash -c 'psql "postgresql://$${POSTGRES_USER}:$${POSTGRES_PASSWORD}@$${QUALICHARGE_DB_HOST}:$${QUALICHARGE_DB_PORT}/postgres" -c "create database \"$${QUALICHARGE_TEST_DB_NAME}\";"' || echo "Duly noted, skipping database creation."
@$(COMPOSE) exec postgresql bash -c 'psql "postgresql://$${POSTGRES_USER}:$${POSTGRES_PASSWORD}@$${QUALICHARGE_DB_HOST}:$${QUALICHARGE_DB_PORT}/$${QUALICHARGE_TEST_DB_NAME}" -c "create extension postgis;"' || echo "Duly noted, skipping extension creation."
.PHONY: create-api-test-db
drop-api-test-db: ## drop API test database
@echo "Droping api service test database…"
@$(COMPOSE) exec postgresql bash -c 'psql "postgresql://$${POSTGRES_USER}:$${POSTGRES_PASSWORD}@$${QUALICHARGE_DB_HOST}:$${QUALICHARGE_DB_PORT}/postgres" -c "drop database \"$${QUALICHARGE_TEST_DB_NAME}\";"' || echo "Duly noted, skipping database deletion."
.PHONY: drop-api-test-db
drop-api-db: ## drop API database
@echo "Droping api service database…"
@$(COMPOSE) exec postgresql bash -c 'psql "postgresql://$${POSTGRES_USER}:$${POSTGRES_PASSWORD}@$${QUALICHARGE_DB_HOST}:$${QUALICHARGE_DB_PORT}/postgres" -c "drop database \"$${QUALICHARGE_DB_NAME}\";"' || echo "Duly noted, skipping database deletion."
.PHONY: drop-api-db
migrate-api: ## run alembic database migrations for the api service
@echo "Running api service database engine…"
@$(COMPOSE) up -d --wait postgresql
@echo "Creating api service database…"
@$(COMPOSE) exec postgresql bash -c 'psql "postgresql://$${POSTGRES_USER}:$${POSTGRES_PASSWORD}@$${QUALICHARGE_DB_HOST}:$${QUALICHARGE_DB_PORT}/postgres" -c "create database \"$${QUALICHARGE_DB_NAME}\";"' || echo "Duly noted, skipping database creation."
@$(COMPOSE) exec postgresql bash -c 'psql "postgresql://$${POSTGRES_USER}:$${POSTGRES_PASSWORD}@$${QUALICHARGE_DB_HOST}:$${QUALICHARGE_DB_PORT}/$${QUALICHARGE_DB_NAME}" -c "create extension postgis;"' || echo "Duly noted, skipping extension creation."
@echo "Running migrations for api service…"
@bin/alembic upgrade head
.PHONY: migrate-api
create-superuser: ## create super user
@echo "Creating super user…"
@$(COMPOSE_RUN_API_PIPENV) python -m qualicharge create-user \
--username admin \
--email [email protected] \
--password admin \
--is-active \
--is-superuser \
--is-staff \
--force
.PHONY: create-superuser
seed-oidc: ## seed the OIDC provider
@echo 'Starting OIDC provider…'
@$(COMPOSE) up -d keycloak
@$(COMPOSE_RUN) dockerize -wait http://keycloak:8080 -timeout 60s
@echo 'Seeding OIDC client…'
@$(COMPOSE) exec keycloak /usr/local/bin/kc-init
.PHONY: seed-oidc
# -- API
lint: ## lint api python sources
lint: \
lint-black \
lint-ruff \
lint-mypy
.PHONY: lint
lint-black: ## lint api python sources with black
@echo 'lint:black started…'
@$(COMPOSE_RUN_API_PIPENV) black qualicharge tests
.PHONY: lint-black
lint-ruff: ## lint api python sources with ruff
@echo 'lint:ruff started…'
@$(COMPOSE_RUN_API_PIPENV) ruff check qualicharge tests
.PHONY: lint-ruff
lint-ruff-fix: ## lint and fix api python sources with ruff
@echo 'lint:ruff-fix started…'
@$(COMPOSE_RUN_API_PIPENV) ruff check --fix qualicharge tests
.PHONY: lint-ruff-fix
lint-mypy: ## lint api python sources with mypy
@echo 'lint:mypy started…'
@$(COMPOSE_RUN_API_PIPENV) mypy qualicharge tests
.PHONY: lint-mypy
test: ## run tests
bin/pytest
.PHONY: test
# -- Misc
help:
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: help