Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase Cloud Functions Deployment Error with error code "NoSuchKey"

I'm trying to deploy one of my functions from firebase CLI (version 8.12.1) and it keeps failing. The function hasn't changed in weeks, so I am a bit confused as to why it's failing now.

Error from the CLI

functions[http-api-(europe-west1)]: Deployment error. Build failed: Build error details not available. Please check the logs at https://console.cloud.google.com/logs/viewer?project=&advancedFilter=resource.type%3Dbuild%0Aresource.labels.build_id%3Dfeb2697d-29b4-4ab7-9b84-90d9f847be42%0AlogName%3Dprojects%2Fvestico-dev%2Flogs%2Fcloudbuild

Logs from the cloud console

Step #3 - "restorer": Restoring data for "google.nodejs.functions-framework:functions-framework" from cache

Step #3 - "restorer": \u001b[31;1mERROR: \u001b[0mfailed to restore: restoring data: GET https://storage.googleapis.com/eu.artifacts..appspot.com/containers/images/sha256:484d08dfc6a8f356c34a86fa4440fedf86f4fc398967eea66e4aab4e9ee81e3d?access_token=REDACTED: unsupported status code 404; body: NoSuchKeyThe specified key does not exist.No such object: eu.artifacts..appspot.com/containers/images/sha256:484d08dfc6a8f356c34a86fa4440fedf86f4fc398967eea66e4aab4e9ee81e3d

Finished Step #3 - "restorer"

ERROR: build step 3 "eu.gcr.io/fn-img/buildpacks/nodejs10/builder:nodejs10_20201005_20_RC00" failed: step exited with non-zero status: 46

The interesting piece is probably the error from above:

<Error>
  <Code>NoSuchKey</Code>
  <Message>The specified key does not exist.</Message>
  <Details>No such object: eu.artifacts.<project-id>.appspot.com/containers/images/sha256:484d08dfc6a8f356c34a86fa4440fedf86f4fc398967eea66e4aab4e9ee81e3d</Details>
</Error>

What key is builder referring to? <project-id>@appspot.gserviceaccount.com has accesss to the cloud function with roles Cloud Functions Admin and Editor.

EDIT

Deploying through firebase deploy --only functions:<my-api>

That function uses @google-cloud/storage to get a public url for a storage resource.

I'm loading the service account configs like this:


const devServiceAccount = require("../../service-accounts/dev.json");
const prodServiceAccount = require("../../service-accounts/prod.json");

export const getAdminConfig = (): (AppOptions | undefined) => {
  const baseConfigEnv = process.env.FIREBASE_CONFIG;
  if (!baseConfigEnv) {
    console.error("no firebase config environment");
    return undefined;
  }

  const app = functions.config().app;
  if (app === undefined) {
    console.error("no firebase app config");
    return undefined;
  }

  const serviceAccount = app.environment === 'dev' ? devServiceAccount : prodServiceAccount;
  const adminConfig = JSON.parse(baseConfigEnv) as AppOptions;
  adminConfig.credential = credential.cert(serviceAccount);

  return adminConfig;
}

The cloud storage is used here.

const options = {
    action: 'read',
    expires: Date.now() + 1000 * 60 * 60 //1 hour
  } as GetSignedUrlConfig;

const file = bucket.file(path);
filePathPromises.push(file.getSignedUrl(options))
  });

My folder structure is as follows.

+ functions
  + lib
    + function.js
  + service-accounts
    + dev.json
    + prod.json
  + src
    + function.ts

I was ruling out that the service account files are the issue given that the files are loaded in getAdminConfig() for all functions in the project.

Update 10/13/20

I've verified the files uploaded to the GCF storage container. The JSON keys are there and in the right location. The paths match, so they should be found when the GCF is running.

like image 859
bhr Avatar asked Jan 25 '23 16:01

bhr


2 Answers

Adding a hint for the next soul running into this problem. It seems to be caused by missing/inaccessible file in the restore/rollback process.

I was successfully removing the problem by simply:

  1. Deleting my functions using the web firebase console.
  2. Deploying normally again >firebase deploy
like image 125
markussvensson Avatar answered May 22 '23 11:05

markussvensson


It seems there was an intermittent issue in Firebase Cloud Functions or GCF. I just ran firebase deploy --only functions again and it deployed successfully.

like image 20
bhr Avatar answered May 22 '23 10:05

bhr