Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase Functions: Could not create or update Cloud Run service, Container Healthcheck failed

On deploy i got this error

i  functions: creating Node.js 18 (2nd Gen) function addCourseData(us-central1)...
Could not create or update Cloud Run service addcoursedata, Container Healthcheck failed. Revision 'addcoursedata-00001-cup' is not ready and cannot serve traffic. The user-provided container failed to start and listen on the port defined provided by the PORT=8080 environment variable. Logs for this revision might contain more information.

Logs URL: https://console.cloud.google.com/logs/viewer?project=PROJECT_ID&resource=cloud_run_revision/service_name/addcoursedata/revision_name/addcoursedata-00001-cup&advancedFilter=resource.type%3D%22cloud_run_revision%22%0Aresource.labels.service_name%3D%22addcoursedata%22%0Aresource.labels.revision_name%3D%22addcoursedata-00001-cup%22
For more troubleshooting guidance, see https://cloud.google.com/run/docs/troubleshooting#container-failed-to-start

Functions deploy had errors with the following functions:
        addCourseData(us-central1)
i  functions: cleaning up build files...

with --debug I got this log

Total Function Deployment time: 67749
[] 1 Functions Deployed
[] 1 Functions Errored
[] 0 Function Deployments Aborted
[] Average Function Deployment time: 67748

Functions deploy had errors with the following functions:
        addCourseData(us-central1)
[] Not printing URL for HTTPS function. Typically this means it didn't match a filter or we failed deployment

Functions deploy failed.
[] {
  "endpoint": {
    "id": "addCourseData",
    "project": "PROJECT_ID",
    "region": "us-central1",
    "entryPoint": "addCourseData",
    "platform": "gcfv2",
    "runtime": "nodejs18",
    "httpsTrigger": {},
    "labels": {
      "deployment-tool": "cli-firebase"
    },
    "serviceAccount": null,
    "ingressSettings": null,
    "availableMemoryMb": null,
    "timeoutSeconds": null,
    "maxInstances": null,
    "minInstances": null,
    "concurrency": 80,
    "vpc": null,
    "environmentVariables": {
      "FIREBASE_CONFIG": "{\"projectId\":\"PROJECT_ID\",\"databaseURL\":\"https://PROJECT_ID-default-rtdb.asia-southeast1.firebasedatabase.app\",\"storageBucket\":\"PROJECT_ID.appspot.com\"}",
      "GCLOUD_PROJECT": "PROJECT_ID",
      "EVENTARC_CLOUD_EVENT_SOURCE": "projects/PROJECT_ID/locations/us-central1/services/addCourseData"
    },
    "codebase": "default",
    "securityLevel": "SECURE_ALWAYS",
    "cpu": 1,
    "targetedByOnly": true,
    "hash": "38475170b79b25f455db5cacbdc1d6c36adc4679"
  },
  "op": "update",
  "original": {
    "name": "FirebaseError",
    "children": [],
    "exit": 1,
    "message": "Could not create or update Cloud Run service addcoursedata, Container Healthcheck failed. Revision 'addcoursedata-00001-sox' is not ready and cannot serve traffic. The user-provided container failed to start and listen on the port defined provided by the PORT=8080 environment variable. Logs for this revision might contain more information.\n\nLogs URL: https://console.cloud.google.com/logs/viewer?project=PROJECT_ID&resource=cloud_run_revision/service_name/addcoursedata/revision_name/addcoursedata-00001-sox&advancedFilter=resource.type%3D%22cloud_run_revision%22%0Aresource.labels.service_name%3D%22addcoursedata%22%0Aresource.labels.revision_name%3D%22addcoursedata-00001-sox%22 \nFor more troubleshooting guidance, see https://cloud.google.com/run/docs/troubleshooting#container-failed-to-start",
    "status": 3,
    "code": 3
  }
}
[] Error: Failed to update function addcourseData in region us-central1
    at C:\Users\USER_ABC\AppData\Roaming\npm\node_modules\firebase-tools\lib\deploy\functions\release\fabricator.js:51:11
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Fabricator.updateV2Function (C:\Users\USER_ABC\AppData\Roaming\npm\node_modules\firebase-tools\lib\deploy\functions\release\fabricator.js:380:32)
    at async Fabricator.updateEndpoint (C:\Users\USER_ABC\AppData\Roaming\npm\node_modules\firebase-tools\lib\deploy\functions\release\fabricator.js:153:13)
    at async handle (C:\Users\USER_ABC\AppData\Roaming\npm\node_modules\firebase-tools\lib\deploy\functions\release\fabricator.js:88:17)

Error: There was an error deploying functions

How to fix it? Any help!

My code is

const calledFunctionName = process.env.K_SERVICE;
if (!calledFunctionName || calledFunctionName === "addCourseData") {
  const {onRequest} = require("firebase-functions/v2/https");

  // Take the email and adds an entry to Firestore with Course data
  exports.addCourseData = onRequest(async (request, response) => {
    return await (await require("./my-functions/course/add-course-data-function"))
        .addCourseData(request, response);
  });
}

Everything was working fine before introducing the process.env.K_SERVICE, so is there anything else to do too, to use the environment variable? As I just added in code to save the cold start and unnecessary file loading.

Why server not able to create a container for the function?

like image 730
eagle Avatar asked Nov 22 '25 20:11

eagle


2 Answers

Make sure you have all the dependents you are using specified in package.json:

"dependencies": {
  "firebase-admin": "^11.8.0",
  "firebase-functions": "^4.3.1",
  "nodemailer": "^6.9.7"
},

Same here. I am using Nodemailer so I had to install it first in the function's directory.

"message": "Could not create or update Cloud Run service sendemailonnewentry, Container Healthcheck failed. Revision 'sendemailonnewentry-00001-por' is not ready and cannot serve traffic.

Also make sure you didn't install the dependents in the parent directory. The code in the functions directory will still find the package when run in the local emulator, but the deployment obviously won't.

like image 61
Mouayad Avatar answered Nov 24 '25 21:11

Mouayad


I need to change this line

if (!calledFunctionName || calledFunctionName === "addCourseData")

to

if (!calledFunctionName || calledFunctionName === "addcoursedata")

OR (better approach would be)

if (!calledFunctionName || calledFunctionName === "addCourseData".toLowerCase())

as process.env.K_SERVICE returns the lower alphabets ONLY, instead of camelCase or name-with-hyphens.

Finally, I found the answer to my issue after 2 days of researching and debugging. Maybe it saves someone's time!

like image 34
eagle Avatar answered Nov 24 '25 20:11

eagle



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!