-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
111 lines (104 loc) · 3.07 KB
/
Copy pathdocker-compose.yml
File metadata and controls
111 lines (104 loc) · 3.07 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
version: "3.9"
networks:
prefect_network:
external: true
name: prefect_network
app_network:
name: app_network
driver: bridge
services:
# =============================================================================
# Infrastructure - Database
# =============================================================================
dbapp:
image: postgres:17
container_name: dbapp
restart: always
env_file:
- .env
environment:
POSTGRES_DB: ${APP_DB_NAME}
POSTGRES_USER: ${APP_DB_USER}
POSTGRES_PASSWORD: ${APP_DB_PASSWORD}
ports:
- "5432:5432"
volumes:
- app_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${APP_DB_USER} -d ${APP_DB_NAME}"]
interval: 10s
timeout: 5s
retries: 5
start_period: 30s
networks:
- app_network
# =============================================================================
# Migrations - Database schema management
# =============================================================================
migrations:
build:
context: .
dockerfile: dockerfile
target: migrations
container_name: migrations
env_file:
- .env
depends_on:
dbapp:
condition: service_healthy
command: alembic upgrade head
restart: "no"
networks:
- app_network
# =============================================================================
# API - FastAPI HTTP server
# =============================================================================
api:
build:
context: .
dockerfile: dockerfile
target: api
container_name: fastapi-api
env_file:
- .env
ports:
- "8000:80"
depends_on:
dbapp:
condition: service_healthy
migrations:
condition: service_completed_successfully
restart: always
networks:
- app_network
healthcheck:
test: ["CMD", "python", "-c", "import requests; requests.get('http://localhost/api/v1/health/', timeout=5)"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
# =============================================================================
# Prefect Worker - Managed by Prefect server
# =============================================================================
prefect-worker:
image: prefecthq/prefect:3-latest
container_name: prefect-worker
environment:
PREFECT_API_URL: ${PREFECT_API_URL}
WORK_POOL_NAME: ${WORK_POOL_NAME}
PREFECT_API_AUTH_STRING: "${PREFECT_LOGIN_USER}:${PREFECT_LOGIN_PASSWORD}"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
depends_on:
dbapp:
condition: service_healthy
migrations:
condition: service_completed_successfully
networks:
- prefect_network # Access to Prefect server
- app_network # Access to application database
entrypoint:
["/bin/sh", "-c", "pip install -q prefect-docker && prefect worker start --pool ${WORK_POOL_NAME} --type docker"]
restart: unless-stopped
volumes:
app_data: