Skip to content

Add support for Build Envvars and Secrets - #11266

Merged
falahat merged 13 commits into
bapi_local_buildsfrom
bapi_build_env
Oct 13, 2026
Merged

falahat merged 13 commits into
bapi_local_buildsfrom
bapi_build_env

Conversation

@falahat

@falahat falahat commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Description

Lets Cloud Run deployments pass env vars and secrets to the build. They're read from the service's firebase.google.com/buildConfig.environmentVariablesAndSecrets annotation, a JSON object. The annotation is a prototype: where this config finally lives is out of scope for now.

Values follow apphosting.yaml:

  • Strings. Numbers and booleans also work and become strings (3 becomes "3"), as they do in apphosting.yaml.
  • Secrets: {"secret": "npm-token"}, {"secret": "npm-token@3"}, or a full resource name.

Only local builds can use secrets: they read them with the deployer's credentials, through App Hosting's loadSecret. Cloud Run's build API only takes plain values, so if the annotation names a secret, a deploy that builds on Cloud Build fails and points to "localBuild": true. Per the spec, there's no --allow-local-build-secrets flag.

  • buildEnv.ts: parses and validates the annotation.
  • prepare.ts: reads it, and rejects secrets for builds on Cloud Build.
  • deploy.ts: passes only the non-secret values to Cloud Build, and all of them to local builds.

Stacked on #11207. Next is #11208 (SDK auto-init).

Scenarios Tested

  • Unit tests.

Sample Commands

gcloud run services describe my-service --region us-central1 --format export > service.yaml
# Add this under metadata.annotations in service.yaml:
#   firebase.google.com/buildConfig.environmentVariablesAndSecrets: '{"API_URL": "https://api.example.com", "NPM_TOKEN": {"secret": "npm-token@3"}}'
gcloud run services replace service.yaml
firebase deploy --only run:my-service

Reads the firebase.google.com/buildConfig.environmentVariablesAndSecrets
annotation on the service. Plain values go to Cloud Build and local builds;
secret references only work in local builds, which read them with the
deployer's credentials.
Realistic names (API_URL, NPM_TOKEN, npm-token) and shorter fixtures.
# Conflicts:
#	src/deploy/run/deploy.spec.ts
#	src/deploy/run/prepare.spec.ts

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for build-time environment variables and secret references on Cloud Run services by reading them from a service annotation, validating them, and passing them to either Cloud Build or local builds. The review feedback highlights two TypeScript type-safety issues: first, an unsafe type assertion (as Record<string, string>) in deploy.ts should be replaced with explicit filtering of string values to adhere to the repository style guide; second, a compilation error in buildEnv.ts when calling Object.entries on an unknown type should be resolved by casting the validated object to Record<string, unknown>.

Comment thread src/deploy/run/deploy.ts Outdated
Comment thread src/deploy/run/buildEnv.ts
@falahat
falahat added this pull request to stack #11267 October 12, 2026 15:22
Comment thread src/deploy/run/args.ts
Comment thread src/deploy/run/buildEnv.ts Outdated
Comment thread src/deploy/run/buildEnv.ts Outdated
Comment thread src/deploy/run/buildEnv.ts Outdated
Comment thread src/deploy/run/deploy.ts Outdated
A build secret is now written the way apphosting.yaml writes one ({"secret": "npm-token@3"}) and passed straight to loadSecret, so there are no extra regexes or format conversions. Cloud Build gets an explicit filter for plain values instead of a cast, and the comments and errors say why only local builds can use secrets.
The name and doc comment now say that the result never includes secrets or their values.
@falahat
falahat requested a review from abhis3 October 13, 2026 18:56
@falahat
falahat merged commit a7afb34 into main Oct 13, 2026
51 checks passed
@falahat
falahat deleted the bapi_build_env branch October 13, 2026 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants