Merge pull request #9 from prinzpiuz/infra_setup #8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - "public/**" | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up SSH | |
| uses: webfactory/ssh-agent@v0.9.1 | |
| with: | |
| ssh-private-key: ${{ secrets.VPS_SSH_KEY }} | |
| - name: Copy files to Server | |
| run: | | |
| rsync -avz --delete \ | |
| --filter='P /.env' \ | |
| --filter='P /caddy_data/' \ | |
| --filter='P /caddy_config/' \ | |
| ./public/ ${{ secrets.VPS_USER }}@${{ secrets.VPS_HOST }}:~/Druv/ | |
| env: | |
| RSYNC_RSH: "ssh -o StrictHostKeyChecking=no" | |
| - name: Deploy on Server | |
| run: | | |
| ssh -o StrictHostKeyChecking=no ${{ secrets.VPS_USER }}@${{ secrets.VPS_HOST }} << 'EOF' | |
| cd ~/Druv/ | |
| docker compose pull | |
| docker compose up -d --remove-orphans | |
| EOF | |
| - name: Deployment Complete | |
| if: success() | |
| uses: appleboy/telegram-action@master | |
| with: | |
| to: ${{ secrets.TELEGRAM_TO }} | |
| token: ${{ secrets.TELEGRAM_TOKEN }} | |
| message: | | |
| Public Services Deployed Successfully! | |
| - name: Deployment Failed | |
| if: failure() | |
| uses: appleboy/telegram-action@master | |
| with: | |
| to: ${{ secrets.TELEGRAM_TO }} | |
| token: ${{ secrets.TELEGRAM_TOKEN }} | |
| message: | | |
| Alert! Deployment Failed for Druv Setup Scripts. | |
| Please check the GitHub Actions logs for more details. | |
| - name: Clean up old deployments | |
| if: success() | |
| run: | | |
| ssh -o StrictHostKeyChecking=no ${{ secrets.VPS_USER }}@${{ secrets.VPS_HOST }} << 'EOF' | |
| docker system prune -f | |
| EOF |