chore: productionize compose deployment

This commit is contained in:
Cheng Zhou
2026-03-27 16:13:28 +08:00
parent d8c5413b26
commit f2f856ea24
7 changed files with 182 additions and 79 deletions
+5 -63
View File
@@ -1,9 +1,4 @@
services:
# =========================================
# [主演] 业务服务 (日常开发一直开着)
# =========================================
# 1. 数据库 (PostgreSQL)
db:
image: postgres:15-alpine
container_name: ctms_db
@@ -27,18 +22,14 @@ services:
networks:
- ctms_net
# 2. 后端 (FastAPI)
backend:
build:
build:
context: ./backend
dockerfile: Dockerfile
container_name: ctms_backend
command: python -m debugpy --listen 0.0.0.0:5678 -m uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload --proxy-headers --forwarded-allow-ips '*'
volumes:
- ./backend:/code
restart: always
ports:
- "8000:8000"
- "5678:5678"
environment:
DATABASE_URL: postgresql+asyncpg://ctms_user:secret_password@db/ctms_db
depends_on:
@@ -47,56 +38,10 @@ services:
networks:
- ctms_net
# 3. 前端 (Vue3)
frontend:
build:
context: ./frontend
dockerfile: Dockerfile
container_name: ctms_frontend
restart: always
# 开启 Host 模式以支持 Vite 热更新
command: npm run dev -- --host
volumes:
- ./frontend:/app
# [关键] 让容器使用自己的 node_modules,而不是宿主机的
- /app/node_modules
ports:
- "5173:5173"
environment:
VITE_API_BASE_URL: /
NODE_OPTIONS: --max-old-space-size=4096
depends_on:
- backend
networks:
- ctms_net
# =========================================
# [剧务] 初始化工具 (只在需要时召唤)
# profiles: ["init"] 标记了它们平时不会启动
# =========================================
# Node 工具箱:用于生成 Vue 代码、安装 npm 包
frontend-init:
image: node:latest
profiles: ["init"]
working_dir: /app
volumes:
- ./frontend:/app
networks:
- ctms_net
# Python 工具箱:用于生成 requirements.txt 等
backend-init:
image: python:3.10-slim
profiles: ["init"]
working_dir: /code
volumes:
- ./backend:/code
networks:
- ctms_net
nginx:
image: nginx:latest
build:
context: .
dockerfile: nginx/Dockerfile
container_name: ctms_nginx
restart: always
ports:
@@ -104,16 +49,13 @@ services:
- "443:443" # HTTPS
- "8888:8888"
volumes:
- ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
- ./nginx/certs:/etc/nginx/certs:ro
- ./frontend/public/favicon.ico:/usr/share/nginx/html/favicon.ico:ro
depends_on:
- backend
- frontend
networks:
- ctms_net
networks:
ctms_net:
driver: bridge