Files
000-platform/.drone.yml
Admin 82ac147762
All checks were successful
continuous-integration/drone/push Build is passing
feat: 生产环境使用独立数据库
- 创建生产数据库 new_platform_prod
- 配置使用 database_url_prod secret
2026-01-24 17:50:23 +08:00

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
JWT_SECRET:
from_secret: jwt_secret
CONFIG_ENCRYPT_KEY:
from_secret: config_encrypt_key
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