-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
287 lines (276 loc) · 7.64 KB
/
docker-compose.yml
File metadata and controls
287 lines (276 loc) · 7.64 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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
services:
postgres:
image: postgres:17.5-alpine
ports:
- "5432:5432"
volumes:
- postgres_data:/var/lib/postgresql/data
environment:
- POSTGRES_DB=pagespace
- POSTGRES_USER=user
- POSTGRES_PASSWORD=password
healthcheck:
test: ["CMD-SHELL", "pg_isready -U user -d pagespace"]
interval: 10s
timeout: 5s
retries: 5
networks:
- internal
deploy:
resources:
limits:
memory: 200M
migrate:
build:
context: .
dockerfile: apps/web/Dockerfile.migrate
depends_on:
postgres:
condition: service_healthy
env_file: .env
environment:
- DATABASE_URL=postgresql://user:password@postgres:5432/pagespace
- PNPM_HOME=/usr/local/bin
command: >
sh -c "
echo 'Starting database migrations...' &&
pnpm run db:migrate &&
echo 'Migrations complete, starting services...'
"
healthcheck:
test: ["CMD", "echo", "Migration service healthy"]
interval: 30s
timeout: 10s
retries: 3
networks:
- internal
web:
build:
context: .
dockerfile: apps/web/Dockerfile
args:
# NEXT_PUBLIC_* vars must be passed at build time for Next.js to inline them
# Note: Stripe keys are hardcoded in stripe-config.ts to simplify builds
- NEXT_PUBLIC_REALTIME_URL=${NEXT_PUBLIC_REALTIME_URL}
- NEXT_PUBLIC_APP_URL=${NEXT_PUBLIC_APP_URL}
- NEXT_PUBLIC_STORAGE_MAX_FILE_SIZE_MB=${NEXT_PUBLIC_STORAGE_MAX_FILE_SIZE_MB}
- NEXT_PUBLIC_GOOGLE_OAUTH_CLIENT_ID=${NEXT_PUBLIC_GOOGLE_OAUTH_CLIENT_ID}
- NEXT_PUBLIC_GOOGLE_OAUTH_IOS_CLIENT_ID=${NEXT_PUBLIC_GOOGLE_OAUTH_IOS_CLIENT_ID}
extra_hosts:
- "host.docker.internal:host-gateway"
ports:
- "3000:3000"
depends_on:
migrate:
condition: service_completed_successfully
processor:
condition: service_healthy
volumes:
- file_storage:/app/storage
env_file: .env
environment:
- DATABASE_URL=postgresql://user:password@postgres:5432/pagespace
- NEXT_PUBLIC_REALTIME_URL=${NEXT_PUBLIC_REALTIME_URL}
- FILE_STORAGE_PATH=/app/storage
- PROCESSOR_URL=http://processor:3003
- PORT=3000
- HOSTNAME=0.0.0.0
- NODE_OPTIONS=--max-old-space-size=640
deploy:
resources:
limits:
memory: 768M
networks:
- internal
- frontend
# Permission fixer - runs once to fix existing volume permissions
processor-permissions:
build:
context: .
dockerfile: apps/processor/Dockerfile
user: root
volumes:
- file_storage:/data/files
- cache_storage:/data/cache
command: |
sh -c '
echo "Fixing volume permissions..."
chown -R 1000:1000 /data/files /data/cache
echo "Permissions fixed successfully"
'
restart: "no"
networks:
- internal
processor:
# @tensorflow/tfjs-node has no Linux-arm64 prebuild. CI + prod build on
# ubuntu-latest (amd64); pin here so local builds on Apple Silicon
# produce an amd64 image (runs via Rosetta 2). No-op on amd64 hosts.
platform: linux/amd64
build:
context: .
dockerfile: apps/processor/Dockerfile
platforms:
- linux/amd64
ports:
- "3003:3003"
depends_on:
migrate:
condition: service_completed_successfully
postgres:
condition: service_healthy
processor-permissions:
condition: service_completed_successfully
volumes:
- file_storage:/data/files
- cache_storage:/data/cache
env_file: .env
environment:
- DATABASE_URL=postgresql://user:password@postgres:5432/pagespace
- FILE_STORAGE_PATH=/data/files
- CACHE_PATH=/data/cache
- PORT=3003
- NODE_OPTIONS=--max-old-space-size=1024
- ENABLE_OCR=${ENABLE_OCR:-false}
- ENABLE_EXTERNAL_OCR=${ENABLE_EXTERNAL_OCR:-false}
- PROCESSOR_AUTH_REQUIRED=${PROCESSOR_AUTH_REQUIRED:-true}
- PROCESSOR_UPLOAD_RATE_LIMIT=${PROCESSOR_UPLOAD_RATE_LIMIT:-100}
- PROCESSOR_UPLOAD_RATE_WINDOW=${PROCESSOR_UPLOAD_RATE_WINDOW:-3600}
healthcheck:
test: ["CMD", "node", "-e", "require('http').get('http://localhost:3003/health', (r) => {r.statusCode === 200 ? process.exit(0) : process.exit(1)})"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
deploy:
resources:
limits:
memory: 1280M
restart: unless-stopped
networks:
- internal
user: "1000:1000"
read_only: true
tmpfs:
- /tmp:noexec,nosuid,size=100m
security_opt:
- no-new-privileges:true
realtime:
build:
context: .
dockerfile: apps/realtime/Dockerfile
ports:
- "3001:3001"
depends_on:
migrate:
condition: service_completed_successfully
env_file: .env
environment:
- DATABASE_URL=postgresql://user:password@postgres:5432/pagespace
- PORT=${REALTIME_PORT}
- CORS_ORIGIN=http://localhost:3000
deploy:
resources:
limits:
memory: 256M
networks:
- internal
- frontend
# Cron service for scheduled background jobs
# Runs inside Docker network, authenticates with CRON_SECRET
cron:
build:
context: ./docker/cron
dockerfile: Dockerfile
depends_on:
web:
condition: service_started
environment:
- CRON_SECRET=${CRON_SECRET}
volumes:
- cron_logs:/var/log/cron
deploy:
resources:
limits:
memory: 32M
restart: unless-stopped
networks:
- internal
marketing:
build:
context: .
dockerfile: apps/marketing/Dockerfile
args:
- NEXT_PUBLIC_MARKETING_URL=http://localhost:3004
- NEXT_PUBLIC_APP_URL=http://localhost:3000
- NEXT_PUBLIC_COOKIE_DOMAIN=localhost
ports:
- "3004:3004"
environment:
- PORT=3004
- NEXT_PUBLIC_MARKETING_URL=http://localhost:3004
- NEXT_PUBLIC_APP_URL=http://localhost:3000
- NEXT_PUBLIC_COOKIE_DOMAIN=localhost
- RESEND_API_KEY=${RESEND_API_KEY}
- FROM_EMAIL=${FROM_EMAIL:-noreply@pagespace.ai}
- NODE_ENV=production
deploy:
resources:
limits:
memory: 256M
networks:
- frontend
# Test service for running unit tests with database access
test:
build:
context: .
dockerfile: apps/web/Dockerfile.migrate
depends_on:
postgres:
condition: service_healthy
environment:
- DATABASE_URL=postgresql://user:password@postgres:5432/pagespace_test
- CSRF_SECRET=test-csrf-secret-minimum-32-characters-long-for-testing-purposes
- ENCRYPTION_KEY=test-encryption-key-32-chars-minimum-required-length
- REALTIME_BROADCAST_SECRET=test-realtime-broadcast-secret-32-chars-minimum-length
command: >
sh -c "
echo 'Setting up test database schema...' &&
cd packages/db && pnpm drizzle-kit push --force &&
cd ../.. &&
echo 'Running tests...' &&
pnpm test:unit
"
networks:
- internal
profiles:
- test
# Optional nginx service for efficient static file serving
nginx:
image: nginx:alpine
ports:
- "3004:80"
volumes:
- cache_storage:/usr/share/nginx/html/cache:ro
- ./nginx.conf:/etc/nginx/nginx.conf:ro
depends_on:
processor:
condition: service_healthy
deploy:
resources:
limits:
memory: 128M
profiles:
- production
networks:
- frontend
networks:
internal:
driver: bridge
internal: true
frontend:
driver: bridge
volumes:
postgres_data:
file_storage:
cache_storage:
cron_logs: