chore(ci): deploy docker #418
Workflow file for this run
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: '[Testnet] Api Main' | |
| on: | |
| pull_request: | |
| branches: | |
| - main | |
| push: | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| jobs: | |
| detect-changes: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| changed: ${{ steps.changes.outputs.api-main }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| - name: Detect api-main changes | |
| uses: dorny/paths-filter@v3 | |
| id: changes | |
| with: | |
| filters: | | |
| api-main: | |
| - 'packages/api-main/**' | |
| test: | |
| needs: detect-changes | |
| if: needs.detect-changes.outputs.changed == 'true' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Bun | |
| uses: oven-sh/setup-bun@v2 | |
| with: | |
| bun-version: 1.3.2 | |
| - name: Create Directory | |
| run: mkdir -p ./packages/api-main/data/postgres_data | |
| - name: Install dependencies | |
| run: bun install | |
| - name: Set up Docker | |
| uses: docker/setup-docker-action@v4 | |
| - name: Run Docker Compose Up | |
| working-directory: ./packages/api-main | |
| run: docker compose -f ./docker-compose-github.yml up --build -d --wait --wait-timeout 30 | |
| - name: Wait for database to be ready | |
| working-directory: ./packages/api-main | |
| run: | | |
| until docker exec postgres_db pg_isready -U default; do | |
| sleep 1 | |
| done | |
| - name: Push database migrations | |
| working-directory: ./packages/api-main | |
| run: bun run db:push:force | |
| env: | |
| PG_URI: postgresql://default:password@localhost:5432/postgres | |
| - name: Run tests | |
| working-directory: ./packages/api-main | |
| run: bun run test | |
| env: | |
| NODE_OPTIONS: --experimental-global-webcrypto | |
| PG_URI: postgresql://default:password@localhost:5432/postgres | |
| JWT: default_jwt_secret | |
| JWT_STRICTNESS: lax | |
| AUTH: whatever | |
| build: | |
| needs: [detect-changes, test] | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' && needs.detect-changes.outputs.changed == 'true' | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| id-token: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| - name: Set short SHA | |
| id: sha_short | |
| run: echo "value=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT | |
| - name: Auth GCloud | |
| uses: google-github-actions/auth@v2 | |
| with: | |
| workload_identity_provider: ${{ secrets.WORKLOAD_IDENTITY_PROVIDER }} | |
| service_account: ${{ secrets.SERVICE_ACCOUNT }} | |
| - name: Set up Cloud SDK | |
| uses: google-github-actions/setup-gcloud@v3 | |
| - name: Configure Docker | |
| run: gcloud auth configure-docker ${{ secrets.REGION }}-docker.pkg.dev --quiet | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Build and push | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: ./packages/api-main/Dockerfile | |
| push: true | |
| tags: | |
| ${{ secrets.REGION }}-docker.pkg.dev/${{ secrets.PROJECT_ID }}/dither-chat/api-main:${{ steps.sha_short.outputs.value }} | |
| notify: | |
| needs: [build] | |
| if: failure() && needs.build.result != 'skipped' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: appleboy/telegram-action@v1.0.1 | |
| with: | |
| to: ${{ secrets.TELEGRAM_TO }} | |
| token: ${{ secrets.TELEGRAM_BOT_TOKEN }} | |
| format: markdown | |
| message: | | |
| 🚨 *API Testnet Build Failed* 🚨 | |
| 🔗 *Repository*: [${{ github.repository }}](https://github.com/${{ github.repository }}) | |
| 📝 *Commit*: ${{ github.event.commits[0].message }} | |
| 👤 *Author*: ${{ github.actor }} | |
| ⛓️💥 *App*: ${{ inputs.app_name }} | |
| 🔍 [View Logs](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) | |
| Please investigate and fix *ASAP*! 🔧 |