-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
113 lines (83 loc) · 4.39 KB
/
Makefile
File metadata and controls
113 lines (83 loc) · 4.39 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
SHELL := /bin/bash
COMPOSE ?= docker compose
COMPOSE_FILE ?= docker-compose.yaml
ENV_FILE ?= .env.example
API_SERVICE ?= productory-demo
DB_SERVICE ?= productory-db
SERVICE ?= $(API_SERVICE)
TEST ?=
VENV ?= .venv
VENV_PY := $(VENV)/bin/python3
DC := $(COMPOSE) --env-file $(ENV_FILE) -f $(COMPOSE_FILE)
.DEFAULT_GOAL := help
.PHONY: help venv install-dev qa coverage demo-migrate demo-run demo-stop demo-logs demo-check up down restart logs ps migrations superuser drop-create-db loaddata show-urls test test-quick test-one test-all shell ipython
help: ## Show available commands
@grep -E '^[a-zA-Z_-]+:.*##' Makefile | sort | awk 'BEGIN {FS = ":.*## "}; {printf "%-18s %s\n", $$1, $$2}'
venv: ## Create local virtualenv at .venv (if missing)
@if [ ! -x "$(VENV_PY)" ]; then \
python3 -m venv $(VENV); \
$(VENV_PY) -m pip install --upgrade pip; \
fi
install-dev: venv ## Install package + dev dependencies into local .venv
$(VENV_PY) -m pip install -e '.[dev]'
qa: venv ## Run lint, format check, type check, and tests
$(VENV_PY) -m ruff check src tests demo
$(VENV_PY) -m ruff format --check src tests demo --exclude '*/migrations/*'
$(VENV_PY) -m mypy src
$(VENV_PY) -m pytest tests
coverage: venv ## Run tests with coverage report
$(VENV_PY) -m coverage run -m pytest tests
$(VENV_PY) -m coverage report
demo-migrate: ## Run migrations for the demo project
$(DC) up -d $(DB_SERVICE) $(API_SERVICE)
$(DC) exec -T $(DB_SERVICE) sh -lc 'until pg_isready -U "$$POSTGRES_USER" -d "$$POSTGRES_DB" >/dev/null 2>&1; do echo "Waiting for Postgres..."; sleep 1; done'
$(DC) exec $(API_SERVICE) python demo/manage.py migrate
demo-run: ## Run demo stack in detached docker mode
$(DC) up -d --build $(DB_SERVICE) $(API_SERVICE)
$(DC) exec -T $(DB_SERVICE) sh -lc 'until pg_isready -U "$$POSTGRES_USER" -d "$$POSTGRES_DB" >/dev/null 2>&1; do echo "Waiting for Postgres..."; sleep 1; done'
$(DC) exec $(API_SERVICE) python demo/manage.py migrate
$(DC) exec $(API_SERVICE) python demo/manage.py seed_demo_data --reset
demo-stop: ## Stop detached demo docker stack
$(DC) down
demo-logs: ## Tail demo container logs
$(DC) logs -f --tail=200 $(API_SERVICE)
demo-check: venv ## Run Django checks for demo project
$(VENV_PY) demo/manage.py check
up: ## Start and build docker services
$(DC) up -d --build
down: ## Stop and remove docker services
$(DC) down --remove-orphans
restart: ## Restart services (override with SERVICE=<name>)
$(DC) restart $(SERVICE)
logs: ## Tail logs (override with SERVICE=<name>)
$(DC) logs -f --tail=200 $(SERVICE)
ps: ## List running services
$(DC) ps
migrations: ## Create and apply Django migrations in docker
$(DC) exec $(API_SERVICE) python demo/manage.py makemigrations
$(DC) exec $(API_SERVICE) python demo/manage.py migrate
superuser: ## Create a Django superuser in docker
$(DC) exec $(API_SERVICE) python demo/manage.py createsuperuser
drop-create-db: ## Nuke Postgres DB (DROP + CREATE) and re-run migrations
$(DC) up -d $(DB_SERVICE) $(API_SERVICE)
$(DC) exec -T $(DB_SERVICE) sh -lc 'psql -U "$$POSTGRES_USER" -d postgres -c "SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname='\''$$POSTGRES_DB'\'' AND pid <> pg_backend_pid();" -c "DROP DATABASE IF EXISTS \"$$POSTGRES_DB\";" -c "CREATE DATABASE \"$$POSTGRES_DB\";"'
$(DC) exec $(API_SERVICE) python demo/manage.py migrate
loaddata: ## Seed dynamic demo data in docker (50 products, bundles, promotions)
$(DC) exec $(API_SERVICE) python demo/manage.py seed_demo_data --reset
show-urls: ## Print resolved Django URL patterns in docker
$(DC) exec -T $(API_SERVICE) python demo/manage.py show_urls
test: test-quick ## Run quick tests in docker
test-quick: ## Run quick smoke tests in docker (fail fast)
$(DC) exec $(API_SERVICE) python -m pytest tests/test_services.py tests/test_api.py --maxfail=1 -q
test-one: ## Run one test in docker (pass TEST=tests/test_api.py::test_x)
@if [ -z "$(strip $(TEST))" ]; then \
echo "Usage: make test-one TEST=tests/test_api.py::test_catalog_and_checkout_flow"; \
exit 1; \
fi
$(DC) exec $(API_SERVICE) python -m pytest $(TEST) -q
test-all: ## Run full test suite in docker
$(DC) exec $(API_SERVICE) python -m pytest tests -q
shell: ## Open Django shell in docker
$(DC) exec $(API_SERVICE) python demo/manage.py shell
ipython: ## Open Django shell with IPython in docker if available
$(DC) exec $(API_SERVICE) sh -lc 'python demo/manage.py shell -i ipython || python demo/manage.py shell'