Deploy Production #7
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 Production | |
| on: | |
| workflow_run: | |
| workflows: ["CI"] | |
| branches: [main] | |
| types: | |
| - completed | |
| jobs: | |
| deploy: | |
| if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Deploy to VPS | |
| uses: appleboy/ssh-action@v1.0.3 | |
| with: | |
| host: ${{ secrets.VPS_HOST }} | |
| username: ${{ secrets.VPS_USER }} | |
| key: ${{ secrets.VPS_SSH_KEY }} | |
| port: ${{ secrets.VPS_PORT }} | |
| script: | | |
| set -e | |
| cd Hs_codes_api | |
| echo "Pulling latest code..." | |
| git pull origin main | |
| echo "Building and starting containers..." | |
| docker compose up -d --build | |
| echo "Waiting for application to start..." | |
| sleep 15 | |
| echo "Running migrations..." | |
| docker compose exec -T web python manage.py migrate --noinput | |
| echo "Checking health endpoint..." | |
| for i in $(seq 1 20); do | |
| if curl -fsS http://localhost:8001/api/v1/health/ > /dev/null; then | |
| echo "Health check passed" | |
| exit 0 | |
| fi | |
| echo "Attempt $i/20 — waiting..." | |
| sleep 5 | |
| done | |
| echo "Health check failed after 100s" | |
| exit 1 |