Skip to content

feat: Add .env.<codebase> support for multi-instance functions #8967

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

Closed
wants to merge 2 commits into from

Conversation

taeold
Copy link
Contributor

@taeold taeold commented Aug 14, 2025

Summary

Adds support for .env.<codebase> environment files as an enhancement to the multi-instance functions feature from #8911.

This enables per-codebase environment variable isolation by adding .env.<codebase> to the environment file loading precedence.

Environment File Precedence (Updated)

  1. .env (global defaults)
  2. .env.<codebase> (codebase-specific) ← NEW
  3. .env.<project|alias> (project overrides)
  4. .env.local (emulator only)

Changes

  • Updated UserEnvsOpts interface to include required codebase parameter
  • Modified findEnvfiles() to load .env.<codebase> files in correct precedence order
  • Added unit tests for codebase environment variable functionality
  • Updated all callers to pass codebase parameter

Related

This builds on the multi-instance functions implementation in #8911 by adding the environment variable isolation component described in the original design spec.

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.

Summary of Changes

Hello @taeold, 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 enhances the multi-instance functions feature by introducing support for codebase-specific environment variables through .env.<codebase> files. This allows developers to define distinct environment configurations for different function codebases, even if they share the same source directory. Additionally, it adds the ability to specify a prefix for function names, ensuring uniqueness and better organization when deploying multiple instances of functions from a single source. These changes improve environment isolation and naming flexibility for complex function deployments.

Highlights

  • Codebase-Specific Environment Variables: Introduced support for .env.<codebase> files, allowing environment variables to be isolated and configured per codebase in multi-instance functions.
  • Environment File Precedence: Updated the environment variable loading precedence to prioritize .env.<codebase> files over global .env files, but still allow .env.<project|alias> and .env.local (for emulators) to override them.
  • Function Naming with Prefixes: Added a new prefix property to function configurations, enabling unique naming for functions that share the same source code across different codebases.
  • Configuration Validation: Implemented validation for the new prefix property, ensuring it adheres to naming conventions and that source-prefix pairs are unique.
  • Emulator Support: Extended the Functions Emulator to correctly handle and apply codebase-specific environment variables and function prefixes during local development and testing.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

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 issue 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 support for .env.<codebase> environment files and function name prefixes, enhancing multi-instance function capabilities. The changes are well-implemented across configuration, deployment, and emulation, with thorough test coverage. My review identified a type-related bug in the emulator's prefix handling logic that could cause runtime issues. I've provided a fix and also suggested refactoring some duplicated code to improve maintainability. Overall, this is a solid contribution.

taeold added 2 commits August 13, 2025 19:49
Implements environment variable isolation per codebase to support
multi-instance function deployments where the same source can be
deployed multiple times with different configurations.

Environment file precedence order:
1. .env (global defaults for all functions in source)
2. .env.<codebase> (codebase-specific settings)
3. .env.<project|alias> (project-specific overrides)
4. .env.local (emulator-only, highest precedence)

Changes:
- Update UserEnvsOpts interface to require codebase parameter
- Modify findEnvfiles() to include .env.<codebase> in search order
- Update all function calls to pass codebase parameter
- Add comprehensive unit tests for codebase environment variables
- Fix compilation errors in test files

Enables configuration isolation for multi-instance deployments like:
- .env.profile-pics-resizer for profile picture functions
- .env.gallery-pics-resizer for gallery picture functions
@taeold taeold force-pushed the feat-codebase-env-files branch from 6f59a04 to 9adf98c Compare August 14, 2025 02:50
@taeold
Copy link
Contributor Author

taeold commented Aug 14, 2025

/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 adds support for codebase-specific environment files (.env.<codebase>), which is a great enhancement for managing multi-instance functions. The implementation correctly adjusts the environment file loading precedence and updates all relevant parts of the codebase. The new unit tests are comprehensive and cover the new functionality well. The code is clean and well-structured. I have no suggestions for improvement.

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.

1 participant