fix: 修复 Drone 配置和 nginx 多环境支持
All checks were successful
continuous-integration/drone/push Build is passing

- 分离测试/生产环境的前端镜像构建
- nginx 配置使用 BACKEND_HOST 变量区分环境
- 生产环境添加独立的 Docker network
- 生产环境使用独立的密钥配置 (xxx_prod)
- 修复前端空白问题:确保前后端在同一 network
This commit is contained in:
2026-01-24 17:15:12 +08:00
parent 6c6c48cf71
commit b6b5ac61af
3 changed files with 36 additions and 13 deletions

View File

@@ -20,15 +20,31 @@ steps:
- docker build -t platform-backend:${DRONE_COMMIT_SHA:0:8} -f deploy/Dockerfile.backend .
- docker tag platform-backend:${DRONE_COMMIT_SHA:0:8} platform-backend:latest
# 构建前端镜像
- name: build-frontend
# 构建前端镜像(测试环境)
- name: build-frontend-test
image: docker:dind
volumes:
- name: docker-sock
path: /var/run/docker.sock
commands:
- docker build -t platform-frontend:${DRONE_COMMIT_SHA:0:8} -f deploy/Dockerfile.frontend .
- docker tag platform-frontend:${DRONE_COMMIT_SHA:0:8} platform-frontend:latest
- docker build -t platform-frontend-test:${DRONE_COMMIT_SHA:0:8} -f deploy/Dockerfile.frontend --build-arg BACKEND_HOST=platform-backend-test .
- docker tag platform-frontend-test:${DRONE_COMMIT_SHA:0:8} platform-frontend-test:latest
when:
branch:
- develop
# 构建前端镜像(生产环境)
- name: build-frontend-prod
image: docker:dind
volumes:
- name: docker-sock
path: /var/run/docker.sock
commands:
- docker build -t platform-frontend-prod:${DRONE_COMMIT_SHA:0:8} -f deploy/Dockerfile.frontend --build-arg BACKEND_HOST=platform-backend-prod .
- docker tag platform-frontend-prod:${DRONE_COMMIT_SHA:0:8} platform-frontend-prod:latest
when:
branch:
- main
# 部署测试环境
- name: deploy-test
@@ -50,7 +66,7 @@ steps:
- docker stop platform-backend-test platform-frontend-test || true
- docker rm platform-backend-test platform-frontend-test || true
- docker run -d --name platform-backend-test --network platform-network -p 8001:8000 --restart unless-stopped -e DATABASE_URL=$DATABASE_URL -e API_KEY=$API_KEY -e JWT_SECRET=$JWT_SECRET -e CONFIG_ENCRYPT_KEY=$CONFIG_ENCRYPT_KEY platform-backend:latest
- docker run -d --name platform-frontend-test --network platform-network -p 3003:80 --restart unless-stopped platform-frontend:latest
- docker run -d --name platform-frontend-test --network platform-network -p 3003:80 --restart unless-stopped platform-frontend-test:latest
when:
branch:
- develop
@@ -63,18 +79,19 @@ steps:
path: /var/run/docker.sock
environment:
DATABASE_URL:
from_secret: database_url
from_secret: database_url_prod
API_KEY:
from_secret: api_key
from_secret: api_key_prod
JWT_SECRET:
from_secret: jwt_secret
from_secret: jwt_secret_prod
CONFIG_ENCRYPT_KEY:
from_secret: config_encrypt_key
from_secret: config_encrypt_key_prod
commands:
- docker network create platform-network-prod 2>/dev/null || true
- docker stop platform-backend-prod platform-frontend-prod || true
- docker rm platform-backend-prod platform-frontend-prod || true
- docker run -d --name platform-backend-prod -p 9001:8000 --restart unless-stopped -e DATABASE_URL=$DATABASE_URL -e API_KEY=$API_KEY -e JWT_SECRET=$JWT_SECRET -e CONFIG_ENCRYPT_KEY=$CONFIG_ENCRYPT_KEY platform-backend:latest
- docker run -d --name platform-frontend-prod -p 4003:80 --restart unless-stopped platform-frontend:latest
- docker run -d --name platform-backend-prod --network platform-network-prod -p 9001:8000 --restart unless-stopped -e DATABASE_URL=$DATABASE_URL -e API_KEY=$API_KEY -e JWT_SECRET=$JWT_SECRET -e CONFIG_ENCRYPT_KEY=$CONFIG_ENCRYPT_KEY platform-backend:latest
- docker run -d --name platform-frontend-prod --network platform-network-prod -p 4003:80 --restart unless-stopped platform-frontend-prod:latest
when:
branch:
- main