-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
125 lines (93 loc) · 3.69 KB
/
Makefile
File metadata and controls
125 lines (93 loc) · 3.69 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
114
115
116
117
118
119
120
121
122
123
124
125
MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
PROJECT_DIR := $(dir $(MKFILE_PATH))
# Set additional build args for docker image build using make arguments
IMAGE_NAME := pycon_backend
SERVER_CONTAINER_NAME = $(IMAGE_NAME)_server_container
ifeq ($(DOCKER_DEBUG),true)
DOCKER_MID_BUILD_OPTIONS = --progress=plain --no-cache
DOCKER_END_BUILD_OPTIONS = 2>&1 | tee docker-build.log
else
DOCKER_MID_BUILD_OPTIONS =
DOCKER_END_BUILD_OPTIONS =
endif
# =============================================================================
# Local development commands
# Setup local environments
local-setup:
@uv sync
# Run local development server
local-api: local-collectstatic
@ENV_PATH=envfile/.env.local uv run python app/manage.py runserver 8000
# Run local Celery worker (requires `make docker-compose-up` for redis)
local-worker:
@cd app && ENV_PATH=../envfile/.env.local uv run celery -A core worker -l INFO --concurrency=4
# Run django collectstatic
local-collectstatic:
@ENV_PATH=envfile/.env.local uv run python app/manage.py collectstatic --noinput
# Run django shell
local-shell:
@ENV_PATH=envfile/.env.local uv run python app/manage.py shell
# Run django shell plus
local-shell-plus:
@ENV_PATH=envfile/.env.local uv run python app/manage.py shell_plus
# Run django db-shell
local-dbshell:
@ENV_PATH=envfile/.env.local uv run python app/manage.py dbshell
# Run django makemigrations
local-makemigrations:
@ENV_PATH=envfile/.env.local uv run python app/manage.py makemigrations
# Run django migrate
local-migrate:
@ENV_PATH=envfile/.env.local uv run python app/manage.py migrate
# Show django makemigrations
local-showmigrations:
@ENV_PATH=envfile/.env.local uv run python app/manage.py showmigrations
# Create admin superuser
local-createsuperuser:
@ENV_PATH=envfile/.env.local uv run python app/manage.py createsuperuser
# Reverse django migrations
local-reverse-migrations:
@ENV_PATH=envfile/.env.local uv run python app/manage.py migrate $(app) $(number)
# Run pytest
local-test:
@ENV_PATH=envfile/.env.local cd app && uv run pytest -v
# Devtools
hooks-install: local-setup
uv run pre-commit install
hooks-upgrade:
uv run pre-commit autoupdate
hooks-lint:
uv run pre-commit run --all-files
lint: hooks-lint # alias
# =============================================================================
# Docker related commands (Server)
# Server Docker image build
docker-server-build:
@docker build \
-f ./infra/server.Dockerfile -t $(IMAGE_NAME):server \
--build-arg GIT_HASH=$(shell git rev-parse HEAD) \
--build-arg IMAGE_BUILD_DATETIME=$(shell date +%Y-%m-%d_%H:%M:%S) \
$(DOCKER_MID_BUILD_OPTIONS) $(PROJECT_DIR) $(DOCKER_END_BUILD_OPTIONS)
docker-server-run: docker-compose-up
@(docker stop $(SERVER_CONTAINER_NAME) || true && docker rm $(SERVER_CONTAINER_NAME) || true) > /dev/null 2>&1
@docker run -d --rm \
-p 8000:8000 \
--env-file envfile/.env.local --env-file envfile/.env.docker \
--name $(SERVER_CONTAINER_NAME) \
$(IMAGE_NAME):server
docker-server-readyz:
curl -s http://localhost:8000/readyz/ | jq '.'
docker-server-test: docker-server-run docker-server-readyz
docker-server-build-and-test: docker-server-build docker-server-test
docker-server-stop:
docker stop $(SERVER_CONTAINER_NAME) || true
docker-server-rm: docker-server-stop
docker rm $(SERVER_CONTAINER_NAME) || true
# Docker compose setup
# Below commands are for local development only
docker-compose-up:
docker compose --env-file envfile/.env.local -f ./infra/docker-compose.dev.yaml up -d
docker-compose-down:
docker compose --env-file envfile/.env.local -f ./infra/docker-compose.dev.yaml down
docker-compose-rm: docker-compose-down
docker compose --env-file envfile/.env.local -f ./infra/docker-compose.dev.yaml rm