-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.dev.yml
More file actions
193 lines (187 loc) · 5.43 KB
/
Copy pathdocker-compose.dev.yml
File metadata and controls
193 lines (187 loc) · 5.43 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
# Docker Compose 配置 (本地 Docker 开发环境: PostgreSQL + Redis + API + Web)
#
# 用法:
# docker compose -f docker-compose.dev.yml up -d (或 make docker-dev)
#
# 源码通过 docker compose watch sync 实时同步到容器:
# docker compose -f docker-compose.dev.yml watch (或 make docker-dev-watch)
#
# 停止:
# docker compose -f docker-compose.dev.yml down (或 make docker-dev-down)
name: violet-dev
services:
# PostgreSQL 数据库
postgres:
image: postgres:16-alpine
container_name: blog-postgres-dev
restart: unless-stopped
environment:
POSTGRES_USER: ${DATABASE_USER:-blog}
POSTGRES_PASSWORD: ${DATABASE_PASSWORD:-changeme-strong-password}
POSTGRES_DB: ${DATABASE_NAME:-blog}
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${DATABASE_USER:-blog} -d ${DATABASE_NAME:-blog}"]
interval: 5s
timeout: 5s
retries: 5
start_period: 10s
deploy:
resources:
limits:
memory: 512M
# Redis 缓存
redis:
image: redis:7-alpine
container_name: blog-redis-dev
restart: unless-stopped
command: >
sh -c "if [ -n \"$${REDIS_PASSWORD}\" ]; then
redis-server --requirepass \"$${REDIS_PASSWORD}\";
else
redis-server;
fi"
environment:
REDIS_PASSWORD: ${REDIS_PASSWORD:-}
volumes:
- redis_data:/data
healthcheck:
test: >
sh -c "if [ -n \"$${REDIS_PASSWORD}\" ]; then
redis-cli -a \"$${REDIS_PASSWORD}\" ping;
else
redis-cli ping;
fi"
interval: 5s
timeout: 5s
retries: 5
start_period: 5s
deploy:
resources:
limits:
memory: 256M
# Go API 服务 (Air 热重载 + docker compose watch sync)
api:
build:
context: ./api
dockerfile: Dockerfile.dev
container_name: blog-api-dev
restart: unless-stopped
ports:
- "9090:9090"
environment:
ENVIRONMENT: development
DATABASE_HOST: ${DEV_DATABASE_HOST:-postgres}
DATABASE_PORT: ${DATABASE_PORT:-5432}
DATABASE_NAME: ${DATABASE_NAME:-blog}
DATABASE_USER: ${DATABASE_USER:-blog}
DATABASE_PASSWORD: ${DATABASE_PASSWORD:-changeme-strong-password}
DATABASE_SSLMODE: disable
REDIS_HOST: ${DEV_REDIS_HOST:-redis}
REDIS_PORT: 6379
REDIS_DB: 0
REDIS_PASSWORD: ${REDIS_PASSWORD:-}
PORT: 9090
SUPERADMIN_ENABLED: ${SUPERADMIN_ENABLED:-false}
SUPERADMIN_USERNAME: ${SUPERADMIN_USERNAME:-}
SUPERADMIN_EMAIL: ${SUPERADMIN_EMAIL:-}
SUPERADMIN_PASSWORD: ${SUPERADMIN_PASSWORD:-}
extra_hosts:
- "host.docker.internal:host-gateway"
develop:
watch:
# Go 源码同步进容器后由 Air 检测变化并自动重编译重启
- action: sync
path: ./api
target: /app
ignore:
- tmp/
- bin/
- .git/
- uploads/
- .idea/
- .vscode/
- action: sync+restart
path: ./api/.air.toml
target: /app/.air.toml
- action: rebuild
path: ./api/go.mod
- action: rebuild
path: ./api/go.sum
- action: rebuild
path: ./api/Dockerfile.dev
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
volumes:
# go 编译缓存持久化:recreate 后 air 增量编译秒级完成,
# 否则每次全量编译 ~2.5 分钟
- go_build_cache:/root/.cache/go-build
# 系统面板数据库备份,容器重建后保留
- backups_data:/app/backups
healthcheck:
test: ["CMD", "wget", "--no-verbose", "--tries=1", "-O-", "http://localhost:9090/api/health"]
interval: 10s
timeout: 5s
retries: 12
start_period: 60s
deploy:
resources:
limits:
memory: 2G
# React Web 前端 (Vite HMR + docker compose watch sync)
web:
build:
context: ./web
dockerfile: Dockerfile.dev
container_name: blog-web-dev
restart: unless-stopped
ports:
- "5173:5173"
environment:
VITE_API_PROXY_TARGET: ${DEV_API_TARGET:-http://api:9090}
VITE_SSR_API_BASE_URL: ${DEV_SSR_API_BASE_URL:-http://api:9090/api/v1}
CHOKIDAR_USEPOLLING: "true"
WATCHPACK_POLLING: "true"
develop:
watch:
# 前端源码同步进容器后由 Vite 检测变化并触发 HMR;
# node_modules/dist/.env 等由 ignore 排除,防止宿主机目录同步覆盖容器内部文件
- action: sync
path: ./web
target: /app
ignore:
- node_modules/
- dist/
- .git/
- .vite/
# pnpm-workspace.yaml 承载 allowBuilds 等 install 行为配置,需 rebuild 才生效
- action: rebuild
path: ./web/pnpm-workspace.yaml
- action: rebuild
path: ./web/package.json
- action: rebuild
path: ./web/pnpm-lock.yaml
- action: rebuild
path: ./web/Dockerfile.dev
depends_on:
api:
condition: service_healthy
healthcheck:
test: ["CMD", "wget", "--no-verbose", "--tries=1", "-O-", "http://127.0.0.1:5173/"]
interval: 10s
timeout: 5s
retries: 5
start_period: 15s
deploy:
resources:
limits:
memory: 2G
volumes:
postgres_data:
redis_data:
go_build_cache:
backups_data: