How do you un-deploy Cloud Functions for Firebase? - firebase

I was experimenting with Cloud Functions for Firebase and deployed one of the samples in the functions-samples repo and linked it to an existing project using firebase use --add.
Since I was just playing around, these files were not added to my version control, and I no longer have access to the machine this was done on. I would like to build on this function or create new ones, but I am unsure how to either 1) modify and re-deploy over the original function or 2) un-use --add and start fresh. I see the function in my firebase console but no 'delete' or 'remove' button and have read through the CLI docs looking for clues to no avail.
Thanks for adding functions to the firebase 'stack.' Any guidance is much appreciated.

Functions get deleted when they aren't present during a firebase deploy. Most commonly that'd be because because you removed the function from your index.js, but if you've removed the whole functions directory that'll work too.
To continue work on a function for which you don't have the source anymore, the easiest is to start fresh. The function(s) you deploy will replace the ones you deployed previously.
Alternatively, if you're partial to using the Google Cloud Console instead of the Firebase Console, the Cloud Console will show you the code for the currently-deployed function, so you can copy-paste it onto your local machine.
The Cloud Console also has a 'delete' button for every function, and even a web editor. Be aware when editing functions from the Cloud Console though: your next firebase deploy will overwrite any changes.

To delete a function explicitly use the following command:
$ firebase functions:delete myFunction
Replace myFunction with your function name. For detailed info. follow this link: https://firebase.google.com/docs/functions/manage-functions

Go to Google Cloud Console Cloud Functions and select project, then select the function you want to undeploy or delete. Select it and click delete.

To delete/undeploy a single function, you can delete the code for your function and then run the following in command line:
firebase deploy --only functions:YourFunctionName
Replace YourFunctionName with the name of your function
In the case that you are working on other functions that you are not ready to deploy or do not want to deploy all of your functions for any reason, then the code above can be handy. This also feels a bit safer since you're not redeploying everything :)

Now you can simply delete a function from the function dashboard as follows. Click on the three dots mark of relevant function in the right side corner.

Related

Firebase functions change names when deploying

I have been working with functions for a while, recently I made a function called "unPublishStore" in my index.js file.
When calling firebase deploy --only functions every thing runs flawlessly, but the function's name gets changed, where in the cmd it shows the following:
and in the firebase's functions list the name is also changed:
This feels very much like a typo error.
Please check you index file, ensure the definition name on the left side:
exports.functionNameToDeploy = functionYouWrote;
The functionNameToDeploy will exactly be the name shown in cloud instead of the functionYouWrote
Probably you can search globally in your project to see if there is a function called upPublishStore?

Deploying over an existing Firebase Function without deleting it first fails silently or leads to "Internal" error when called

Our Firebase Functions have been working fine. However, we noticed that recently when we deploy a new version of a function over an existing one, e.g. "firebase deploy --only functions:PurchaseShopItem", the deploy will report success. But the PurchaseShopItem function will simply be the old version. We can even look at the source code and see that it's still the old version.
The only work around is to manually delete the function either from the CLI or from Firebase Functions console.
Related problem: When bulk deploying (for example, "firebase deploy --only functions") some of our functions get stuck in a state where they are present in the Functions Console, but trying to call them leads to an immediate "internal" error return code to the client. No log appears in the Firebase Functions Logs. The fix is the same: If we delete the function first then redeploy, it starts working.
Even deleting a function by removing it from index.js and redeploying doesn't seem to work (the existing function just fails with "internal" and no more information.) Only deleting the function from Console or explicitly from CLI seems to work to replace it.
Has anyone seen this where you must manually delete a function in Firebase Functions Console before you can deploy over it? Are there any work arounds? Are we doing something wrong?
It can take some time for a function to fully deploy after the CLI finishes. That's expected, and the total time can vary. You're not doing anything wrong.

CLI question: "The following functions are found in your project but do not exist in your local source code" - how to default answer No?

Everytime I deploy a function, I have the annoyance that I need to answer the question:
The following functions are found in your project but do not exist in your local source code
with "No".
I have the following structure of my functions. I have a folder with the Typescript functions and then a different folder with the Javascript functions. They are in separate folders, because I am too dumb to get it to work in the same folder.
I initially created both folders using the Firebase CLI and choosing Typescript and Javascript respectively.
I am aware of the --force operator, but I think it will force "Yes" and I don't want the functions to be deleted.
As detailed in the documentation:
You could only target the specific functions you want to deploy, like:
$ firebase deploy --only functions:function1,functions:function2
Or you could group your Cloud Functions into export groups in your index.js/index.ts files.
Grouping functions allows you to deploy multiple functions using a
single command.
See the same doc for more detail.
And yes, the --force operator bypasses the confirmation prompt, but it is the confirmation prompt for deletion, not for deployment (the --force operator is to be used with functions:delete). Therefore it will not help in your case.

How to update in firebase cloud function source code

I have a firebase project which has cloud functions, i don't have the original source code and i want to update in the source code.
i tried to follow the documentation of firebase but it create new folder, i don't know how to get the current source code to update it then deploy it.
also i get the source code using "https://console.cloud.google.com/functions" but can't know how to deploy the code after update on it.
Here is the solution which i follow:
Go to the Cloud Console > Cloud Functions list.
Select any of the functions.
Inside the function's detail, click on the Source tab.
Then at the bottom, you'll see the "Download.zip" button.
Then you can make changes,i.e add new function >> add the code for that function and update the index.js (append your work on it to avoid deleting the old functions) then follow the firebase documentation to deploy only one function

Travis and Firebase: deploy only changed functions

I'm using Travis to automatically deploy my Firebase hosted website and cloud functions as I push to GitHub, as detailed here. However, even for my small website with a limited amount of cloud functions, deploying all of the functions takes quite a long time. Were I deploying manually, I would be able to use --only to specify precisely those functions that I actually changed. Is there a way to make this information available to Travis, so that only the necessary functions are rebuilt?
https://m.youtube.com/watch?v=iyGHW4UQ_Ts
min 30 and following
This guy solves the problem by copying all functions to a cloud bucket and then making a diff for every file. This works well if all your logic is in one file. But this is not what you want for larger projects. For my own project i used webpack to create one file for each function that includes the imports. then i generate a md5 hash for that file and save it to a functions-lock.json. with the next run i can easily check against the old hash value and only deploy the changed functions. The ci should manage the state of the lock file by uploading it to the cloud or doing some git magic
Unfortunately this isn't going to be simple to do -- the Firebase CLI deploys all of your functions because it's next-to-impossible to just analyze the code and figure out which functions are impacted (since you can require other files, you might have updated dependencies but no files changed, etc.).
One thing I can think of that might be a hack would be to have named branches for functions or groups of functions. Then you could git push to the branch of the specific function you want to deploy, and have a script that uses the branch name as a signal to pass the --only functions:<fnName> to the firebase deploy command. That's not the most glamorous solution, but, depending on how much this bugs you, it might help.
So this is a bit late but the long deployment times have bothered us for a while now.
Our solution is based on CircleCI but it should be possible to adapt.
First we get all changed files in the last merged PR for our branch with
git log -m -1 --name-only --pretty="format:" ${process.env.CIRCLE_SHA1}
CIRCLE_SHA1 is the SHA of the last merge commit, i.e featurebranch -> master
Then we get all the function filenames from our /functions/ directory and use
madge to generate an array of all the dependencies those functions have.
Next we go trough all changed files that we got from git and check if their filename is part of the dependency array for a sepcific cloud function, if so we add the cloudfunction to another array.
once this is done we pretty much have an array from all cloudfunctions that have been affected by the change of a specific file that we now can map to their actual cloud function names for deployment.
Now instead of always deploying 75 cloudfunctions which takes 45 minutes we only deploy maybe 20.

Resources