Search code examples
google-cloud-platformgoogle-cloud-rungoogle-container-registry

Cloud Run deployment using image from last revision


We need to deploy labels to multiple CLoud Run services using below API method

https://cloud.google.com/run/docs/reference/rest/v1/namespaces.services/replaceService

We are looking for options where we can apply labels using API without any new image deployment from Container Registry . We understand that there will be deployment and revision change while applying labels but we want that during deployment it should not pull new image from container registry rather it should use the image from last revision . Any configuration parameter in Cloud Run to prevent new images being pulled while applying labels using API or gcloud run services update SERVICE --update-labels KEY=VALUE


Solution

  • The principle of Cloud Run (and Knative, because the behavior is the same) is that the revision is immutable. Thus, if you change something in it, a new revision is created. You can't fake it!

    So, the solution is to not use the latest tag of your image, but the SHA of it.

    # the latest
    gcr.io/PROJECT_ID/myImage
    gcr.io/PROJECT_ID/myImage:latest
    
    # A specific version
    gcr.io/PROJECT_ID/myImage:SHA123465465dfsqfsdf
    

    Of course, you have to update your YAML for this.