Deploy de uma app para o Google Cloud Run usando Github Actions.

Gere uma credencial para a Service Account com as permissões Permissões para deploy do Google Cloud Run

 
name: "Build and Deploy to Cloud Run"
 
on:
  push:
    branches:
      - main
    paths:
      - 'mysubdir/**'
 
jobs:
  build-and-deploy:
    runs-on: ubuntu-latest
 
    steps:
    - name: Checkout Code
      uses: actions/checkout@v4
 
    - name: 'Setup gcloud env'
      uses: google-github-actions/auth@v2.1.5
      with:
        project_id: ${{ vars.GCP_PROJECT_ID }}
        credentials_json: ${{ secrets.GCP_SA_CREDS_JSON }}
 
    - name: Authenticate Docker to Artifact Registry
      run: |
        gcloud auth configure-docker us-central1-docker.pkg.dev
 
    - name: Build the Docker image
      run: |
        docker build -t us-central1-docker.pkg.dev/${{ vars.GCP_PROJECT_ID }}/repo/appname:main ./mysubdir
 
    - name: Push Docker image to Artifact Registry
      run: |
        docker push us-central1-docker.pkg.dev/${{ vars.GCP_PROJECT_ID }}/repo/appname:main
 
    - name: Deploy to Cloud Run
      run: |
        gcloud run deploy my-app \
          --image us-central1-docker.pkg.dev/${{ vars.GCP_PROJECT_ID }}/repo/appname:main \
          --platform managed \
          --region us-central1 \
          --allow-unauthenticated