Fix deploy-backend workflow: separate build and deploy phases

- Build & push images: Only on PR creation/updates (not on merge)
- Deploy to production: Only on merge to main branch or manual trigger
- Improved workflow clarity with emojis and better step descriptions
- Added deployment progress logging for better visibility
- Fixed workflow logic to prevent unnecessary builds on merge

This ensures:
 PR creates/updates → Build and push Docker images
 Merge to main → Deploy using pre-built images
 Manual deployment → Deploy latest images

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
pull/21891/head
ytqh 11 months ago
parent 816ea24571
commit b399b573c1

@ -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
echo "🔄 Restarting services..."
docker compose up -d --force-recreate nginx web api worker scheduler
echo "✅ Deployment completed successfully!"
Loading…
Cancel
Save