|
| 1 | +name: Deploy to Cloud Run |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_run: |
| 5 | + workflows: ["CI"] |
| 6 | + types: |
| 7 | + - completed |
| 8 | + branches: [main] |
| 9 | + workflow_dispatch: |
| 10 | + |
| 11 | +env: |
| 12 | + REGION: europe-west4 |
| 13 | + SERVICE_NAME: cityjson-spec-mcp |
| 14 | + GAR_LOCATION: europe-west4 |
| 15 | + GAR_REPOSITORY: cityjson-spec-mcp |
| 16 | + |
| 17 | +jobs: |
| 18 | + build-and-push: |
| 19 | + name: Build and Push Docker Image |
| 20 | + runs-on: ubuntu-latest |
| 21 | + if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' }} |
| 22 | + permissions: |
| 23 | + contents: read |
| 24 | + packages: write |
| 25 | + id-token: write |
| 26 | + |
| 27 | + steps: |
| 28 | + - name: Checkout repository |
| 29 | + uses: actions/checkout@v4 |
| 30 | + with: |
| 31 | + submodules: recursive |
| 32 | + |
| 33 | + - name: Set up Docker Buildx |
| 34 | + uses: docker/setup-buildx-action@v3 |
| 35 | + |
| 36 | + - name: Google Auth |
| 37 | + id: auth |
| 38 | + uses: google-github-actions/auth@v2 |
| 39 | + with: |
| 40 | + workload_identity_provider: ${{ secrets.WIF_PROVIDER }} |
| 41 | + project_id: ${{ secrets.PROJECT_ID }} |
| 42 | + |
| 43 | + - name: Set up Cloud SDK |
| 44 | + uses: google-github-actions/setup-gcloud@v2 |
| 45 | + |
| 46 | + - name: Configure Docker for Artifact Registry |
| 47 | + run: gcloud auth configure-docker ${{ env.GAR_LOCATION }}-docker.pkg.dev |
| 48 | + |
| 49 | + - name: Build and push container |
| 50 | + run: |- |
| 51 | + # Build the image |
| 52 | + docker build -t "${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ secrets.PROJECT_ID }}/${{ env.GAR_REPOSITORY }}/${{ env.SERVICE_NAME }}:${{ github.sha }}" . |
| 53 | +
|
| 54 | + # Tag as latest |
| 55 | + docker tag "${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ secrets.PROJECT_ID }}/${{ env.GAR_REPOSITORY }}/${{ env.SERVICE_NAME }}:${{ github.sha }}" "${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ secrets.PROJECT_ID }}/${{ env.GAR_REPOSITORY }}/${{ env.SERVICE_NAME }}:latest" |
| 56 | +
|
| 57 | + # Push both tags |
| 58 | + docker push "${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ secrets.PROJECT_ID }}/${{ env.GAR_REPOSITORY }}/${{ env.SERVICE_NAME }}:${{ github.sha }}" |
| 59 | + docker push "${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ secrets.PROJECT_ID }}/${{ env.GAR_REPOSITORY }}/${{ env.SERVICE_NAME }}:latest" |
| 60 | +
|
| 61 | + - name: Verify image push |
| 62 | + run: |- |
| 63 | + echo "Verifying image was pushed successfully..." |
| 64 | + gcloud artifacts docker images list ${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ secrets.PROJECT_ID }}/${{ env.GAR_REPOSITORY }} --include-tags --filter="tags:latest" |
| 65 | +
|
| 66 | + deploy: |
| 67 | + name: Deploy to Cloud Run |
| 68 | + needs: build-and-push |
| 69 | + runs-on: ubuntu-latest |
| 70 | + permissions: |
| 71 | + contents: read |
| 72 | + id-token: write |
| 73 | + |
| 74 | + steps: |
| 75 | + - name: Checkout |
| 76 | + uses: actions/checkout@v4 |
| 77 | + |
| 78 | + - name: Google Auth |
| 79 | + id: auth |
| 80 | + uses: google-github-actions/auth@v2 |
| 81 | + with: |
| 82 | + workload_identity_provider: ${{ secrets.WIF_PROVIDER }} |
| 83 | + project_id: ${{ secrets.PROJECT_ID }} |
| 84 | + |
| 85 | + - name: Set up Cloud SDK |
| 86 | + uses: google-github-actions/setup-gcloud@v2 |
| 87 | + |
| 88 | + - name: Deploy to Cloud Run |
| 89 | + id: deploy |
| 90 | + uses: google-github-actions/deploy-cloudrun@v2 |
| 91 | + with: |
| 92 | + service: ${{ env.SERVICE_NAME }} |
| 93 | + region: ${{ env.REGION }} |
| 94 | + image: ${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ secrets.PROJECT_ID }}/${{ env.GAR_REPOSITORY }}/${{ env.SERVICE_NAME }}:latest |
| 95 | + flags: | |
| 96 | + --port=8080 |
| 97 | + --min-instances=0 |
| 98 | + --max-instances=3 |
| 99 | + --cpu=1 |
| 100 | + --memory=256Mi |
| 101 | + --timeout=300 |
| 102 | + --allow-unauthenticated |
| 103 | +
|
| 104 | + - name: Show deployed URL |
| 105 | + run: echo "Deployed to ${{ steps.deploy.outputs.url }}" |
0 commit comments