name: Deploy to Production
on:
  push:
    branches:
      - main
      - master

jobs:
  deploy:
    name: Deploy to Production
    needs: build_and_push
    runs-on: ubuntu-latest
    if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
    environment: production
    steps:
    - name: Deploy to Server
      uses: appleboy/ssh-action@v0.1.5
      with:
        host: ${{ secrets.SERVER_HOST }}
        username: ${{ secrets.SERVER_USERNAME }}
        key: ${{ secrets.SERVER_SSH_KEY }}
        port: ${{ secrets.SERVER_PORT }}
        script: |
          whoami

          cd /home/wesal
          
          git pull origin main
          
          docker compose down
          
          docker compose up -d --build
          
          docker image prune -f