-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
69 lines (66 loc) · 2.39 KB
/
docker-compose.yml
File metadata and controls
69 lines (66 loc) · 2.39 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
name: nestjs-scaffold
version: '1.2'
services:
# ─────────────────── PostgreSQL ───────────────────
database:
container_name: ${POSTGRES_CONTAINER_NAME:-database}
image: postgres:18
restart: unless-stopped
environment:
POSTGRES_USER: ${POSTGRES_USER:-nestjs}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-nestjs_password}
POSTGRES_DB: ${POSTGRES_DB:-nestjs_demo}
# 额外创建一个 shadow 数据库供 Prisma Migrate 使用
POSTGRES_MULTIPLE_DATABASES: ${POSTGRES_DB:-nestjs_demo_shadow}
volumes:
- postgres_data:/var/lib/postgresql
ports:
- '${POSTGRES_PORT:-5432}:5432'
healthcheck:
test: ['CMD-SHELL', 'pg_isready -U ${POSTGRES_USER:-nestjs} -d ${POSTGRES_DB:-nestjs_demo}']
interval: 10s
timeout: 5s
retries: 5
start_period: 10s
networks:
- app_network
# ─────────────────── NestJS App ───────────────────
backend:
container_name: ${APP_CONTAINER_NAME:-backend}
build:
context: .
dockerfile: Dockerfile
args:
NODE_ENV: ${NODE_ENV:-development}
APP_NAME: ${APP_NAME:-nestjs-scaffold}
APP_VERSION: ${APP_VERSION:-latest}
restart: unless-stopped
depends_on:
database:
condition: service_healthy
environment:
NODE_ENV: ${NODE_ENV:-development}
# DATABASE_URL 需要指向 Compose 内部服务名,覆盖加密文件中的值
DATABASE_URL: postgresql://${POSTGRES_USER:-nestjs}:${POSTGRES_PASSWORD:-nestjs_password}@database:5432/${POSTGRES_DB:-nestjs_demo}?schema=public
SHADOW_DATABASE_URL: postgresql://${POSTGRES_USER:-nestjs}:${POSTGRES_PASSWORD:-nestjs_password}@database:5432/${POSTGRES_DB:-nestjs_demo_shadow}?schema=public
volumes:
# .env.keys 提供 dotenvx 解密私钥,其余所有配置由解密后的 .env.{NODE_ENV} 文件注入
- type: bind
source: ./.env.keys
target: /app/.env.keys
read_only: true
ports:
- '${BACKEND_PORT:-3000}:3000'
healthcheck:
test: ['CMD-SHELL', 'curl --fail http://backend:3000/health']
interval: 10s
timeout: 5s
retries: 5
start_period: 10s
networks:
- app_network
volumes:
postgres_data:
networks:
app_network:
driver: bridge