From 961cff99086c63729fe3bcc9b1f101f52680cffc Mon Sep 17 00:00:00 2001 From: DeOwl Date: Sun, 24 May 2026 22:49:35 +0300 Subject: [PATCH] added automatic deployment --- .gitea/workflows/deploy-remote.yml | 68 ++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 .gitea/workflows/deploy-remote.yml diff --git a/.gitea/workflows/deploy-remote.yml b/.gitea/workflows/deploy-remote.yml new file mode 100644 index 0000000..692f3c7 --- /dev/null +++ b/.gitea/workflows/deploy-remote.yml @@ -0,0 +1,68 @@ +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 }} + COMPOSE_PATH: /usr/local/share/vkrb/quantum_backend # Path to docker-compose.yml on remote server + +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 }} + 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