Reputation: 677
My CI/CD pipeline for deploying my Angular app is close, but I see that Google Cloud Run does not deploy a new revision when the container image has been updated.
I have Cloud Build set to trigger a build when a branch on GitHub has been updated. That is working fine and I see I get a new image named after the commit hash. I'm expecting Cloud Run to trigger its service, pick up the latest image and deploy it, but it's not running. I'm not sure if I need to change the image names so they are not unique due to the SHA-1 hash value.
Upvotes: 3
Views: 3401
Reputation: 364
I also had this issue while using Terraform and got around it by tagging the image with the COMMIT_SHA
variable (which is available in all cloud builds by default) and referencing that in the .tf
files I was using.
The tagging step:
- id: 'Tag image'
name: 'gcr.io/cloud-builders/docker'
args:
- 'tag'
- '${_IMAGE_NAME}'
- '${_ARTIFACT_REGISTRY_REGION}-docker.pkg.dev/${_PROJECT_ID}/${_ARTIFACT_REGISTRY_REPO}/${_IMAGE_NAME}:${COMMIT_SHA}'
The push step:
- id: 'Push image'
name: 'gcr.io/cloud-builders/docker'
args:
- 'push'
- '${_ARTIFACT_REGISTRY_REGION}-docker.pkg.dev/${_PROJECT_ID}/${_ARTIFACT_REGISTRY_REPO}/${_IMAGE_NAME}:${COMMIT_SHA}'
The application step:
- id: 'Apply Terraform changes'
name: 'hashicorp/terraform'
args:
- 'apply'
# other vars I was using
- '-var'
- 'image_tag=${COMMIT_SHA}'
- '-auto-approve'
In the terraform I created a local variable for the image like so:
locals {
image = "${var.artifact_registry_region}-docker.pkg.dev/${var.project_id}/${var.artifact_registry_repo}/${var.image_name}:${var.image_tag}"
}
Which I then referenced in the google_cloud_run_v2_service
definition in Terraform.
Upvotes: 4
Reputation: 81336
Add a Cloud Build step to deploy the new image to Cloud Run.
Modify this example with SERVICE_NAME, REGION, PROJECT_ID, and IMAGE.
# Deploy container image to Cloud Run
- name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'
entrypoint: gcloud
args: ['run', 'deploy', 'SERVICE-NAME', '--image', 'gcr.io/PROJECT_ID/IMAGE', '--region', 'REGION', '--platform', 'managed']
Upvotes: 9