fix: 移除 artifact 传递,合并 build+deploy jobs 兼容 Gitea Actions
This commit is contained in:
parent
567613aa6b
commit
d8f30e8362
@ -2,8 +2,10 @@
|
|||||||
# Duoqi API - 双分支工作流(develop → main)
|
# Duoqi API - 双分支工作流(develop → main)
|
||||||
#
|
#
|
||||||
# 工作流:
|
# 工作流:
|
||||||
# develop push → quality → test → build → 自动部署测试环境
|
# develop push → quality → test → 构建并自动部署测试环境
|
||||||
# main push → quality → test → build → 手动确认部署生产环境
|
# main push → quality → test → 构建并手动确认部署生产环境
|
||||||
|
#
|
||||||
|
# 注意:单服务器架构,构建后直接部署,无需 artifact 传递
|
||||||
|
|
||||||
name: CI/CD Pipeline
|
name: CI/CD Pipeline
|
||||||
|
|
||||||
@ -44,70 +46,21 @@ jobs:
|
|||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: bun run test
|
run: bun run test
|
||||||
|
|
||||||
# ==================== 构建测试镜像 ====================
|
# ==================== 构建并部署测试环境(develop 自动触发)====================
|
||||||
build-test:
|
build-and-deploy-test:
|
||||||
name: Build Test Image
|
name: Build & Deploy Test
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: [quality, test]
|
needs: [quality, test]
|
||||||
if: github.ref == 'refs/heads/develop'
|
if: github.ref == 'refs/heads/develop'
|
||||||
steps:
|
|
||||||
- name: Checkout code
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Build test image
|
|
||||||
run: |
|
|
||||||
docker build --build-arg NODE_ENV=test -t duoqi-api:test .
|
|
||||||
mkdir -p /tmp/images
|
|
||||||
docker save duoqi-api:test -o /tmp/images/duoqi-api-test.tar
|
|
||||||
|
|
||||||
- name: Upload image artifact
|
|
||||||
uses: actions/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: docker-images-test
|
|
||||||
path: /tmp/images/
|
|
||||||
retention-days: 1
|
|
||||||
|
|
||||||
# ==================== 构建生产镜像 ====================
|
|
||||||
build-prod:
|
|
||||||
name: Build Production Image
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: [quality, test]
|
|
||||||
if: github.ref == 'refs/heads/main'
|
|
||||||
steps:
|
|
||||||
- name: Checkout code
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Build production image
|
|
||||||
run: |
|
|
||||||
docker build -t duoqi-api:prod .
|
|
||||||
mkdir -p /tmp/images
|
|
||||||
docker save duoqi-api:prod -o /tmp/images/duoqi-api-prod.tar
|
|
||||||
|
|
||||||
- name: Upload image artifact
|
|
||||||
uses: actions/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: docker-images-prod
|
|
||||||
path: /tmp/images/
|
|
||||||
retention-days: 1
|
|
||||||
|
|
||||||
# ==================== 部署到测试环境(develop push 自动触发) ====================
|
|
||||||
deploy-test:
|
|
||||||
name: Deploy to Test
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: build-test
|
|
||||||
if: github.ref == 'refs/heads/develop'
|
|
||||||
environment:
|
environment:
|
||||||
name: test
|
name: test
|
||||||
url: http://test-api.duoqi.me
|
url: http://test-api.duoqi.me
|
||||||
steps:
|
steps:
|
||||||
- name: Download image artifact
|
- name: Checkout code
|
||||||
uses: actions/download-artifact@v4
|
uses: actions/checkout@v4
|
||||||
with:
|
|
||||||
name: docker-images-test
|
|
||||||
path: /tmp/images/
|
|
||||||
|
|
||||||
- name: Load Docker image
|
- name: Build test image
|
||||||
run: docker load -i /tmp/images/duoqi-api-test.tar
|
run: docker build --build-arg NODE_ENV=test -t duoqi-api:test .
|
||||||
|
|
||||||
- name: Deploy test environment
|
- name: Deploy test environment
|
||||||
run: |
|
run: |
|
||||||
@ -128,24 +81,21 @@ jobs:
|
|||||||
echo "Test environment health check failed"
|
echo "Test environment health check failed"
|
||||||
exit 1
|
exit 1
|
||||||
|
|
||||||
# ==================== 部署到生产环境(main push,手动确认) ====================
|
# ==================== 构建并部署生产环境(main 手动确认)====================
|
||||||
deploy-prod:
|
build-and-deploy-prod:
|
||||||
name: Deploy to Production
|
name: Build & Deploy Production
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: build-prod
|
needs: [quality, test]
|
||||||
if: github.ref == 'refs/heads/main'
|
if: github.ref == 'refs/heads/main'
|
||||||
environment:
|
environment:
|
||||||
name: production
|
name: production
|
||||||
url: https://api.duoqi.me
|
url: https://api.duoqi.me
|
||||||
steps:
|
steps:
|
||||||
- name: Download image artifact
|
- name: Checkout code
|
||||||
uses: actions/download-artifact@v4
|
uses: actions/checkout@v4
|
||||||
with:
|
|
||||||
name: docker-images-prod
|
|
||||||
path: /tmp/images/
|
|
||||||
|
|
||||||
- name: Load Docker image
|
- name: Build production image
|
||||||
run: docker load -i /tmp/images/duoqi-api-prod.tar
|
run: docker build -t duoqi-api:prod .
|
||||||
|
|
||||||
- name: Deploy production
|
- name: Deploy production
|
||||||
run: |
|
run: |
|
||||||
@ -178,6 +128,4 @@ jobs:
|
|||||||
|
|
||||||
- name: Cleanup
|
- name: Cleanup
|
||||||
if: always()
|
if: always()
|
||||||
run: |
|
run: docker image prune -f
|
||||||
docker image prune -f
|
|
||||||
rm -rf /tmp/images
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user