chore: 完善全栈 Docker 开发环境与容器基础设施

This commit is contained in:
2026-08-04 17:09:30 +08:00
parent 9ec4f8efa7
commit e0bd1ad44e
3 changed files with 97 additions and 5 deletions

23
backend/Dockerfile.dev Normal file
View File

@ -0,0 +1,23 @@
# ============================================================
# 后端开发 Dockerfile — FastAPI + Uvicorn 热更新
# ============================================================
FROM python:3.13-slim
WORKDIR /app
# 系统依赖Pillow / cryptography 编译所需)
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
libpq-dev \
libffi-dev \
libjpeg-dev \
zlib1g-dev \
&& rm -rf /var/lib/apt/lists/*
# 先装 Python 依赖(利用 Docker 缓存层,改代码不重装)
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# 代码通过 docker-compose volumes 挂载,不需要 COPY
# --reload 监听代码变化自动重启
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--reload"]

View File

@ -1,19 +1,24 @@
# ============================================================
# 生产流转管理系统 — PostgreSQL 15 + pgvector
# 独立于老系统数据库,通过逻辑外键关联 user / material
# 生产流转管理系统 — 全栈 Docker 热更新开发环境
# 启动: docker compose up -d --build
# 停止: docker compose down
# 日志: docker compose logs -f
# ============================================================
services:
track_db_prod:
# ============================================================
# PostgreSQL 15 + pgvector
# ============================================================
db:
image: pgvector/pgvector:pg15
container_name: track_db_prod
container_name: track_db
restart: unless-stopped
environment:
POSTGRES_USER: track
POSTGRES_PASSWORD: track_prod_2026
POSTGRES_DB: track_production
ports:
- "5433:5432" # 避开老系统 5432 端口
- "8012:5432"
volumes:
- track_pgdata:/var/lib/postgresql/data
healthcheck:
@ -22,6 +27,57 @@ services:
timeout: 5s
retries: 5
# ============================================================
# FastAPI 后端 — --reload 热更新
# ============================================================
backend:
build:
context: ./backend
dockerfile: Dockerfile.dev
container_name: track_backend
restart: unless-stopped
environment:
DATABASE_URL: postgresql+asyncpg://track:track_prod_2026@db:5432/track_production
SECRET_KEY: change-me-in-production
DEBUG: "true"
CORS_ORIGINS: '["http://localhost:8010","https://localhost:8010","http://192.168.9.80:8010","https://192.168.9.80:8010","tauri://localhost"]'
MOM_DB_HOST: 172.20.0.3
MOM_DB_PORT: "5432"
ports:
- "8011:8000"
volumes:
- ./backend:/app
depends_on:
db:
condition: service_healthy
networks:
- default
- mom_net
# ============================================================
# Vite + React 前端 — HMR 热更新
# ============================================================
frontend:
build:
context: ./frontend
dockerfile: Dockerfile.dev
container_name: track_frontend
restart: unless-stopped
environment:
VITE_API_BASE_URL: /api/v1
ports:
- "8010:1420"
volumes:
- ./frontend:/app
- /app/node_modules # 匿名卷,不覆盖容器里的 node_modules
depends_on:
- backend
networks:
mom_net:
external: true
name: inventory-backend_default
volumes:
track_pgdata:
name: track_pgdata

13
frontend/Dockerfile.dev Normal file
View File

@ -0,0 +1,13 @@
# ============================================================
# 前端开发 Dockerfile — Vite + React HMR 热更新
# ============================================================
FROM node:20-alpine
WORKDIR /app
# 先装依赖(利用 Docker 缓存层)
COPY package.json package-lock.json ./
RUN npm install
# 代码通过 docker-compose volumes 挂载
CMD ["npx", "vite", "--host", "0.0.0.0"]