This commit is contained in:
Заид Омар Медхат 2025-12-25 23:37:32 +05:00
parent bf82ba32b2
commit b2ae0478be

View File

@ -6,7 +6,7 @@ on:
jobs:
deploy_production:
name: Deploy to Production
runs-on: ubuntu-latest
runs-on: self-hosted
environment:
name: production
@ -14,46 +14,11 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install SSH and rsync
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends openssh-client rsync
- name: Configure SSH
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SSH_PRIVATE_KEY }}" | tr -d '\r' > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
- name: Ensure remote directory exists
run: |
ssh -o StrictHostKeyChecking=yes "${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }}" \
"mkdir -p /opt/apps/api-finance"
- name: Sync repository to server
run: |
rsync -az --delete \
--exclude='.git' \
--exclude='.env' \
--exclude='.env.*' \
--exclude='node_modules' \
--exclude='coverage' \
--exclude='dist' \
./ "${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }}:/opt/apps/api-finance/"
- name: Rebuild and restart Docker Compose
run: |
ssh -o StrictHostKeyChecking=yes "${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }}" "
set -e
cd /opt/apps/api-finance
docker compose -f docker-compose.server.yml pull
docker compose -f docker-compose.server.yml up -d --build
docker image prune -f
"
set -e
docker compose -f docker-compose.server.yml up -d --build
- name: Optional: Check service health
- name: 'Optional: Check service health'
run: |
ssh -o StrictHostKeyChecking=yes "${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }}" "
set -e
curl --fail --silent --show-error https://api-finance.ai-assistant-bot.xyz/ || exit 1
"
curl --fail --silent --show-error https://api-finance.ai-assistant-bot.xyz/ || exit 1