Repository navigation
Support Firebase SDK auto-initialization for Cloud Run services - #11208
Conversation
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces support for linking and clearing a Firebase Web App associated with a Cloud Run service to enable SDK auto-initialization. It adds --app and --clear-app options to the update command, automatically links web apps during initialization, and injects the configuration into environment variables. Feedback on these changes includes wrapping getOrCreateWebApp in a try-catch block to prevent crashes from permission errors, skipping redundant redeployments when the app ID is already linked, using hasOwnProperty instead of the in operator to avoid prototype pollution, and replacing numeric length checks in object spreads to prevent evaluating to { ...0 }.
b574dd5 to
25b3c53
Compare
There was a problem hiding this comment.
Code Review
This pull request introduces the ability to link and clear a Firebase Web App for Cloud Run services, enabling Firebase SDK auto-initialization. It adds --app and --clear-app options to the run:services:update command, updates firebase init run to automatically associate a Web App, and injects the corresponding FIREBASE_CONFIG and FIREBASE_WEBAPP_CONFIG environment variables during preparation and deployment. The review feedback highlights two important improvements: first, wrapping the getOrCreateWebApp call in firebase init run with a try-catch block to prevent crashes on network or permission failures; second, throwing a FirebaseError if a newly requested Web App lookup fails during deployment, ensuring the service is not left in a partially configured state.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request adds support for linking and clearing a Firebase Web App on Cloud Run services to enable SDK auto-initialization, updating the CLI commands, deployment pipeline, and initialization flows accordingly. The feedback recommends moving the resolution of the default service account and project number inside the try-catch block to prevent deployment crashes, correcting the arguments passed to getProjectNumber, and utilizing the getError utility instead of manual type checks to safely handle unknown error types.
Name the case where a deploy unlinks the app. Keep an emptied env list instead of deleting it: to Cloud Run, [] and no env field mean the same thing. Always send the service's annotations, instead of only when the linked app changed, which removes the undefined return and the conditional update mask.
For an app ID with no app, the web app config lookup returns the project's config without an appId, so a typo in --app deployed and was saved on the service. Check that the app exists first, with the same check App Hosting's --app uses, so the deploy fails before building or saving anything.
abhis3
left a comment
There was a problem hiding this comment.
Nice! Happy to merge this as is since it's a prototype and we can clean it up later. Heads up you might need to squash your commits. Left a few AI comments that I thought were reasonable when comparing it to this design doc, feel free to fix/ignore as necessary. I don't think any are blocking the merge here.
Nits:
-
RUN_PERMISSIONS doesn't include firebase.clients.list/get or resourcemanager.projects.getIamPolicy, so CI identities pass the precheck and then fail mid-prepare.
-
A 403 on the IAM read is reported as "Failed to grant…".
-
annotations is in the update mask on every deploy, a full read-modify-write with no etag. Maybe include it only when the link changes.
-
appId and firebaseConfig can diverge; a single autoInit?: {appId, firebaseConfig} would prevent that.
-
The PR description is a bit stale: it says init prompts, it says a failed lookup only warns, and the error text has changed.
…mmand when linking an app
…e created getOrCreateWebApp only warns, and returns nothing, when the project is out of web apps (App Hosting backends work without one). Init then deployed the service without a linked app, silently skipping Firebase SDK auto-initialization.
The CLI always sets FIREBASE_CONFIG on linked services; users override auto-init in code, not with the env var. Once Cloud Run injects it, only the annotation is needed.
The build env annotation could override FIREBASE_CONFIG and FIREBASE_WEBAPP_CONFIG for the build, while the container always got the app's FIREBASE_CONFIG. Now both come from the app: users override auto-init in code, not with these env vars.
Description
Links a Firebase Web App to a Cloud Run service so Firebase SDKs auto-initialize. The app ID is saved in the service's
firebase.google.com/app-idannotation.firebase init runasks which web app to link (default: create a new one). A new app is created only after all questions are answered, and init fails if it can't create one. An existing service keeps its app.firebase run:services:update <service> --app <appId>links an app;--clear-appunlinks it.FIREBASE_WEBAPP_CONFIGandFIREBASE_CONFIG.FIREBASE_CONFIGon the container, and removes it when unlinking.roles/firebase.sdkAdminServiceAgent. If not, or if it can't check, it prints thegcloudcommand to grant it. It never changes IAM.Scenarios Tested
npx mocha src/deploy/run/*.spec.ts src/init/features/run.spec.ts--appswitches it,--clear-appremoves it, and a bad--appfails before deploying.Sample Commands
firebase init run
firebase run:services:update my-service --app
firebase run:services:update my-service --clear-app