diff --git a/.github/workflows/deploy-backend.yml b/.github/workflows/deploy-backend.yml index 8e4f12c5ca..cfe08b2db7 100644 --- a/.github/workflows/deploy-backend.yml +++ b/.github/workflows/deploy-backend.yml @@ -1,42 +1,55 @@ name: Deploy Backend API on: + # Build and push on PR creation/update pull_request: - types: [closed] branches: - main - master + types: [opened, synchronize, reopened] + + # Deploy on merge to main + push: + branches: + - main + - master + + # Allow manual deployment workflow_dispatch: jobs: build-and-push: - # Only run if PR was merged or manually triggered - if: github.event_name == 'workflow_dispatch' || (github.event.pull_request.merged == true) + name: 🔨 Build & Push Images (PR Only) + # Only run on PR events (not on push to main) + if: github.event_name == 'pull_request' runs-on: ubuntu-latest steps: - - name: Checkout code + - name: 📥 Checkout code uses: actions/checkout@v4 - - name: Set up Docker Buildx + - name: 🔧 Set up Docker Buildx uses: docker/setup-buildx-action@v3 - - name: Login to Docker Hub + - name: 🔐 Login to Docker Hub uses: docker/login-action@v3 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - - name: Build and push API image using Makefile + - name: 🏗️ Build and push API image run: | + echo "Building and pushing API image for PR #${{ github.event.number }}" make build-push-api deploy: - needs: build-and-push + name: 🚀 Deploy to Production (Main Branch Only) + # Only run on push to main (merge) or manual trigger + if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' runs-on: ubuntu-latest steps: - - name: Deploy to Production Server + - name: 🚀 Deploy to Production Server uses: appleboy/ssh-action@v1.0.3 with: host: qingsu.chat @@ -44,12 +57,23 @@ jobs: key: ${{ secrets.SSH_PRIVATE_KEY }} port: 22 script: | + echo "🚀 Starting deployment to production server..." cd /root/projects/jim-dify + + echo "📦 Updating source code..." git fetch origin git reset --hard origin/$(git branch --show-current) + + echo "🐳 Updating Docker images..." cd docker export HTTP_PROXY=http://host.docker.internal:1081 export HTTPS_PROXY=http://host.docker.internal:1081 export NO_PROXY=weaviate,sandbox,plugin_daemon,localhost,127.0.0.1 + + # Pull latest images (built from the merged PR) docker compose pull - docker compose up -d --force-recreate nginx web api worker scheduler \ No newline at end of file + + echo "🔄 Restarting services..." + docker compose up -d --force-recreate nginx web api worker scheduler + + echo "✅ Deployment completed successfully!" \ No newline at end of file