Deploy #2
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: | |
| workflow_run: | |
| workflows: ["CI"] | |
| branches: [main] | |
| types: | |
| - completed | |
| jobs: | |
| deploy: | |
| name: Deploy to Production | |
| runs-on: ubuntu-latest | |
| if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Log in to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build and push backend image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: ./backend | |
| push: true | |
| tags: ghcr.io/${{ github.repository }}/backend:latest | |
| - name: Deploy backend | |
| run: echo "Deploying backend to hosting provider..." | |
| # Replace with actual deploy command, e.g., Fly.io: | |
| # flyctl deploy --image ghcr.io/${{ github.repository }}/backend:latest | |
| env: | |
| DEPLOY_TOKEN: ${{ secrets.DEPLOY_TOKEN }} | |
| - name: Setup Node.js for migrations | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| - name: Run DB migrations | |
| env: | |
| DATABASE_URL: ${{ secrets.DATABASE_URL }} | |
| run: node migrate.js | |
| - name: Deploy frontend | |
| run: echo "Deploying frontend to static hosting..." | |
| # Replace with actual deploy action, e.g., Vercel: | |
| # npx vercel --prod --token ${{ secrets.VERCEL_TOKEN }} | |
| - name: Post deploy status to Slack | |
| uses: 8398a7/action-slack@v3 | |
| with: | |
| status: ${{ job.status }} | |
| text: Deployment to production completed. | |
| env: | |
| SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} | |
| if: always() |