firebase-functions icon indicating copy to clipboard operation
firebase-functions copied to clipboard

Custom Parameters while Deploying Functions or Serving Functions

Open rohitgarg-lenskart opened this issue 3 years ago • 6 comments

Currently we can't access custom parameters while deployment of functions or while serving functions locally. Only a few selected params are allowed. e.g. minInstance Can we expect custom parameters to be added, to access while deployment or while serving. Unlike, this issue https://github.com/firebase/firebase-tools/issues/5524, where few of the values are only added to params.

Even, the most basic thing used by functions "region" is still not added, and functions.config() is deprecated, just to make things tough for the users?

If any alternatives to access custom parameters while deployment, please provide.

Use Case 1: Need to select different regions to deploy functions based on parameters. Use Case 2: Need to select different environment and a lot of pre-deployment conditions are dependent upon the environment being selected. eg.functions.storage.bucket("bucket-name").object().onFinalize, here bucket name can be different for different projects, and the bucket name has to given while deployment itself.

Related issues

https://github.com/firebase/firebase-tools/issues/5524 https://github.com/firebase/firebase-functions/issues/1084 https://github.com/firebase/firebase-tools/issues/5347

[REQUIRED] Version info

node: 18.12.1

firebase-functions: 4.2.1

firebase-tools: 11.19.0

firebase-admin: 11.5.0

[REQUIRED] Test case

const envParam = param.defineString("APP_ENV") const bucketName = envParam.equals("dev").thenElse("dev-bucket-name", "prod-bucket-name") //or const bucketName = envParam.equals("dev").thenElse("dev-bucket-name", "prod-bucket-name").value()

functions.storage.bucket(bucketName).object().onFinalize(async (object: ObjectMetadata) => {})

[REQUIRED] Steps to reproduce

.env file contains : APP_ENV="dev" Build the functions. Deploy the functions.

[REQUIRED] Expected behavior

Bucket name selected should be "prod-bucket-name", and function should be deployed successfully.

[REQUIRED] Actual behavior

Bucket name selected is "dev-bucket-name", and function is not deployed as the bucket belongs to different project and we get insufficient permissions error.

Were you able to successfully deploy your functions?

NO Function is not deployed as the bucket belongs to different project and we get insufficient permissions error.

rohitgarg-lenskart avatar Mar 23 '23 20:03 rohitgarg-lenskart

Hi @rohitgarg-lenskart, thanks for reaching out about this issue. We've noticed that many developers like yourself are expecting to be able to parametrize various configuration options that are currently not supported. We are working on expanding the parametrization feature to include all functions configuration options. Stay tuned for those changes!

blidd-google avatar Mar 29 '23 21:03 blidd-google

I see some PRs getting merged around the RuntimeOptions param support. When can we expect those to be available in a release? Specifically interested in this being added to a release: https://github.com/firebase/firebase-functions/commit/1f2aeb541b804c5cc4ce7490c835956983dffdeb#diff-0c2415a36e96ceeb3631ded1cbf200df14f025b4c5ea0d3bc863376f567cfa3b

amsipe avatar Apr 12 '23 09:04 amsipe

Hi @blidd-google , most of the config options now support Expression type now but still bucket parameter does not supported Expression type yet. can you share any update regarding that. Thank you.

amankr avatar Jul 31 '23 08:07 amankr

Can we get cors too? Or is there a better way to deal with CORS than params? I am deploying my functions to dev, staging and production environments, each with a unique list of allowed origins.

jessetane avatar Nov 27 '23 15:11 jessetane

This is a real shortcoming of the functions API. It's a common use case to have different buckets between environments. If a fix isn't coming soon then an alternative should be documented.

kollinmurphy avatar Dec 22 '23 04:12 kollinmurphy

Has this issue been resolved? I cannot find solution anywhere . I really would prefer not to have to hardcode those values as they vary depending on the environment...

EDIT: Got it somewhat to work using dotenv and regular env file. Not ideal, and definitely not ideal that documentation and cli prompts indicated a feature that doesnt work/exist. EDIT2: Just to try it out i deployed a test function and it seems that it works during deployment, just not when using an emulator EDIT3: Ended up using regular process.env and dotenv. Seems to work in all environments.

jdziek avatar Jan 19 '24 16:01 jdziek