-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
126 lines (95 loc) · 3.27 KB
/
Copy pathMakefile
File metadata and controls
126 lines (95 loc) · 3.27 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
126
# ======================
# ==== CONFIG ==========
# ======================
# Container/service name used by docker-compose
SERVICE_NAME = python_application_template
# Python virtual environment path for local development
VENV = venv
PYTHON = $(VENV)/bin/python
# Default docker-compose files
COMPOSE_FILES = -f docker-compose.yaml
# ======================
# === PROD COMMANDS ====
# ======================
# Build production image
build:
docker compose $(COMPOSE_FILES) build
# Rebuild production image
rebuild:
docker compose $(COMPOSE_FILES) build --no-cache
# Start production container (detached)
up:
docker compose $(COMPOSE_FILES) up -d
# Stop and remove production containers, networks
down:
docker compose $(COMPOSE_FILES) down
# Show container logs (follow mode)
logs:
docker compose logs -f $(SERVICE_NAME)
# Open terminal shell inside the container
terminal:
docker compose $(COMPOSE_FILES) run -it --rm --entrypoint /bin/bash $(SERVICE_NAME)
# ======================
# === DEV COMMANDS ====
# ======================
# Build development image
build-dev:
DOCKER_BUILD_TARGET=dev docker compose $(COMPOSE_FILES) build
# Rebuild development image
rebuild-dev:
DOCKER_BUILD_TARGET=dev docker compose $(COMPOSE_FILES) build --no-cache
# Start development container
up-dev:
DOCKER_BUILD_TARGET=dev docker compose $(COMPOSE_FILES) up -d
# Enter development container shell
shell-dev: up-dev
docker exec -it $(SERVICE_NAME) bash
# Open terminal shell inside the development container
terminal-dev: build-dev
DOCKER_BUILD_TARGET=dev docker compose $(COMPOSE_FILES) run -it --rm --entrypoint /bin/bash $(SERVICE_NAME)
# Stop development container
down-dev:
docker compose $(COMPOSE_FILES) down
# ======================
# === TEST & LINT (DOCKER) ===
# ======================
# Run tests inside dev container
test-dev: build-dev
#docker exec -it $(SERVICE_NAME) pytest -vv
docker-compose $(COMPOSE_FILES) run --rm --entrypoint "bash -c 'python3 -m pytest --junitxml=logs/test-results.xml tests'" $(SERVICE_NAME)
# # Run tests inside production container
# test-prod: build
# docker-compose $(COMPOSE_FILES) run --rm --entrypoint "bash -c 'python3 -m pytest --junitxml=logs/test-results.xml tests'" $(SERVICE_NAME)
# Run linters inside dev container (adjust tools as needed)
lint: build-dev
docker-compose $(COMPOSE_FILES) run --rm --entrypoint "bash -c 'pre-commit run --all-files'" $(SERVICE_NAME)
pre-commit:
docker compose $(COMPOSE_FILES) run --rm --entrypoint "bash" $(SERVICE_NAME) -c "git init && pre-commit run --all-files"
# ======================
# === LOCAL ENV SETUP ===
# ======================
# Create local virtual environment and install dev dependencies
local-venv:
uv venv $(VENV)
source venv/bin/activate \
&& uv pip install -r requirements/requirements.txt \
&& uv pip install -r requirements/requirements-dev.txt
# Remove local virtual environment
local-clean:
rm -rf $(VENV)
# ======================
# === TEST & LINT (LOCAL) ===
# ======================
# Run tests locally
local-test:
$(VENV)/bin/pytest -vv
# Run linters locally
local-pre-commit:
$(VENV)/bin/pre-commit run --all-files
# ======================
# === UTILITIES ========
# ======================
# Clean unused Docker images, networks and volumes
clean:
docker system prune -f
docker volume prune -f