Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting deploy region in firebase configuration file

Is there a way of defining which region to use when deploying a function to firebase using either the firebase.json or the .firebaserc files? The documentation around this doesn't seem to be clear.

Deploying the firebase functions using GitHub Actions and want to avoid adding the region in the code itself if possible.

Suggestions?

like image 879
Skaleb Avatar asked Sep 15 '25 21:09

Skaleb


2 Answers

It's not possible using the configurations you mention. The region must be defined synchronously in code using the provided API. You could perhaps pull in an external JSON file using fs.readFileSync() at the global scope of index.js, parse its contents, and apply them to the function builder. (Please note that you have to do this synchronously - you can't use a method that returns a promise.)

like image 117
Doug Stevenson Avatar answered Sep 17 '25 12:09

Doug Stevenson


I've target this problem using native functions config.
Example:

firebase functions:config:set functions.region=southamerica-east1

Then in functions declaration I'd as follows:

const { region } = functions.config().functions;
    
exports.myFunction = functions.region(region).https.onCall((data) => {
  // do something
});

That way, for each time I need a different region, it would only need a new config set.

like image 23
Víctor Hugo Avatar answered Sep 17 '25 11:09

Víctor Hugo