refactor: 改造 CI/CD 使用阿里云 ACR 镜像仓库
All checks were successful
continuous-integration/drone/push Build is passing

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-02-03 17:15:04 +08:00
parent facb854e3d
commit 28baed1cad

View File

@@ -1,6 +1,6 @@
kind: pipeline kind: pipeline
type: docker type: docker
name: build-and-deploy name: build-and-push
trigger: trigger:
branch: branch:
@@ -10,88 +10,66 @@ trigger:
- push - push
steps: steps:
# 构建后端镜像 # 构建并推送后端镜像
- name: build-backend - name: build-push-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 image: docker:dind
volumes: volumes:
- name: docker-sock - name: docker-sock
path: /var/run/docker.sock path: /var/run/docker.sock
environment: environment:
DATABASE_URL: DOCKER_REGISTRY:
from_secret: database_url from_secret: docker_registry
API_KEY: DOCKER_USERNAME:
from_secret: api_key from_secret: docker_username
JWT_SECRET: DOCKER_PASSWORD:
from_secret: jwt_secret from_secret: docker_password
CONFIG_ENCRYPT_KEY:
from_secret: config_encrypt_key
commands: commands:
- docker network create platform-network 2>/dev/null || true - echo "$DOCKER_PASSWORD" | docker login "$DOCKER_REGISTRY" -u "$DOCKER_USERNAME" --password-stdin
- docker stop platform-backend-test platform-frontend-test || true - docker build -t $DOCKER_REGISTRY/ireborn/platform-backend:${DRONE_BRANCH} -f deploy/Dockerfile.backend .
- docker rm platform-backend-test platform-frontend-test || true - docker tag $DOCKER_REGISTRY/ireborn/platform-backend:${DRONE_BRANCH} $DOCKER_REGISTRY/ireborn/platform-backend:latest
- 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 tag $DOCKER_REGISTRY/ireborn/platform-backend:${DRONE_BRANCH} $DOCKER_REGISTRY/ireborn/platform-backend:${DRONE_COMMIT_SHA:0:8}
- docker run -d --name platform-frontend-test --network platform-network -p 3003:80 --restart unless-stopped platform-frontend-test:latest - docker push $DOCKER_REGISTRY/ireborn/platform-backend:${DRONE_BRANCH}
when: - docker push $DOCKER_REGISTRY/ireborn/platform-backend:latest
branch: - docker push $DOCKER_REGISTRY/ireborn/platform-backend:${DRONE_COMMIT_SHA:0:8}
- develop
# 部署生产环境(使用独立的生产数据库 # 构建并推送前端镜像(测试环境
- name: deploy-prod - name: build-push-frontend-test
image: docker:dind image: docker:dind
volumes: volumes:
- name: docker-sock - name: docker-sock
path: /var/run/docker.sock path: /var/run/docker.sock
environment: environment:
DATABASE_URL: DOCKER_REGISTRY:
from_secret: database_url_prod from_secret: docker_registry
API_KEY: DOCKER_USERNAME:
from_secret: api_key from_secret: docker_username
JWT_SECRET: DOCKER_PASSWORD:
from_secret: jwt_secret from_secret: docker_password
CONFIG_ENCRYPT_KEY:
from_secret: config_encrypt_key
commands: commands:
- docker network create platform-network-prod 2>/dev/null || true - echo "$DOCKER_PASSWORD" | docker login "$DOCKER_REGISTRY" -u "$DOCKER_USERNAME" --password-stdin
- docker stop platform-backend-prod platform-frontend-prod || true - docker build -t $DOCKER_REGISTRY/ireborn/platform-frontend:develop -f deploy/Dockerfile.frontend --build-arg BACKEND_HOST=platform-backend-test .
- docker rm platform-backend-prod platform-frontend-prod || true - docker push $DOCKER_REGISTRY/ireborn/platform-frontend:develop
- 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 when:
- docker run -d --name platform-frontend-prod --network platform-network-prod -p 4003:80 --restart unless-stopped platform-frontend-prod:latest branch:
- develop
# 构建并推送前端镜像(生产环境)
- name: build-push-frontend-prod
image: docker:dind
volumes:
- name: docker-sock
path: /var/run/docker.sock
environment:
DOCKER_REGISTRY:
from_secret: docker_registry
DOCKER_USERNAME:
from_secret: docker_username
DOCKER_PASSWORD:
from_secret: docker_password
commands:
- echo "$DOCKER_PASSWORD" | docker login "$DOCKER_REGISTRY" -u "$DOCKER_USERNAME" --password-stdin
- docker build -t $DOCKER_REGISTRY/ireborn/platform-frontend:main -f deploy/Dockerfile.frontend --build-arg BACKEND_HOST=platform-backend-prod .
- docker push $DOCKER_REGISTRY/ireborn/platform-frontend:main
when: when:
branch: branch:
- main - main