All checks were successful
continuous-integration/drone/push Build is passing
- 分离测试/生产环境的前端镜像构建 - nginx 配置使用 BACKEND_HOST 变量区分环境 - 生产环境添加独立的 Docker network - 生产环境使用独立的密钥配置 (xxx_prod) - 修复前端空白问题:确保前后端在同一 network
103 lines
3.5 KiB
YAML
103 lines
3.5 KiB
YAML
kind: pipeline
|
|
type: docker
|
|
name: build-and-deploy
|
|
|
|
trigger:
|
|
branch:
|
|
- main
|
|
- develop
|
|
event:
|
|
- push
|
|
|
|
steps:
|
|
# 构建后端镜像
|
|
- name: build-backend
|
|
image: docker:dind
|
|
volumes:
|
|
- name: docker-sock
|
|
path: /var/run/docker.sock
|
|
commands:
|
|
- 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-test
|
|
image: docker:dind
|
|
volumes:
|
|
- name: docker-sock
|
|
path: /var/run/docker.sock
|
|
commands:
|
|
- 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
|
|
image: docker:dind
|
|
volumes:
|
|
- name: docker-sock
|
|
path: /var/run/docker.sock
|
|
environment:
|
|
DATABASE_URL:
|
|
from_secret: database_url
|
|
API_KEY:
|
|
from_secret: api_key
|
|
JWT_SECRET:
|
|
from_secret: jwt_secret
|
|
CONFIG_ENCRYPT_KEY:
|
|
from_secret: config_encrypt_key
|
|
commands:
|
|
- docker network create platform-network 2>/dev/null || true
|
|
- 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-test:latest
|
|
when:
|
|
branch:
|
|
- develop
|
|
|
|
# 部署生产环境
|
|
- name: deploy-prod
|
|
image: docker:dind
|
|
volumes:
|
|
- name: docker-sock
|
|
path: /var/run/docker.sock
|
|
environment:
|
|
DATABASE_URL:
|
|
from_secret: database_url_prod
|
|
API_KEY:
|
|
from_secret: api_key_prod
|
|
JWT_SECRET:
|
|
from_secret: jwt_secret_prod
|
|
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 --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
|
|
|
|
volumes:
|
|
- name: docker-sock
|
|
host:
|
|
path: /var/run/docker.sock
|