@ -1,42 +1,55 @@
name : Deploy Backend API
name : Deploy Backend API
on :
on :
# Build and push on PR creation/update
pull_request:
pull_request:
types : [ closed]
branches:
branches:
- main
- main
- master
- master
types : [ opened, synchronize, reopened]
# Deploy on merge to main
push:
branches:
- main
- master
# Allow manual deployment
workflow_dispatch:
workflow_dispatch:
jobs:
jobs:
build-and-push:
build-and-push:
# Only run if PR was merged or manually triggered
name : 🔨 Build & Push Images (PR Only)
if : github.event_name == 'workflow_dispatch' || (github.event.pull_request.merged == true)
# Only run on PR events (not on push to main)
if : github.event_name == 'pull_request'
runs-on : ubuntu-latest
runs-on : ubuntu-latest
steps:
steps:
- name : Checkout code
- name : 📥 Checkout code
uses : actions/checkout@v4
uses : actions/checkout@v4
- name : Set up Docker Buildx
- name : 🔧 Set up Docker Buildx
uses : docker/setup-buildx-action@v3
uses : docker/setup-buildx-action@v3
- name : Login to Docker Hub
- name : 🔐 Login to Docker Hub
uses : docker/login-action@v3
uses : docker/login-action@v3
with:
with:
username : ${{ secrets.DOCKER_USERNAME }}
username : ${{ secrets.DOCKER_USERNAME }}
password : ${{ secrets.DOCKER_PASSWORD }}
password : ${{ secrets.DOCKER_PASSWORD }}
- name : Build and push API image using Makefil e
- name : 🏗️ Build and push API image
run : |
run : |
echo "Building and pushing API image for PR #${{ github.event.number }}"
make build-push-api
make build-push-api
deploy:
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
runs-on : ubuntu-latest
steps:
steps:
- name : Deploy to Production Server
- name : 🚀 Deploy to Production Server
uses : appleboy/ssh-action@v1.0.3
uses : appleboy/ssh-action@v1.0.3
with:
with:
host : qingsu.chat
host : qingsu.chat
@ -44,12 +57,23 @@ jobs:
key : ${{ secrets.SSH_PRIVATE_KEY }}
key : ${{ secrets.SSH_PRIVATE_KEY }}
port : 22
port : 22
script : |
script : |
echo "🚀 Starting deployment to production server..."
cd /root/projects/jim-dify
cd /root/projects/jim-dify
echo "📦 Updating source code..."
git fetch origin
git fetch origin
git reset --hard origin/$(git branch --show-current)
git reset --hard origin/$(git branch --show-current)
echo "🐳 Updating Docker images..."
cd docker
cd docker
export HTTP_PROXY=http://host.docker.internal:1081
export HTTP_PROXY=http://host.docker.internal:1081
export HTTPS_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
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 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!"