Repository navigation
fix: exclude .env files from the build context - #315
Merged
Merged
Conversation
`.dockerignore` re-includes all of `cloud_registry/`, so a local `cloud_registry/.env` would reach the build context and the layer and cache of the build stage (finding L3 of the rc1 pre-release review). It now excludes `.env` and `.env.*` files in all paths, except `.env.example`. Tests check the build context with Docker's matching rules (the last matching pattern decides). Closes #312 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review findings: `**/.env` and `**/.env.*` missed files such as `.envrc` or `.env-prod`, so the pattern is now `**/.env*`, as in the org rule. The `.env.example` exception is dropped: the build copies no example, and an exception with wildcards makes Docker walk all excluded directories. The test emulation now supports character classes (`**/*.py[cod]`), and `.gitignore` also ignores `.env.*`. Refs #312 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The emulation of Docker's matching copies character classes unchanged, as moby does (ranges, negations), and `.gitignore` ignores all `.env*` files (e.g., `.envrc`), as `.dockerignore` does. Review findings of round 2. Refs #312 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideThe PR prevents File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #315 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 22 22
Lines 2366 2366
=========================================
Hits 2366 2366 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
uniqueg
marked this pull request as ready for review
November 1, 2026 12:23
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="tests/test_image_build.py" line_range="313" />
<code_context>
+ for path in [
+ ".env",
+ ".env.local",
+ ".env.example",
+ "cloud_registry/.env",
+ "cloud_registry/.env.production",
</code_context>
<issue_to_address>
**Keep env example available**
The issue asks to re-include `.env.example`, but the test lists it among paths that must be excluded, matching the current behavior. Add the requested exception and test that the example remains in the build context.
</issue_to_address>Linked issues
#312 Exclude .env files from the image build context · 1 of 2 met
| # | Requirement | Status | Notes |
|---|---|---|---|
| 1 | Exclude .env and .env.* files from the build context, while re-including .env.example. |
🟡 Partly met | The broader **/.env* pattern excludes the requested secret files, but .env.example is excluded rather than re-included. |
| 2 | Test the build-context exclusion in tests/test_image_build.py. |
✅ Met | The added tests check that .env-named paths are excluded from the context. |
Sourcery assessment
Approval pending. 1 finding to address first.
Blocking findings: tests/test_image_build.py:313
This was referenced Nov 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #312 (finding L3 of the v1.0.0rc1 whole-repo pre-release review).
.dockerignorenow excludes**/.env*, after the allowlist, so local secret files (.env,.env.local,.envrc,.env-prod, directories named.env…) stay out of the build context, also inside the re-includedcloud_registry/(which the build stage copies into a layer). The final image was not affected (it only installs the wheel)..env.exampleis not re-included: the build copies no example, and an exception with wildcards (!**/.env.example) makes BuildKit walk every excluded directory (.git,.venv, …). The org rule allows, but doesn't require, keeping examples..gitignorealso ignores.env*(it only had.env), except.env.example.tests/test_image_build.pycheck the build context with an emulation of Docker's matching (moby patternmatcher: last match wins,**/matches zero or more directories, parent-directory matches, character classes): needed files are kept, caches and.env*files are excluded.No docs change: no doc describes the build context.
Verification
test_context_without_env_filesfailed before the.dockerignorechange.pytest tests/test_image_build.py: 8 passed; the full suite and coverage ran on the other branches of this series (this change adds tests only).pre-commit run --all-files: passed..envfiles (the Docker socket isn't available in the agent sandbox); the reviewers checked the patterns against moby's matching rules.CI passed).Review
Full lane (security). Round 1: lows only (pattern narrower than
.env*, the costly example exception, character classes in the emulation, boundary paths, comment wording); all fixed. Round 2 (adversarial): lows only (copy classes unchanged,.gitignore.env*); fixed.Declined review findings
test_context_fileschecks the existing include/exclude rules beyond Exclude .env files from the image build context #312 (low): kept, as it guards the emulation against the base rules (*,!cloud_registry/).Open questions
None.
🤖 Generated with Claude Code
Summary by Sourcery
Prevent local environment files from entering Docker build contexts and add regression coverage for the ignore rules.
Bug Fixes:
.env*secret files from Docker build contexts, including files under re-included directories.Enhancements:
.env*files while retaining.env.examplein Git.Tests:
.env*files are excluded using Docker-compatible matching behavior.