Skip to content

Barebones implementation of local builds#10101

Draft
falahat wants to merge 50 commits intomainfrom
zip_deploy_barebones
Draft

Barebones implementation of local builds#10101
falahat wants to merge 50 commits intomainfrom
zip_deploy_barebones

Conversation

@falahat
Copy link
Contributor

@falahat falahat commented Mar 14, 2026

Description

Scenarios Tested

Sample Commands

annajowang and others added 30 commits November 22, 2025 01:29
1. Fix for injecting auto-init variables into the build

2. Fixes how we handle dependencies, nodejs paths, modulepaths, etc. This needs closer attention/fixes.

3. Adds env var handling (not secrets) and determines which env vars to pass down to the build
… variants) and include them in the final artifact
…ctually a local build (instead of assuming true.)
…ore strictly. We also remove some hardcoded values and we generalize the code so that it does not affect source deploys.

The goal is to prepare this PR so that we can safely submit it to main (behind the experiment flag.)
…ive. Only run it if it's a local build and the local build experiment flag is enabled.
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces the foundational support for local builds within App Hosting, enabling developers to perform application builds on their local machines prior to deployment. It streamlines the deployment pipeline by integrating a new tar-based archiving mechanism for these local builds and ensures proper handling of environment variables during the build process. The changes are carefully integrated into the existing deployment and preparation steps, with the new functionality gated behind an experiment flag.

Highlights

  • Local Build Implementation: Introduced a barebones implementation for local builds in App Hosting, allowing users to build their applications locally before deployment. This feature is guarded by an experiment flag.
  • New Archiving Method: Switched to using .tar.gz archives for local builds instead of .zip files, leveraging the tar npm package for more efficient packaging of build artifacts.
  • Environment Variable Handling: Enhanced environment variable processing for local builds, including stringifying numeric values and injecting them into the build process's process.env.
  • Deployment Flow Integration: Integrated the local build process into the prepare and deploy phases, ensuring that locally built artifacts are correctly archived, uploaded, and referenced during rollout.
  • Firebase SDK Autoinit Removal: Removed the Firebase JS SDK autoinit environment variable generation from the local serving logic, simplifying the emulator setup.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • package.json
    • Updated the @apphosting/build dependency to ^0.1.7.
    • Added the tar package as a new dependency with version ^7.5.11.
  • src/apphosting/backend.ts
    • Imported the logger module.
    • Added an extra newline for formatting.
  • src/apphosting/config.spec.ts
    • Added new test cases for the splitEnvVars function to verify correct stringification of numeric environment variables.
  • src/apphosting/config.ts
    • Imported basename from 'path'.
    • Removed a redundant basename import.
    • Implemented a new splitEnvVars function to separate environment variables into build and runtime categories, ensuring numeric values are stringified.
  • src/apphosting/localbuilds.ts
    • Imported path and EnvMap.
    • Modified the localBuild function to inject provided environment variables into process.env during the build process and restore the original process.env afterwards.
    • Added a new helper function toProcessEnv to convert EnvMap to NodeJS.ProcessEnv.
  • src/apphosting/utils.ts
    • Removed the WebConfig import.
    • Removed the getAutoinitEnvVars utility function.
  • src/deploy/apphosting/args.ts
    • Added an optional env?: Env[] property to the LocalBuild interface.
  • src/deploy/apphosting/deploy.spec.ts
    • Imported experiments and FirebaseError.
    • Updated initializeContext to include an empty env array in LocalBuild.
    • Added a stub for createTarArchive and updated existing stubs to use it for local builds.
    • Added test cases to verify that an error is thrown if local builds are enabled but the corresponding experiment flag is disabled.
  • src/deploy/apphosting/deploy.ts
    • Imported experiments and util.
    • Modified the deployment logic to use util.createTarArchive for local builds and util.createArchive for source builds.
    • Added an experiment flag assertion for local builds.
    • Updated the content type for uploaded objects to TAR for local builds and ZIP otherwise.
  • src/deploy/apphosting/prepare.spec.ts
    • Imported experiments and FirebaseError.
    • Added stubs for experiments.assertEnabled and experiments.isEnabled.
    • Added test cases to ensure that local build functionality correctly checks for the experiment flag and throws an error if it's not enabled, while allowing source deploys to proceed.
  • src/deploy/apphosting/prepare.ts
    • Imported getAppHostingConfiguration, getProjectNumber, and experiments.
    • Updated the localBuild call to use path.resolve for the project root and pass an empty env map.
    • Added an experiment flag assertion for local builds.
  • src/deploy/apphosting/release.ts
    • Removed the warning and filtering logic that previously skipped local builds.
    • Updated the orchestrateRollout call to include buildConfig and set locallyBuiltSource based on whether a local build was performed.
  • src/deploy/apphosting/util.spec.ts
    • Added a new test file to verify the functionality of createTarArchive, specifically its ability to include apphosting.yaml from the root and handle cases where apphosting.yaml is absent.
  • src/deploy/apphosting/util.ts
    • Imported tar and APPHOSTING_YAML_FILE_REGEX.
    • Implemented a new createTarArchive function to create gzipped tar archives of project directories, including logic to handle apphosting.yaml and ignore patterns.
    • Updated the JSDoc for createArchive.
  • src/emulator/apphosting/serve.ts
    • Removed imports for constructDefaultWebSetup, WebConfig, getAutoinitEnvVars, AppPlatform, and getAppConfig.
    • Removed the logic for generating Firebase JS SDK autoinit environment variables.
  • tsconfig.json
    • Reformated the include and exclude arrays for better readability.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

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

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 a foundational implementation for local builds in App Hosting. It correctly adds logic to use a tar archive for build artifacts, gates the feature behind an experimental flag, and updates the deployment flow to handle these new local builds. The changes are well-structured and include relevant tests. However, there appear to be some gaps in the handling of environment variables for local builds. Specifically, build-time environment variables are not passed to the local build process, and runtime environment variables are not correctly passed to the release/rollout phase. These issues could lead to incorrect builds and deployments.

@falahat
Copy link
Contributor Author

falahat commented Mar 18, 2026

/gemini review

Copy link
Contributor

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

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 barebones support for local builds in App Hosting, allowing the deployment of pre-built artifacts. Key changes include updating dependencies, adding a new createTarArchive utility for packaging local build outputs, and modifying the deployment and release processes to differentiate between source and local build deployments. New test cases have been added to cover the local build functionality and experiment flag enforcement. The documentation for localBuild and the main deployment function has also been improved.

const targetDir = targetSubDir ? path.join(rootDir, targetSubDir) : rootDir;
// We must ignore firebase-debug.log or weird things happen if you're in the public dir when you deploy.
// const ignore = config.ignore || [".git"];
const ignore = ["firebase-debug.log", "firebase-debug.*.log", ".git"];
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The createTarArchive function's ignore array is hardcoded and does not respect the config.ignore property or .gitignore files, unlike the createArchive function. This inconsistency means that user-defined ignore patterns in firebase.json or .gitignore files will not be applied to local builds, potentially leading to unintended files being included in the tarball or larger-than-necessary archives. This deviates from expected behavior and could expose sensitive files or increase deployment times unnecessarily.

  const ignore = config.ignore || ["node_modules", ".git"];
  ignore.push("firebase-debug.log", "firebase-debug.*.log");
  const gitIgnorePatterns = parseGitIgnorePatterns(rootDir);
  ignore.push(...gitIgnorePatterns);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

createTarArchive is meant to package a built output directory. The .gitignore might specifically ignore compiled files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I might rename createArchive and createTarArchive to make them clear that they are for different products/features (source deploy vs. local builds.)

@falahat
Copy link
Contributor Author

falahat commented Mar 19, 2026

I manually tested a local build and it was correctly deployed. Of course, env vars didn't work yet but I confirmed that:

  1. We didn't do a Cloud Build for this deployment
  2. The rollout (from CLI) was successful and I saw the new version/rollout on the Firebase Console
  3. I was able to use the deployed nextjs site

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