diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index f17b0e1..cf3aa95 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -20,6 +20,8 @@ jobs: name: build and push image runs-on: ubuntu-latest timeout-minutes: 30 + outputs: + version: ${{ steps.meta.outputs.version }} steps: - name: Checkout uses: actions/checkout@v6 @@ -64,4 +66,47 @@ jobs: labels: ${{ steps.meta.outputs.labels }} cache-from: type=gha cache-to: type=gha,mode=max - provenance: false \ No newline at end of file + provenance: false + + deploy: + name: deploy to VPS + needs: release + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - name: Checkout + uses: actions/checkout@v6 + + - name: Copy compose file to VPS + uses: appleboy/scp-action@v1 + with: + host: ${{ secrets.VPS_HOST }} + username: ${{ secrets.VPS_USER }} + key: ${{ secrets.VPS_SSH_KEY }} + port: ${{ secrets.VPS_PORT || 22 }} + source: "docker/docker-compose.prod.yaml" + target: "${{ secrets.VPS_DEPLOY_PATH }}/" + strip_components: 1 + + - name: Deploy via SSH + uses: appleboy/ssh-action@v1 + env: + BOT_IMAGE: ${{ env.IMAGE_NAME }}:${{ needs.release.outputs.version }} + DEPLOY_PATH: ${{ secrets.VPS_DEPLOY_PATH }} + with: + host: ${{ secrets.VPS_HOST }} + username: ${{ secrets.VPS_USER }} + key: ${{ secrets.VPS_SSH_KEY }} + port: ${{ secrets.VPS_PORT || 22 }} + envs: BOT_IMAGE,DEPLOY_PATH + script: | + set -euo pipefail + cd "$DEPLOY_PATH" + + echo "Deploying image: $BOT_IMAGE" + + docker compose -f docker-compose.prod.yaml pull + docker compose -f docker-compose.prod.yaml up -d --remove-orphans + + docker compose -f docker-compose.prod.yaml ps + docker image prune -f \ No newline at end of file