Firebase Cloud Functions. Logged errors indicate files from dist are missing - firebase

I am new to FCM.
My function works great locally as a simple nodejs module but when i deploy it. The logs are showing that some files are not there. But I can't find instructions on how to inspect what exactly got deployed. This is the dist after running build (see post build below):
"build": "tsc",
"postbuild": "cp -r src/email/emails lib/email",
Here is my dist
Errors in my app say that /email/emails/html.pug do not exist or are not in the expected location. Could that have something to do with postbuild scripts? How am I expected to troubleshoot?

Related

"firebase use" - projects out of sync between command line and when invoked from npm

I have been doing firebase functions development for a while now and was used to be able to switch the target project from the command line via firebase use test, firebase use staging etc.
In my npm package scripts in the project I also invoke the firebase tools to do things like generating a .runtimeconfig.json via:
"scripts": {
"genruntime" : "firebase functions:config:get > .runtimeconfig.json",
}
In general, this worked fine - I'd change the target project from the command line, and the same target project would be used when I ran firebase commands by npm scripts.
Over the last few days though, I've found that sometimes the target projects weren't synced as I'd set the target environment to test but the find that the npm command was getting functions from the staging environment.
My firebase tools are the same version (global via project) and it's almost as if the target project is not being shared between the global firebase tools and the the npm ones.
Has anyone else seen this issue?
I can change my npm scripts to be explicit about the project being used but this has worked in the past and I'm curious about what might have happened.

GCP: how to make sure that gcp project is set in Cloud Shell Editor

I am toying around a bit with GCP cloud shell editor which I start by visiting https://shell.cloud.google.com/?show=ide (which I installed as an PWA) and would like to debug a simple Flask AppEngine app. The app is using Cloud Logging. It runs fine in the terminal window when I first do:
gcloud config set project myproject
However if I want to use the builtin debugging I get errors because gcloud config set project myproject has not been set in that new window. So my question is how do I make sure that gcloud config set project myproject is run at startup of each console? I already tried running a preLaunchTask but since that is run in a separate console it does not help
Update (26 Jan 2021)
Also toyed around with trying to change the .bashrc automatically when opening a project by using a task that is triggered by folderOpen and then writes the relevant gcloud command to a script which is called by .bashrcas shown below
{
"version": "2.0.0",
"tasks": [
{
"label": "Set GCP Project",
"type": "shell",
"command": "echo \"set -x; gcloud config set project [MYPROJECT]\" > $HOME/set_gcp_project",
"runOptions": {
"runOn": "folderOpen"
},
"presentation": {
"reveal": "never",
"panel": "shared"
},
"problemMatcher": []
}
]
}
However Cloud Shell does not support these automated tasks. It works fine in VSCode. However it is still a nuisance because if in the GCP console I open a terminal or it opens it when you click on a run in cloud shell it sets the project to whatever project I had last opened in the Cloud Shell Editor
If you are interested in customizing your Cloud Shell experience you can always refer to the following section of the documentation.
I guess the must straightforward to always guarantee that the gcloud config set project myproject is always run when a new window is opened will be to append that gcloud command at the end of the .bashrc file located at your $HOME directory.
Just open the Cloud Shell (make sure you are located at the $HOME directory, which is the default directory that opens up when you open your Cloud Shell) and append the gcloud command by running the following command:
[YOUR-USERNAME]#cloudshell:~ (myproject)$ echo "gcloud config set project myproject" >> .bashrc

Changing target Firebase ID using firebase-tools CLI

At the command line...
When I run firebase deploy, I get the following error:
Error: The entered credentials were incorrect.
When I run firebase deploy --debug, I get the following (more detailed) error (and log) shown when you click here. (firebase-debug.log)
When I run firebase deploy --project good-project-id, I get the expected deployment behavior.
When I rerun firebase deploy and firebase deploy --debug I get the same errors already described.
How do I make the proper changes to eliminate the errors when running firebase deploy?
Notes:
I am running Mac OS/X Yosemite v10.10.5
I just ran the NPM installation procedure (via Homebrew) described here.
Look at the contents of your .firebaserc file in your project directory. You likely have a "default" project alias specified. Run firebase list and see if that project id shows up there as well (note it should be the project id, not the instance/subdomain name).
If it doesn't match, that's likely your issue. Another thing you can try is deleting the .firebaserc file and then running firebase use --add to create a new project alias.

No programs/server/main.js file in Meteor build

I am trying to build a Meteor app using meteor build --directory ../dist. Everything seems to build fine, but when I follow the instructions provided in the generated README file I get an error saying the server/main.js file can't load. When I looked, I saw that the main.js file is not there.
Is there something I need to do before I build to ensure the file exists after build?
I'm having a very difficult time trying to build the Meteor app for a production serve, and I can't seem to find any clear instructions. The Meteor doc instructions are very vague in regard to build.
I can see how the README can be confusing if not followed as intended.
The first command line states:
$ (cd programs/server && npm install)
Note the parentheses.
Those cause the command to run in a subshell, which means that your shell will remain in the same directory after the command execution is done.
However, if you only execute the inner commands, you will end up in the programs/server directory and experience what you describe.
In any case, $ node main.js should be run from the bundle's root directory.

How can I automate "firebase deploy"?

Is there any way I can automate my "firebase deploy" pushes to Firebase Hosting using a script? I can't seem to figure out how to do this.
Thanks.
Here's a couple different approaches:
Firebase's own David East on how to do it with Travis and GitHub
https://www.youtube.com/watch?v=QLVzozWDYAs
I took an alternate approach, since my automation tool is written in java.
firebase CLI installed in the bash shell, previous to launching my java binary.
[deploy.sh] shell script runs "firebase deploy" command.
java binary has internal code to run the [deploy.sh] script.
Bottom line - no matter what your automation binary is written in, as long as it can shell out and run your [deploy.sh] script in the same shell that firebase is installed in, you should be good to go.
Open your terminal and run this command to generate a new CI token. this will help a lot if you are deploying your project on GitHub
npm install -g firebase-tools
firebase deploy --non-interactive --token $FIREBASE_TOKEN
to complete the automation process
firebase login:ci
personal suggestion: click here to see steps of using all commands

Resources