Firebase Cloud functions stop working after Cloud Build deploy

273 Views Asked by At

I am using Cloud Build to deploy my firebase project (hosting and cloud functions) trigged by a commit to a branch in a github repo. The deploy is successful and the site works, but the cloud functions don't run after the deploy. They don't even show up in the log as being called, so there are no errors.

I click a button from the UI that calls a cloud function, which saves some data to the real-time database. The code to call the function is run in a try catch, and the catch code runs. The logs for the cloud function show nothing -- the function isn't even run. When I then deploy the project locally from my laptop instead of via cloud build, the cloud function runs when the button is clicked and the data is saved to the database and the logs indicate that the function was invoked. None of the cloud functions are invoked when triggering an event from the front end, however, when I have deployed from Cloud Build

It's only when the project is deployed by Cloud Build that the functions don't run when they are called. I am wondering if this could be a permissions issue?

Front end code:

 const createTeam = (payload) => {
  return async (dispatch, getState, getFirebase) => {
    debugger;
    const createTeam = getFirebase().functions().httpsCallable("createTeam");
    console.log("create team===>", createTeam);
    try {
      console.log("about to run");
      await createTeam(payload);
      dispatch(
        sendNotification({
          severity: "success",
          message: "Team Created",
          isOpen: true,
        })
      );
    } catch (e) {
      dispatch(
        sendNotification({
          severity: "error",
          message: "An error occurred and team was not created.",
          isOpen: true,
        })
      );
    }
  };
};

Build file:

steps:
  - name: "gcr.io/cloud-builders/npm"
    dir: "functions"
    args: ["install"]
  # Install
  - name: "gcr.io/cloud-builders/npm"
    args: ["install"]
  # Build
  - name: "gcr.io/cloud-builders/npm"
    args: ["run", "build"]
  # Deploy
  - name: "gcr.io/$PROJECT_ID/firebase"
    args: ["deploy", "--project=$PROJECT_ID"]

from the deployment logs:

    Hosting URL: xxxx
Project Console: xxxx
✔  Deploy complete!

✔  hosting[agile-boost]: release complete
i  hosting[agile-boost]: releasing new version...
✔  hosting[agile-boost]: version finalized
i  hosting[agile-boost]: finalizing version...
✔  functions[launchAssessments(us-central1)]: Successful update operation. 
✔  functions[createTeam(us-central1)]: Successful update operation. 
✔  functions[sendParticipantEmailWhenAssessmentOpens(us-central1)]: Successful update operation. 
✔  functions[completeAssessments(us-central1)]: Successful update operation. 
✔  functions[refreshMetricCategoryAvg(us-central1)]: Successful update operation. 
✔  functions[saveParticipantAnswer(us-central1)]: Successful update operation. 
✔  functions[updateParticipant(us-central1)]: Successful update operation. 
✔  functions[closeAssessmentsWhenTeamIsDeleted(us-central1)]: Successful update operation. 
✔  functions[getParticipantsData(us-central1)]: Successful update operation. 
✔  functions[createAccount(us-central1)]: Successful update operation. 
✔  functions[addParticipantToAssessment(us-central1)]: Successful update operation. 
✔  functions[createAssessment(us-central1)]: Successful update operation. 
✔  functions[reviseAssessmentMetrics(us-central1)]: Successful update operation. 
✔  functions[refreshMetricQuestionAvg(us-central1)]: Successful update operation. 
✔  functions[updateParticipantWhenTeamParticipantUpdates(us-central1)]: Successful update operation. 
✔  functions[refreshMetricTagAvg(us-central1)]: Successful update operation. 
✔  functions[updateMetricsWhenParticipantStatusChanges(us-central1)]: Successful update operation. 
✔  functions[addNewTeamParticipantToActiveAssessments(us-central1)]: Successful update operation. 
✔  functions[getSurveyData(us-central1)]: Successful update operation. 
i  functions: scheduler job firebase-schedule-completeAssessments-us-central1 is up to date, no changes required
i  functions: scheduler job firebase-schedule-launchAssessments-us-central1 is up to date, no changes required
✔  pubsub: required API pubsub.googleapis.com is enabled
✔  scheduler: required API cloudscheduler.googleapis.com is enabled
i  pubsub: ensuring required API pubsub.googleapis.com is enabled...
i  scheduler: ensuring required API cloudscheduler.googleapis.com is enabled...
i  functions: updating Node.js 10 function completeAssessments(us-central1)...
i  functions: updating Node.js 10 function launchAssessments(us-central1)...
i  functions: updating Node.js 10 function getParticipantData(us-central1)...
i  functions: updating Node.js 10 function getParticipantsData(us-central1)...
i  functions: updating Node.js 10 function closeAssessmentsWhenTeamIsDeleted(us-central1)...
i  functions: updating Node.js 10 function updateParticipantWhenTeamParticipantUpdates(us-central1)...
i  functions: updating Node.js 10 function updateMetricsWhenParticipantStatusChanges(us-central1)...
i  functions: updating Node.js 10 function sendParticipantEmailWhenAssessmentOpens(us-central1)...
i  functions: updating Node.js 10 function addNewTeamParticipantToActiveAssessments(us-central1)...
i  functions: updating Node.js 10 function saveParticipantAnswer(us-central1)...
i  functions: updating Node.js 10 function getSurveyData(us-central1)...
i  functions: updating Node.js 10 function updateParticipant(us-central1)...
i  functions: updating Node.js 10 function addParticipantToAssessment(us-central1)...
i  functions: updating Node.js 10 function createAssessment(us-central1)...
i  functions: updating Node.js 10 function createTeam(us-central1)...
i  functions: updating Node.js 10 function createAccount(us-central1)...
i  functions: updating Node.js 10 function reviseAssessmentMetrics(us-central1)...
i  functions: updating Node.js 10 function refreshMetricQuestionAvg(us-central1)...
i  functions: updating Node.js 10 function refreshMetricTagAvg(us-central1)...
i  functions: updating Node.js 10 function refreshMetricCategoryAvg(us-central1)...
✔  database: rules for database xxxx released successfully
i  database: releasing rules...
✔  hosting[agile-boost]: file upload complete
i  hosting: uploading new files [4/6] (66%)
i  hosting: hashing files [34/35] (97%)
i  hosting: hashing files [34/35] (97%)
i  hosting[agile-boost]: found 35 files in build
i  hosting[agile-boost]: beginning deploy...
✔  functions: functions folder uploaded successfully
i  functions: packaged functions (52.61 KB) for uploading
i  functions: preparing functions directory for uploading...
✔  functions: required API cloudbuild.googleapis.com is enabled
✔  functions: required API cloudfunctions.googleapis.com is enabled
i  functions: ensuring required API cloudbuild.googleapis.com is enabled...
i  functions: ensuring required API cloudfunctions.googleapis.com is enabled...
✔  database: rules syntax for database agile-boost is valid
i  database: checking rules syntax...
✔  functions: Finished running predeploy script.

> tsc
> functions@ build /workspace/functions

Running command: npm --prefix "$RESOURCE_DIR" run build

> tslint --project tsconfig.json
> functions@ lint /workspace/functions

Running command: npm --prefix "$RESOURCE_DIR" run lint
i  deploying database, functions, hosting

=== Deploying to 'xxxx'...

gcr.io/agile-boost/firebase:latest
Status: Downloaded newer image for gcr.io/agile-boost/firebase:latest
Digest: sha256:063a10dfecc2b3bb4245316fb89ae1588f594bb8bb6e950ecf6a9488015e20bb
38ee9b020816: Pull complete
ddf8c3713c7d: Pull complete
9819791ca1ba: Pull complete
19c9987a828c: Pull complete
40ba0f817ab5: Pull complete
8cdf70a16731: Pull complete
9819791ca1ba: Download complete
9819791ca1ba: Verifying Checksum
8cdf70a16731: Download complete
8cdf70a16731: Verifying Checksum
38ee9b020816: Download complete
38ee9b020816: Verifying Checksum
ddf8c3713c7d: Download complete
ddf8c3713c7d: Verifying Checksum
40ba0f817ab5: Download complete
40ba0f817ab5: Verifying Checksum
19c9987a828c: Download complete
19c9987a828c: Verifying Checksum
38ee9b020816: Waiting
ddf8c3713c7d: Waiting
9819791ca1ba: Waiting
38ee9b020816: Pulling fs layer
ddf8c3713c7d: Pulling fs layer
9819791ca1ba: Pulling fs layer
19c9987a828c: Pulling fs layer
40ba0f817ab5: Pulling fs layer
8cdf70a16731: Pulling fs layer
e5c5821cd889: Already exists
55abbc6cc158: Already exists
8439168fd8dc: Already exists
c159512f4cc2: Already exists
1b49aa113642: Already exists
4f250268ed6a: Already exists
latest: Pulling from agile-boost/firebase
Using default tag: latest
Pulling image: gcr.io/agile-boost/firebase
0

There are 0 best solutions below