Add DevOps release and deployment configuration
Some checks failed
Build and Deploy / test-backend (push) Has been cancelled
Build and Deploy / build-backend (push) Has been cancelled
Build and Deploy / build-admin (push) Has been cancelled
Deploy to Production / build-backend (push) Has been cancelled
Deploy to Production / deploy (push) Has been cancelled

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
bujie9527
2026-02-05 22:59:28 +08:00
parent edae775129
commit 0bd860f956
9 changed files with 488 additions and 30 deletions

24
deploy/.env.prod.example Normal file
View File

@@ -0,0 +1,24 @@
# 生产环境变量配置模板
# 复制此文件为 .env.prod 并填写实际值
# 镜像标签
TAG=latest
# 数据库配置
DATABASE_URL=postgresql://postgres:CHANGE_ME@db:5432/wecom_ai
DATABASE_URL_SYNC=postgresql://postgres:CHANGE_ME@db:5432/wecom_ai
POSTGRES_USER=postgres
POSTGRES_PASSWORD=CHANGE_ME
POSTGRES_DB=wecom_ai
# WeCom 配置
WECOM_CORP_ID=你的企业ID
WECOM_AGENT_ID=你的应用AgentId
WECOM_TOKEN=你的Token
WECOM_ENCODING_AES_KEY=你的43位密钥
# JWT 配置
JWT_SECRET=CHANGE_ME_TO_RANDOM_STRING
# 其他配置
ENVIRONMENT=production

View File

@@ -0,0 +1,78 @@
# 生产环境部署配置
# 用途:云端生产环境一键部署
# 使用: docker compose -f docker-compose.prod.yml --env-file .env.prod up -d
version: '3.8'
services:
db:
image: postgres:16-alpine
environment:
POSTGRES_USER: ${POSTGRES_USER:-postgres}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB:-wecom_ai}
volumes:
- db_data:/var/lib/postgresql/data
restart: always
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-postgres} -d ${POSTGRES_DB:-wecom_ai}"]
interval: 10s
timeout: 5s
retries: 5
networks:
- app-network
backend:
image: registry.667788.cool/wecom-backend:${TAG:-latest}
env_file:
- .env.prod
environment:
DATABASE_URL: ${DATABASE_URL}
DATABASE_URL_SYNC: ${DATABASE_URL_SYNC}
depends_on:
db:
condition: service_healthy
restart: always
healthcheck:
test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:8000/api/health')"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
networks:
- app-network
admin:
image: registry.667788.cool/wecom-admin:${TAG:-latest}
env_file:
- .env.prod
restart: always
healthcheck:
test: ["CMD", "node", "-e", "require('http').get('http://localhost:3000', (r) => {process.exit(r.statusCode === 200 ? 0 : 1)})"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
networks:
- app-network
nginx:
image: registry.667788.cool/wecom-nginx:${TAG:-latest}
ports:
- "80:80"
- "443:443"
volumes:
- ./nginx.conf:/etc/nginx/conf.d/default.conf:ro
depends_on:
- backend
- admin
restart: always
networks:
- app-network
networks:
app-network:
driver: bridge
volumes:
db_data:

View File

@@ -1,36 +1,39 @@
events { worker_connections 1024; }
server {
listen 80;
server_name _;
http {
upstream backend {
server backend:8000;
}
upstream admin {
server admin:3000;
# 后端 API
location /api/ {
proxy_pass http://backend:8000/;
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;
}
server {
listen 80;
server_name _;
# 管理后台
location / {
proxy_pass http://admin:3000/;
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;
# WebSocket 支持(如果需要)
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
# /api -> backend
location /api/ {
proxy_pass http://backend;
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;
}
# 其余 -> admin
location / {
proxy_pass http://admin;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
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;
}
# 健康检查
location /health {
access_log off;
return 200 "healthy\n";
add_header Content-Type text/plain;
}
}

13
deploy/nginx/Dockerfile Normal file
View File

@@ -0,0 +1,13 @@
# Nginx 镜像 Dockerfile
# 用途:构建包含自定义配置的 Nginx 镜像
FROM nginx:alpine
# 复制 Nginx 配置
COPY nginx.conf /etc/nginx/conf.d/default.conf
# 暴露端口
EXPOSE 80 443
# 启动 Nginx
CMD ["nginx", "-g", "daemon off;"]

39
deploy/nginx/nginx.conf Normal file
View File

@@ -0,0 +1,39 @@
server {
listen 80;
server_name _;
# 后端 API
location /api/ {
proxy_pass http://backend:8000/;
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 / {
proxy_pass http://admin:3000/;
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;
# WebSocket 支持(如果需要)
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
# 健康检查
location /health {
access_log off;
return 200 "healthy\n";
add_header Content-Type text/plain;
}
}