Fireabase CLI Stop reuploading all function folder? - firebase

How can I make Firebase CLI to not re-upload all the files located in the function directory ?
I have really slow internet connection and modifying an minor bug in function code makes the whole folder/directory to re-upload which 40MB which is taking 25 minutes to upload.
This is not bearable for every code change that I make and can't use emulator because I am trying to learn storage changes function.
How can I speed up this process ?

You can deploy function which you have changed by this command
$ firebase deploy --only functions:YOUR_FUNCTION_NAME

The Firebase CLI will always upload the entire contents of the functions folder, except for node_modules, which will be rebuilt by Cloud Functions using your package.json. There is no way to change this behavior.
You should look into your options to test locally, so you don't have to go through the process of deploying each time you want to test a change.
https://firebase.google.com/docs/functions/local-emulator
https://firebase.google.com/docs/functions/local-shell

Related

Prevent firebase functions to always update Node.js 10

How do I prevent Firebase to always update Node JS?
Every time I put:
firebase deploy
It updates to Node.js:
functions: updating Node.js 10 function ssr(us-central1)...
Making it to take so long and using a lot of storage.
I already tried to use firebase deploy --only hosting but it obviously doesn't trigger the function.
I just want that firebase resets the SSR function without updating node.
I have done some research too and I didn't find anything.
Your source code is rebuilt every deployment on Cloud Functions. It's part of the deployment process:
Deployments work by uploading an archive containing your function's source code to a Google Cloud Storage bucket. Once the source code has been uploaded, Cloud Build automatically builds your code into a container image and pushes that image to Container Registry. Cloud Functions uses that image to create the container that executes your function.
The storage size you're mentioned defines the size of the execution environment. It includes the runtime, the operating system, packages, and a library that invokes your function. As mentioned above, even if you deploy a 10MB source code, it doesn't mean that the total size of the image will be 10MB. Storage is needed for the built image as well.
--only hosting flag deploys your static sites on Firebase. This flag is not intended for deploying functions. Maybe you're referring on specifying function names like --only functions:funcName
To answer your question, you can't. It's not possible to update your code and skip updating the execution environment of the function. You may be able to do that if you deployed your code on a VM but Cloud Functions is serverless and managed by Google. Because container images are immutable, it's not possible to edit a revision. In order to apply changes to your function, it has to be rebuilt every deployment.
Deployment time and storage is a valid concern, that's why devs are usually recommended testing their function locally first, before deploying it to Firebase. You can do that with Cloud Functions Emulator.

How to deploy static files only to firebase hosting

I am just trying to create a static landing page for my app with firebase hosting. The first time initialized and deployed the site it worked fine, but now that I am trying to tweak the design a little bit and upload better images, somehow my index.html file keeps getting overwritten with code that I do not need, I believe it is the firebase default index page which they create when you first set up a projext. I have tried it three times now and it keeps happening, and each time I have to recreate all the edits.
How do I simply deploy static files without all the extra code overwriting the page?
I cd into the folder containing my site, the public folder, and run firebase init, chose only hosting, then chose no for one page app, then no for the git deploy scripts, then run firebase deploy --only hosting --project (my project)
Each time, my index file gets erased and replaced with a firebase spontaneously created file.
I have searched the firebase docs and can find no explanation.
Please help
Try just running the firebase deploy command. If you run the firebase init command the first time and select the project, and make the public folder, then you should only have to run that command once. cd into the folder, and then just run firebase deploy.

How long it takes for a firebase hosting to work?

I followed the instructions, and deployed a simple web yesterday. At first, it kept showing the default website, saying " you've deployed successfully...", not my web.
Also, the 'firebase open' command + "Hosting: Deployed Site" leads to a undefined site:' undefined.firebaseapp.com '.
But, magically, about an hour later when I open the link from 'firebase console' again, the web showed up... I am not sure whether 'firebase open' command worked cause I didn't try.
Today, I added some features, and deployed again. In the firebase CLI, it said deployed. But, the link still showed the old version.
I'll catch up an hours later to see whether it works, but even it works, it takes too long.
has anyone had the same experience? what's wrong with my web?
Thanks.
This is how I solved this issue for my angular 7 app deployment on Firebase hosting:
ng build --prod
go to dist/myproject and run command Firebase init and...
I went to dist/myproject that now contain build files along with Firebase related files. Copy all files except Firebase related files to dist folder in side dist/myproject.
there you will get overwrite warning just select overwrite option.
after copy process completes, run command Firebase deploy.
after completion of process go to shown URL and there you will find your running app.

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.

firebase deploy not updating html file, not a cache issue

I'm doing a firebase deploy, but my local file does not match my served file. I have quadrupal checked the file that's in the deployed directory, I've disabled cache, I've hard reloaded, I've navigated directly to the file, I've made additional changes to the file, I've deployed from my local dev machine and from a clean CI server.
I navigate to http://localhost:3000/views/tasks.html and see one html result and then to https://[my-firebase-url]/views/tasks.html and see an older html result for the same file.
I've done firebase deploy --debug and everything is reported as successful and the file count is correct. Is there any additional information I can find out myself? Is there a way to look at the build that's uploaded to firebase mentioned in the debug file?
This has worked every time I've ever done it until now with the same project and file structure. Any way to troubleshoot this would be awesome. Thanks!
in my case I forgot to build(ng build --prod) the modified project to update the dist folder, which is uploaded on firebase server when deploy
As the comment by Frank van Puffelencheck mentioned, checking the Firebase status dashboard for the latest information is an additional step to take. If I had done that, I would have seen that the firebase deploy service was having issues at the time.
The issue for me was that I did not save the file. As i was working with bracket and seeing the modification, I forgot it.

Resources