function GetPolicy(timeoutSeconds=60, maxInstances=15){
        let config = functions.config()
        let enviornment = config.app.enviornment;
        if (enviornment == 'local') {
            return {
                timeoutSeconds:  60,
                maxInstances: 2,
                vpcConnector : "******",
                vpcConnectorEgressSettings: '*********'
            }
        } else  {
            return {
                timeoutSeconds:  timeoutSeconds != null ? timeoutSeconds: 60,
                // memory: '2GB',
                // retry: true,
                maxInstances: maxInstances != null ? maxInstances: 15,
                vpcConnector : "********",
                vpcConnectorEgressSettings: '**********'
            }
        }
    }
    

I am exploring GitHub secrets along with GitHub Actions to deploy firebase function on cloud. In my app I am using firebase.config() methods to retrieve my secret values like environment etc. which I want to put in GitHub secrets and want to retrieve from there instead of retrieving it from functions.config() method. Is there any way to do so, if yes please share it here with a short example.

1

There are 1 best solutions below

0
On

For configuring the firebase functions environment you can use defineString combinations as follows :

const { onRequest } = require('firebase-functions/v2/https');
const { defineInt } = require('firebase-functions/params');
const minInstancesConfig = defineInt('EXAMPLE_MININSTANCES');

export const example = onRequest(
  { minInstances: minInstancesConfig },
  (req, res) => { }
)

And to delegate between development and production

const { onRequest } = require('firebase-functions/v2/https');
const environment = params.defineString(‘ENVIRONMENT’, {default: 'dev'});

// use built-in comparators
const minInstancesConfig = environment.equals('PRODUCTION').thenElse(10, 1);
export const helloWorld = onRequest(
  { minInstances: minInstancesConfig },
  (req, res) => { }
)

As per your function configuration you have to configure like this way and offcourse you can use these tricks on global configuration using setGlobalOptions as well like :

const {setGlobalOptions} = require("firebase-functions/v2/options");
const environment = params.defineString(‘ENVIRONMENT’, {default: 'dev'});

// use built-in comparators
const minInstancesConfig = environment.equals('PRODUCTION').thenElse(10, 1);

setGlobalOptions({maxInstances: minInstancesConfig});

Reference : Parameter values and expressions