Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Parameters while Deploying Functions or Serving Functions #1369

Open
rohitgarg-lenskart opened this issue Mar 23, 2023 · 6 comments
Open

Comments

@rohitgarg-lenskart
Copy link

rohitgarg-lenskart commented Mar 23, 2023

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 firebase/firebase-tools#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

firebase/firebase-tools#5524
#1084
firebase/firebase-tools#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.

@blidd-google
Copy link
Contributor

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!

@amsipe
Copy link

amsipe commented Apr 12, 2023

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:
1f2aeb5#diff-0c2415a36e96ceeb3631ded1cbf200df14f025b4c5ea0d3bc863376f567cfa3b

@amankr
Copy link

amankr commented Jul 31, 2023

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.

@jessetane
Copy link

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.

@kollinmurphy
Copy link

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.

@jdziek
Copy link

jdziek commented Jan 19, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants