Cloud Function error failure

Problem

When deploying a function within Cloud Function through the Cloud console, the redeployment fails with log entry:

"Step #2 - "analyzer": [31;1mERROR: [0mfailed to initialize cache: failed to create image cache: accessing cache image "us.gcr.io/MY_PROJECT/gcf/[REGION]/SOME_KEY/cache:latest": failed to get OS from config file for image 'us.gcr.io/MY_PROJECT/gcf/[REGION]/SOME_KEY/cache:latest'"

Environment

  • Cloud Functions
  • Cloud console

Solution

  1. Delete the cache and worker images for functions that throw this error from Google Container Registry.
  2. Sign in to the Cloud console.
  3. Navigate to Container Registry > Images > Cloud Functions.
  4. Select your region.
  5. Go to Images > cache / worker > SOME_UUID. 
    • Translates to <multi-region>.gcr.io/PROJECT_ID/gcf/region/images/{cache/worker}/SOME_UUID
  6. Select the right UUID based on the error and delete the image.
  7. Redeploy your function.

Cause

  • Cloud Functions uses Container Registry to store application and cache images that are built on behalf of Google Cloud Functions. Google Container Registry uses a Google Cloud Storage bucket to store these artifacts
  • Sometimes the user sets a life cycle deletion policy on this bucket, this can cause the Google Container Registry images to become corrupted as certain necessary objects within the bucket are deleted
  • Or if the user arbitrarily deletes objects from the bucket - <multi-region>.artifacts.<project-id>.appspot.com/containers/images/*
  • This stands true for Firebase Functions as well, which just like Google Cloud Functions uses Container Registry to store the container images.