Files
quantum_backend/.gitea/workflows/deploy-remote.yml
deowl a118cf49a4
Some checks failed
Build and Deploy Docker Image / build-and-push (push) Has been cancelled
Update .gitea/workflows/deploy-remote.yml
2026-05-24 19:56:43 +00:00

71 lines
2.0 KiB
YAML

name: Deploy to Remote Server
on:
# Trigger after successful build (using workflow_run)
workflow_run:
workflows: ["Build and Deploy Docker Image"]
types:
- completed
branches: ["main"]
# Allow manual trigger for redeployment
workflow_dispatch:
inputs:
image_tag:
description: "Image tag to deploy (default: latest)"
required: false
default: "latest"
env:
GITEA_INSTANCE_URL: git.deowl.ru
IMAGE_NAME: vkrb/quantum_backend
REMOTE_HOST: ${{ secrets.REMOTE_HOST }}
REMOTE_USER: ${{ secrets.REMOTE_USER }}
REMOTE_PORT: ${{ secrets.REMOTE_PORT }} # Add this
COMPOSE_PATH: /usr/local/share/vkrb/quantum_backend
jobs:
deploy:
# Only run if the build workflow succeeded
if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' }}
runs-on: ubuntu-latest
steps:
- name: Deploy via SSH
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.REMOTE_HOST }}
port: ${{ secrets.REMOTE_PORT }} # Add this line
username: ${{ secrets.REMOTE_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script_stop: true
script: |
cd ${{ env.COMPOSE_PATH }}
# Get the tag to deploy
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
TAG="${{ github.event.inputs.image_tag }}"
else
TAG="${{ github.event.workflow_run.head_sha }}"
fi
# Use 'latest' if no specific tag
if [ -z "$TAG" ]; then
TAG="latest"
fi
echo "Deploying tag: $TAG"
# Method 1: Using environment variable (recommended)
export IMAGE_TAG=$TAG
docker compose pull app # Pull only the app service
# Redeploy with the new image
docker compose up -d --no-deps --force-recreate app
# Clean up old images
docker image prune -f
# Check container status
docker compose ps