I'm currently using firebase-tools as a module as part of a deployment script for our CI.
The thing is, that every time there is more than one firebase func, a user input based question raised
? Would you like to proceed with deletion? Selecting no will continue the rest of the deployments. (y/N)
Which of course is a problem in a CI env.
_Can be reproduce with the same example in the bottom of this repo README file._
Can you provide the version of firebase-tools you are using? force is a feature we have now, so this should be resolved in recent versions.
Sure thing, I'm using _almost_ the latest version: 6.1.0
And here's my current deployment script(based on the example in the repo README):
let fs = require('fs');
let firebaseEnv = (JSON.parse(fs.readFileSync(`${__dirname}/.firebaserc`, 'utf8'))).projects;
let token = fs.readFileSync(`${__dirname}/.firebase-token`);
let client = require('firebase-tools');
/**
* FireBase Deployment script
* FOR CI USE ONLY!
*/
client.deploy({
only_functions: true,
project: firebaseEnv[process.env.NODE_ENV?process.env.NODE_ENV:'dev'],
token: token,
cwd: __dirname,
}).then(() => {
console.log('Rules have been deployed!');
return true;
}).catch((err) => {
console.log(err);
});
Hi @evilUrge I see this is definitely a problem for CI systems. I'll look into whether we have the force option available when using CLI as library, and will update when I find out. Thanks for your patience!
@evilUrge you're right - I just reproduced this behavior on both 6.1.0 and 6.1.1 (latest) version of the CLI - it asks for user input in the case where it sees a function that was previously deployed no longer exists in your code. I have filed a bug to fix this, internal bug reference: 120046123. Thanks for reporting!
Did some more digging around - if you add force: true it works for me:
client.deploy({
only_functions: true,
project: firebaseEnv[process.env.NODE_ENV?process.env.NODE_ENV:'dev'],
token: token,
force: true,
cwd: __dirname,
}).then(() => {
console.log('Rules have been deployed!');
return true;
}).catch((err) => {
console.log(err);
});
@thechenky - the force param works great; if you always want to overwrite the rest of your existing functions.
Maybe I should've refined my request (and perhaps change the title of this ticket).
If you have more than 1 function from a different project, forcing deployment will wipe the other functions. which is far from what I'm trying to accomplish by this simple deploy script.
When a user executes the cmd firebase deploy, the same question I mentioned raised and the deploy process waiting for a user input.
What I'm looking is the same as when the user choose not proceed with deletion; meaning answer 'N' on :
? Would you like to proceed with deletion? Selecting no will continue the rest of the deployments. (y/N)
So it's more actually force default user selection, as the default in this prompt question is no.
@evilUrge I'm not sure what the use case would be here to not wipe out functions that are no longer in the source code. Firebase deploy command lists all the already deployed functions in your project and diffs them to understand which functions in your code need to be deleted and which ones created/updated. This way, your code and Firebase both stay synced up at all times. You mentioned functions from multiple projects - are you keeping them all in one file? In this case I would suggest separating them and having separate CI deploy scripts for each project.
@thechenky Each project has it's own deploy script with a different function name that been exposed.
_Ex. express.js server obj that been exposed with the name "related" and another one for Google's puppeteer which exposed and named as "puppeteer"._
Still, once I'm deploying more than one function to the same firebase project, I'm getting the prompt I mentioned earlier, and with 'force: true', it's just wiping the other functions (instead of a user input of "n").
Hi @evilUrge even if each project has its own deploy script, the functions need to be in separate files for each project. Also keep in mind that even if the source code for a function is the same, if you deployed that function under a different name, Firebase will still prompt you for a deletion as it sees a function with that name no longer exists.
With that said, there might be a workaround for your setup - you can try deploying with the --only flag so that you only pick up the functions you're interested in deploying. This way you should not be getting the prompt for deleted functions. Change your params to client.deploy() to be only: 'functions:functions1' (btw, in the previous snippet you provided, only_functions: true should be only: 'functions' - the CLI will ignore any options that are invalid.
I'm afraid that it didn't help @thechenky .
client.deploy({
only: 'functions',
project: firebaseEnv[process.env.NODE_ENV?process.env.NODE_ENV:'dev'],
token: token,
// force: true,
cwd: __dirname,
}).then(() => {
console.log('Rules have been deployed!');
return true;
}).catch((err) => {
console.log(err);
});
tried with force:true and without; same behavior
It keep's dumping my other functions once force is true, and if it's false it's still waiting for user input
? Would you like to proceed with deletion? Selecting no will continue the rest of the deployments. (y/N)
The code base, and exposed function names are different.
And if I deploy it manually via firebase-tools; I can have all of them.
@evilUrge did you make the changes I suggested in my previous post? I don't see them reflected in the code snippet you provided. Please make the changes and reply back - the behavior you're currently experiencing is intended behavior.
@thechenky
My bad, I missed the part you suggested to use the function name as part of the only flag value
therefore the following snippet actually works:
const fs = require('fs');
const firebaseEnv = (JSON.parse(fs.readFileSync(`${__dirname}/.firebaserc`, 'utf8'))).projects;
const functionName = require('./package').name;
const token = fs.readFileSync(`${__dirname}/.firebase-token`);
const client = require('firebase-tools');
/**
* FireBase Deployment script
* FOR CI USE ONLY!
*/
client.deploy({
only: `functions:${functionName}`,
project: firebaseEnv[process.env.NODE_ENV?process.env.NODE_ENV:'dev'],
token: token,
// force: true,
cwd: __dirname,
}).then(() => {
console.log('Rules have been deployed!');
return true;
}).catch((err) => {
console.log(err);
});
Thanks @thechenky =D
@evilUrge awesome! Glad that option worked for you :) I'm going to close this out. As always, please feel free to open a new issue if you have any other problems.
I would like to warn others that using --force in CLI may wipe out all the other functions.
I mistook this option and got all other than the one in deployment removed. :)
Most helpful comment
@thechenky - the force param works great; if you always want to overwrite the rest of your existing functions.
Maybe I should've refined my request (and perhaps change the title of this ticket).
If you have more than 1 function from a different project, forcing deployment will wipe the other functions. which is far from what I'm trying to accomplish by this simple deploy script.
When a user executes the cmd
firebase deploy, the same question I mentioned raised and the deploy process waiting for a user input.What I'm looking is the same as when the user choose not proceed with deletion; meaning answer 'N' on :
So it's more actually force default user selection, as the default in this prompt question is no.