How to Deploy a Container to Cloud Run From Source in GitHub Actions
gcloud run deploy --source hands your source to Cloud Build, which builds the image and deploys it to Cloud Run in one command.
Skip a separate build step: gcloud run deploy --source . uploads the repo, builds with buildpacks or your Dockerfile via Cloud Build, pushes to Artifact Registry, and deploys the new revision.
Steps
- Authenticate via WIF and set up gcloud.
- Run
gcloud run deploy <service> --source .. - Pass
--regionand--allow-unauthenticatedas needed.
Workflow
.github/workflows/deploy.yml
permissions:
id-token: write
contents: read
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: google-github-actions/auth@v2
with:
workload_identity_provider: ${{ vars.WIF_PROVIDER }}
service_account: ${{ vars.DEPLOY_SA }}
- uses: google-github-actions/setup-gcloud@v2
- run: |
gcloud run deploy web \
--source . \
--region us-central1 \
--allow-unauthenticatedGotchas
- The account needs
roles/cloudbuild.builds.editorand access to the default Cloud Build bucket. - First deploy may prompt to create an Artifact Registry repo; pre-create it to keep CI non-interactive.
Related guides
How to Deploy a Cloud Run Service With GitHub ActionsDeploy a prebuilt container image to Google Cloud Run from GitHub Actions using google-github-actions/deploy-…
How to Deploy With Cloud Build From GitHub ActionsTrigger a Cloud Build pipeline from GitHub Actions with gcloud builds submit, running your cloudbuild.yaml to…