85 lines
2.7 KiB
YAML
85 lines
2.7 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
|
|
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
|
|
|
|
# 部署测试环境
|
|
- 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 stop platform-backend-test platform-frontend-test || true
|
|
- docker rm platform-backend-test platform-frontend-test || true
|
|
- docker run -d --name platform-backend-test -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 -p 3002:80 --restart unless-stopped platform-frontend: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
|
|
API_KEY:
|
|
from_secret: api_key
|
|
JWT_SECRET:
|
|
from_secret: jwt_secret
|
|
CONFIG_ENCRYPT_KEY:
|
|
from_secret: config_encrypt_key
|
|
commands:
|
|
- 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 4002:80 --restart unless-stopped platform-frontend:latest
|
|
when:
|
|
branch:
|
|
- main
|
|
|
|
volumes:
|
|
- name: docker-sock
|
|
host:
|
|
path: /var/run/docker.sock
|