Merge pull request #5 from Virt92/devin/1777304071-backend-api #5
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 to Hetzner | |
| on: | |
| push: | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| concurrency: | |
| group: deploy-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| build-and-deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| cache: npm | |
| - name: Install frontend dependencies | |
| run: npm ci | |
| - name: Typecheck frontend | |
| run: npm run typecheck | |
| - name: Build frontend | |
| run: npm run build | |
| - name: Set up SSH | |
| run: | | |
| mkdir -p ~/.ssh | |
| echo "${{ secrets.DEPLOY_SSH_KEY }}" > ~/.ssh/deploy_key | |
| chmod 600 ~/.ssh/deploy_key | |
| ssh-keyscan -H ${{ secrets.DEPLOY_HOST }} >> ~/.ssh/known_hosts | |
| - name: Deploy frontend via rsync | |
| run: | | |
| rsync -az --delete \ | |
| -e "ssh -i ~/.ssh/deploy_key -o StrictHostKeyChecking=yes" \ | |
| dist/ \ | |
| ${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }}:${{ secrets.DEPLOY_PATH }}/ | |
| - name: Deploy backend via rsync | |
| run: | | |
| rsync -az --delete \ | |
| --exclude='node_modules' --exclude='dist' \ | |
| -e "ssh -i ~/.ssh/deploy_key -o StrictHostKeyChecking=yes" \ | |
| server/ \ | |
| ${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }}:/opt/pest-control-api/server/ | |
| rsync -az \ | |
| -e "ssh -i ~/.ssh/deploy_key -o StrictHostKeyChecking=yes" \ | |
| docker-compose.yml \ | |
| ${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }}:/opt/pest-control-api/ | |
| - name: Build and restart backend on server | |
| run: | | |
| ssh -i ~/.ssh/deploy_key -o StrictHostKeyChecking=yes \ | |
| ${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }} \ | |
| "cd /opt/pest-control-api && docker compose up -d --build" | |
| - name: Verify site responds | |
| run: | | |
| sleep 5 | |
| curl -fsS -o /dev/null -w "HTTP %{http_code}\n" http://${{ secrets.DEPLOY_HOST }}:8083/ | |
| curl -fsS -o /dev/null -w "API %{http_code}\n" http://${{ secrets.DEPLOY_HOST }}:4000/api/auth/login || true |