添加 Docker 部署支持和环境变量配置
添加了完整的 Docker 部署方案,包括: - 创建 .env.example 环境变量配置模板文件 - 新增 docker-compose.yml 用于全栈服务编排 - 为前后端分别创建 Dockerfile 实现容器化部署 - 添加 nginx.conf 配置前端反向代理 - 在 README.md 中详细说明 Docker 部署流程 - 集成 Celery 任务队列支持异步处理 - 配置多数据库服务 (MongoDB, MySQL, Redis) 的连接 - 实现健康检查和服务依赖管理
This commit is contained in:
36
frontend/Dockerfile
Normal file
36
frontend/Dockerfile
Normal file
@@ -0,0 +1,36 @@
|
||||
# ============================================================
|
||||
# FilesReadSystem Frontend - React + Vite
|
||||
# 多阶段构建: Node 构建 -> Nginx 运行
|
||||
# ============================================================
|
||||
|
||||
# === 阶段1: 构建阶段 ===
|
||||
FROM node:20-alpine AS builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# 复制 package 文件和锁文件
|
||||
COPY package.json pnpm-lock.yaml* ./
|
||||
|
||||
# 安装 pnpm 并安装依赖
|
||||
RUN npm install -g pnpm && \
|
||||
pnpm install --frozen-lockfile
|
||||
|
||||
# 复制源码
|
||||
COPY . .
|
||||
|
||||
# 构建生产版本
|
||||
RUN pnpm build
|
||||
|
||||
# === 阶段2: 运行阶段 ===
|
||||
FROM nginx:alpine
|
||||
|
||||
# 复制 nginx 配置
|
||||
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||||
|
||||
# 复制构建产物
|
||||
COPY --from=builder /app/dist /usr/share/nginx/html
|
||||
|
||||
# 暴露端口
|
||||
EXPOSE 80
|
||||
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
47
frontend/nginx.conf
Normal file
47
frontend/nginx.conf
Normal file
@@ -0,0 +1,47 @@
|
||||
# ============================================================
|
||||
# FilesReadSystem Nginx 配置
|
||||
# 反向代理 API 请求到后端
|
||||
# ============================================================
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
server_name localhost;
|
||||
|
||||
# 前端静态文件
|
||||
root /usr/share/nginx/html;
|
||||
index index.html;
|
||||
|
||||
# SPA 支持 - 所有请求都尝试返回 index.html
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
|
||||
# 静态资源缓存
|
||||
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
|
||||
expires 1y;
|
||||
add_header Cache-Control "public, immutable";
|
||||
}
|
||||
|
||||
# API 反向代理到后端
|
||||
location /api/ {
|
||||
proxy_pass http://backend:8000/api/;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
|
||||
# 超时设置
|
||||
proxy_connect_timeout 60s;
|
||||
proxy_send_timeout 60s;
|
||||
proxy_read_timeout 60s;
|
||||
}
|
||||
|
||||
# 文件上传代理
|
||||
location /uploads/ {
|
||||
proxy_pass http://backend:8000/uploads/;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
client_max_body_size 100M;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user