diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index 32ab63f..82f23c3 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -2,8 +2,10 @@ # Duoqi API - 双分支工作流(develop → main) # # 工作流: -# develop push → quality → test → build → 自动部署测试环境 -# main push → quality → test → build → 手动确认部署生产环境 +# develop push → quality → test → 构建并自动部署测试环境 +# main push → quality → test → 构建并手动确认部署生产环境 +# +# 注意:单服务器架构,构建后直接部署,无需 artifact 传递 name: CI/CD Pipeline @@ -44,70 +46,21 @@ jobs: - name: Run tests run: bun run test - # ==================== 构建测试镜像 ==================== - build-test: - name: Build Test Image + # ==================== 构建并部署测试环境(develop 自动触发)==================== + build-and-deploy-test: + name: Build & Deploy Test runs-on: ubuntu-latest needs: [quality, test] 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: name: test url: http://test-api.duoqi.me steps: - - name: Download image artifact - uses: actions/download-artifact@v4 - with: - name: docker-images-test - path: /tmp/images/ + - name: Checkout code + uses: actions/checkout@v4 - - name: Load Docker image - run: docker load -i /tmp/images/duoqi-api-test.tar + - name: Build test image + run: docker build --build-arg NODE_ENV=test -t duoqi-api:test . - name: Deploy test environment run: | @@ -128,24 +81,21 @@ jobs: echo "Test environment health check failed" exit 1 - # ==================== 部署到生产环境(main push,手动确认) ==================== - deploy-prod: - name: Deploy to Production + # ==================== 构建并部署生产环境(main 手动确认)==================== + build-and-deploy-prod: + name: Build & Deploy Production runs-on: ubuntu-latest - needs: build-prod + needs: [quality, test] if: github.ref == 'refs/heads/main' environment: name: production url: https://api.duoqi.me steps: - - name: Download image artifact - uses: actions/download-artifact@v4 - with: - name: docker-images-prod - path: /tmp/images/ + - name: Checkout code + uses: actions/checkout@v4 - - name: Load Docker image - run: docker load -i /tmp/images/duoqi-api-prod.tar + - name: Build production image + run: docker build -t duoqi-api:prod . - name: Deploy production run: | @@ -178,6 +128,4 @@ jobs: - name: Cleanup if: always() - run: | - docker image prune -f - rm -rf /tmp/images + run: docker image prune -f