Deploy chat backend to Cloud Run #10
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-chat-backend | |
| run-name: Deploy chat backend to Cloud Run | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - 'chat-backend/**' | |
| workflow_dispatch: | |
| env: | |
| PROJECT_ID: chipflow-platform | |
| REGION: us-central1 | |
| SERVICE_NAME: chipflow-docs-chat | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| id-token: write # Required for Workload Identity Federation | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Authenticate to Google Cloud | |
| id: auth | |
| uses: google-github-actions/auth@v2 | |
| with: | |
| workload_identity_provider: ${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }} | |
| service_account: ${{ secrets.GCP_SERVICE_ACCOUNT }} | |
| - name: Set up Cloud SDK | |
| uses: google-github-actions/setup-gcloud@v2 | |
| - name: Configure Docker for GCR | |
| run: gcloud auth configure-docker --quiet | |
| - name: Build and push container | |
| working-directory: chat-backend | |
| run: | | |
| docker build -t gcr.io/$PROJECT_ID/$SERVICE_NAME:${{ github.sha }} \ | |
| -t gcr.io/$PROJECT_ID/$SERVICE_NAME:latest . | |
| docker push gcr.io/$PROJECT_ID/$SERVICE_NAME:${{ github.sha }} | |
| docker push gcr.io/$PROJECT_ID/$SERVICE_NAME:latest | |
| - name: Deploy to Cloud Run | |
| run: | | |
| gcloud run deploy $SERVICE_NAME \ | |
| --image gcr.io/$PROJECT_ID/$SERVICE_NAME:${{ github.sha }} \ | |
| --region $REGION \ | |
| --platform managed \ | |
| --allow-unauthenticated \ | |
| --memory 1Gi \ | |
| --cpu 1 \ | |
| --min-instances 0 \ | |
| --max-instances 3 \ | |
| --set-env-vars "DOCS_URL=https://chipflow-docs.docs.chipflow-infra.com/llms-full.txt,GCP_PROJECT=$PROJECT_ID,GCP_LOCATION=$REGION,GEMINI_API_KEY=${{ secrets.GEMINI_API_KEY }}" | |
| - name: Show service URL | |
| run: | | |
| URL=$(gcloud run services describe $SERVICE_NAME --region $REGION --format='value(status.url)') | |
| echo "## Deployed to Cloud Run" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "Service URL: $URL" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "Update \`chat-widget.js\` with:" >> $GITHUB_STEP_SUMMARY | |
| echo "\`\`\`javascript" >> $GITHUB_STEP_SUMMARY | |
| echo "apiUrl: '${URL}/api/chat'" >> $GITHUB_STEP_SUMMARY | |
| echo "\`\`\`" >> $GITHUB_STEP_SUMMARY |