-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompose.yaml
More file actions
206 lines (198 loc) · 6.57 KB
/
compose.yaml
File metadata and controls
206 lines (198 loc) · 6.57 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
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# Docker Compose — Development, Staging, and Production
#
# One file, three modes via profiles. portal-db has no profile and is for local dev.
# See: https://docs.docker.com/compose/how-tos/profiles/
#
# Local development (DB only; run app with pnpm dev):
# docker compose up -d
# docker compose up -d portal-db
#
# Production (pre-built image, resource limits, hardened):
# docker compose --profile production up -d
# COMPOSE_PROFILES=production docker compose up -d
#
# Staging (pre-built image, different ports/DB):
# docker compose --profile staging up -d
# COMPOSE_PROFILES=staging docker compose up -d
#
# Add Adminer (DB UI): use --profile adminer with dev or standalone.
#
# Do not use --profile production and --profile staging together (different ports/containers).
# Set RESTART_POLICY=unless-stopped in .env for production.
#
# PostgreSQL 18+ uses /var/lib/postgresql (not .../data) for the volume mount;
# the image stores data in a versioned subdir. See docker-library/postgres#1259.
# If you see "PostgreSQL data in /var/lib/postgresql/data (unused mount)" after
# upgrading, remove the old volume and start fresh, or run pg_upgrade:
# docker compose down && docker volume rm portal-db-data && docker compose up -d portal-db
#
name: portal
services:
# --------------------------------------------------------------------------
# Local dev DB — no profile; always available. Used by pnpm dev / db:studio.
# --------------------------------------------------------------------------
portal-db:
image: postgres:18
container_name: portal-db
hostname: portal-db
restart: ${RESTART_POLICY:-unless-stopped}
environment:
POSTGRES_USER: ${POSTGRES_USER:-postgres}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-postgres}
POSTGRES_DB: ${POSTGRES_DB:-portal}
ports:
- "127.0.0.1:${POSTGRES_PORT:-5432}:5432"
volumes:
- portal-db-data:/var/lib/postgresql
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-postgres} -d ${POSTGRES_DB:-portal} -h localhost"]
interval: 10s
timeout: 5s
retries: 5
start_period: 10s
# --------------------------------------------------------------------------
# Production app + DB — use: docker compose --profile production up -d
# --------------------------------------------------------------------------
portal-db-production:
image: postgres:18-alpine
container_name: portal-db-production
hostname: portal-db-production
profiles: [production]
restart: unless-stopped
environment:
POSTGRES_USER: ${POSTGRES_USER:-postgres}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-postgres}
POSTGRES_DB: ${POSTGRES_DB:-portal}
volumes:
- portal-db-production-data:/var/lib/postgresql
networks:
- portal-production
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-postgres}"]
interval: 10s
timeout: 5s
retries: 5
start_period: 10s
deploy:
resources:
limits:
cpus: "2"
memory: 4G
reservations:
cpus: "0.5"
memory: 1G
portal-app-production:
image: ghcr.io/${GITHUB_REPOSITORY:-allthingslinux/portal}:${IMAGE_TAG:-production-latest}
container_name: portal-app-production
hostname: portal-app-production
profiles: [production]
restart: unless-stopped
env_file:
- path: .env.production
required: true
environment:
NODE_ENV: production
PORT: "3000"
ports:
- "3000:3000"
depends_on:
portal-db-production:
condition: service_healthy
networks:
- portal-production
healthcheck:
test: ["CMD", "node", "-e", "require('http').get('http://localhost:3000/api/health', (r) => { process.exit(r.statusCode === 200 ? 0 : 1); })"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
deploy:
resources:
limits:
cpus: "2"
memory: 2G
reservations:
cpus: "1"
memory: 512M
# --------------------------------------------------------------------------
# Staging app + DB — use: docker compose --profile staging up -d
# --------------------------------------------------------------------------
portal-db-staging:
image: postgres:18-alpine
container_name: portal-db-staging
hostname: portal-db-staging
profiles: [staging]
restart: unless-stopped
environment:
POSTGRES_USER: ${POSTGRES_USER:-postgres}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-postgres}
POSTGRES_DB: ${POSTGRES_DB:-portal_staging}
ports:
- "127.0.0.1:5433:5432"
volumes:
- portal-db-staging-data:/var/lib/postgresql
networks:
- portal-staging
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-postgres}"]
interval: 10s
timeout: 5s
retries: 5
start_period: 10s
portal-app-staging:
image: ghcr.io/${GITHUB_REPOSITORY:-allthingslinux/portal}:${IMAGE_TAG:-staging-latest}
container_name: portal-app-staging
hostname: portal-app-staging
profiles: [staging]
restart: unless-stopped
env_file:
- path: .env.staging
required: true
environment:
NODE_ENV: production
PORT: "3000"
ports:
- "127.0.0.1:3001:3000"
depends_on:
portal-db-staging:
condition: service_healthy
networks:
- portal-staging
healthcheck:
test: ["CMD", "node", "-e", "require('http').get('http://localhost:3000/api/health', (r) => { process.exit(r.statusCode === 200 ? 0 : 1); })"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
# --------------------------------------------------------------------------
# Adminer (DB UI) — use with dev or alone: docker compose --profile adminer up -d
# --------------------------------------------------------------------------
portal-adminer:
image: adminer:latest
container_name: portal-adminer
hostname: portal-adminer
profiles: [adminer]
restart: "no"
ports:
- "127.0.0.1:${ADMINER_PORT:-8080}:8080"
environment:
ADMINER_DEFAULT_SYSTEM: pgsql
ADMINER_DEFAULT_SERVER: portal-db
ADMINER_DEFAULT_DATABASE: ${POSTGRES_DB:-portal}
depends_on:
portal-db:
condition: service_healthy
volumes:
portal-db-data:
name: portal-db-data
portal-db-production-data:
name: portal-db-production-data
portal-db-staging-data:
name: portal-db-staging-data
networks:
portal-production:
name: portal-production
driver: bridge
portal-staging:
name: portal-staging
driver: bridge