fix: use private ghcr.io with Render registry credential for deployment #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 to Render | |
| on: | |
| push: | |
| branches: [main] | |
| workflow_dispatch: | |
| concurrency: | |
| group: deploy | |
| cancel-in-progress: true | |
| env: | |
| REGISTRY: ghcr.io | |
| IMAGE_PREFIX: ghcr.io/${{ github.repository_owner }}/northwoods | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| strategy: | |
| matrix: | |
| include: | |
| - name: api | |
| dockerfile: src/Services/Northwoods.Api/Dockerfile | |
| context: src/ | |
| render_service_id: srv-d73ber19fqoc73ci2l60 | |
| - name: worker | |
| dockerfile: src/Workers/Extraction.Worker/Dockerfile | |
| context: src/ | |
| render_service_id: srv-d73bervkijhs73dee48g | |
| - name: web | |
| dockerfile: apps/web/Dockerfile | |
| context: . | |
| render_service_id: srv-d73bhic2kvos738c3t6g | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: docker/setup-buildx-action@v3 | |
| - uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - uses: docker/build-push-action@v5 | |
| with: | |
| context: ${{ matrix.context }} | |
| file: ${{ matrix.dockerfile }} | |
| platforms: linux/amd64 | |
| push: true | |
| tags: ${{ env.IMAGE_PREFIX }}-${{ matrix.name }}:latest,${{ env.IMAGE_PREFIX }}-${{ matrix.name }}:${{ github.sha }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| - name: Update Render service image | |
| env: | |
| RENDER_API_KEY: ${{ secrets.RENDER_API_KEY }} | |
| run: | | |
| IMAGE="${{ env.IMAGE_PREFIX }}-${{ matrix.name }}:latest" | |
| echo "Updating ${{ matrix.render_service_id }} to $IMAGE" | |
| # Render credential rgc-d73tmlnfte5s73b88010 handles ghcr.io auth | |
| curl -sf -X PATCH \ | |
| "https://api.render.com/v1/services/${{ matrix.render_service_id }}" \ | |
| -H "Authorization: Bearer $RENDER_API_KEY" \ | |
| -H "Content-Type: application/json" \ | |
| -d "{\"image\": {\"imagePath\": \"$IMAGE\", \"registryCredentialId\": \"rgc-d73tmlnfte5s73b88010\"}}" \ | |
| | jq -r '.name // "updated"' | |
| deploy: | |
| needs: build-and-push | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Trigger Render deploys | |
| env: | |
| RENDER_API_KEY: ${{ secrets.RENDER_API_KEY }} | |
| run: | | |
| for SVC in srv-d73ber19fqoc73ci2l60 srv-d73bervkijhs73dee48g srv-d73bhic2kvos738c3t6g; do | |
| echo "Deploying $SVC..." | |
| curl -sf -X POST "https://api.render.com/v1/services/$SVC/deploys" \ | |
| -H "Authorization: Bearer $RENDER_API_KEY" \ | |
| -H "Content-Type: application/json" \ | |
| -d '{"clearCache":"do_not_clear"}' \ | |
| | jq -r '.id // "triggered"' | |
| done | |
| - name: Wait for deploys | |
| env: | |
| RENDER_API_KEY: ${{ secrets.RENDER_API_KEY }} | |
| run: | | |
| echo "Waiting for services to go live..." | |
| for attempt in $(seq 1 30); do | |
| sleep 15 | |
| ALL_LIVE=true | |
| for SVC in srv-d73ber19fqoc73ci2l60 srv-d73bervkijhs73dee48g srv-d73bhic2kvos738c3t6g; do | |
| STATUS=$(curl -sf -H "Authorization: Bearer $RENDER_API_KEY" \ | |
| "https://api.render.com/v1/services/$SVC/deploys?limit=1" \ | |
| | jq -r '.[0].deploy.status') | |
| if [ "$STATUS" != "live" ]; then | |
| ALL_LIVE=false | |
| fi | |
| done | |
| if [ "$ALL_LIVE" = "true" ]; then | |
| echo "All services live!" | |
| exit 0 | |
| fi | |
| echo "Attempt $attempt: not all live yet..." | |
| done | |
| echo "Timeout waiting for deploys" && exit 1 |