ERROR: build step 2 on Firebase

Lately, I was a getting the following error after deploying Firebase functions:

terminal
ERROR: build step 2 "us.gcr.io/fn-img/buildpacks/nodejs10/builder:nodejs10_20210505_10_24_1_RC00" failed: step exited with non-zero status: 1

After reading this thread, the error on deployment seems to be related to setting a lifecycle of n days to delete automatically a storage bucket. You can find the original answer on StackOverflow.

The rule deletes all the files which has a difference in timestamp of n days since they were last updated, but not all files are updated on deployment, so the rule may delete some of the files, while others remain there. Thus, the bucket remains inconsistent.

For example, let's assume that your first deployment was on 17th May 2021:

terminal
containers/
├── images/
│   ├── sha256:somethingsomething0001 last modified: 17th May 2021 
│   ├── sha256:somethingsomething0002 last modified: 17th May 2021
│   ├── sha256:somethingsomething0003 last modified: 17th May 2021
│   └── sha256:somethingsomething0004 last modified: 17th May 2021

The next day, you redeploy your project; some files are updated while others not:

terminal
containers/
├── images/
│   ├── sha256:somethingsomething0001 last modified: 18th May 2021 
│   ├── sha256:somethingsomething0002 last modified: 17th May 2021
│   ├── sha256:somethingsomething0003 last modified: 18th May 2021
│   └── sha256:somethingsomething0004 last modified: 18th May 2021

If you set a lifecycle of 1 day, the following will happen during the day:

terminal
containers/
├── images/
│   ├── sha256:somethingsomething0001 last modified: 18th May 2021
│̶ ̶ ̶ ̶├̶─̶─̶ ̶s̶h̶a̶2̶5̶6̶:̶s̶o̶m̶e̶t̶h̶i̶n̶g̶s̶o̶m̶e̶t̶h̶i̶n̶g̶0̶0̶0̶2̶ ̶l̶a̶s̶t̶ ̶m̶o̶d̶i̶f̶i̶e̶d̶:̶ ̶1̶7̶t̶h̶ ̶M̶a̶y̶ ̶2̶0̶2̶1̶
│   ├── sha256:somethingsomething0003 last modified: 18th May 2021
│   └── sha256:somethingsomething0004 last modified: 18th May 2021

If you deploy at this point, you may have issues, because the bucket state is inconsistent.

If you have any errors on deployment, delete the entire containers/ folder inside artifacts and redeploy your project again. If still doesn't work, you'll need to delete all the functions and redeploy them again.

Note: Take this solution with a grain of salt, as is a patch to solve the issue temporarily. I reported the issue to Google Team and I'm still waiting for an answer on how to handle this situation properly. It would be good that you could set a rule to delete the whole containers/ folder after n days.

Update

GCF team has reviewed the issue, you can view the full response here. TL;DR: Using a lifecycle deletion or policy or deleting the folder manually causes the issue.

The quick fix is to remove the lifecycle deletion, but it may increase the bill in Firebase. 😔

They also said the following:

Our GCF team has identified long term fixes to this issue and will be looking to improve this behavior such that GCS lifecycle rules would not impact GCF function deployment in the future.

We have to wait for the GCS lifecycle rules to work properly.

Hi, I'm Erik, an engineer from Barcelona. If you like the post or have any comments, say hi.