fix(reaper): read RYUK_CONTAINER_IMAGE lazily so dotenv / runtime overrides work#1323
Open
dvirarad wants to merge 2 commits into
Open
fix(reaper): read RYUK_CONTAINER_IMAGE lazily so dotenv / runtime overrides work#1323dvirarad wants to merge 2 commits into
dvirarad wants to merge 2 commits into
Conversation
✅ Deploy Preview for testcontainers-node ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
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
Fixes #1310.
reaper.tsexportsREAPER_IMAGEas a top-levelconstwhose initializer readsprocess.env.RYUK_CONTAINER_IMAGEat module load time. As @reporter pointed out, that means anything that mutates the environment after the module is imported — most commonly adotenv.config()call in user code, or an explicitprocess.env.RYUK_CONTAINER_IMAGE = ...in a test setup file — is silently ignored, and the user gets the defaulttestcontainers/ryuk:0.14.0image regardless.This is inconsistent with every other
RYUK_*/TESTCONTAINERS_RYUK_*env var in the same file (lines 36, 93, 100, 103, 106, 109…), all of which are read lazily insidecreateNewReaper().Fix
Convert
REAPER_IMAGE(eager const) →getReaperImage()(lazy function), matching the existing pattern. Two files touched:packages/testcontainers/src/reaper/reaper.ts— export becomes a function, call site at the bottom ofcreateNewReaperusesgetReaperImage().packages/testcontainers/src/generic-container/generic-container.ts— the two=== REAPER_IMAGEcomparisons become=== getReaperImage().The function is cheap (one env lookup + an
ImageName.fromStringparse), and both comparisons happen at construction /isReaper()check time — not in a hot loop — so the lazy evaluation has no measurable overhead.API surface
REAPER_IMAGEwas an exported symbol, so this is technically a breaking change for any external consumer that imports it directly. Two notes:docs/configuration.mdand the README don't mentionREAPER_IMAGE— only the env varRYUK_CONTAINER_IMAGE— so the export was effectively internal.getReaperImageasREAPER_IMAGEvia an accessor (Object.definePropertygetter on the module's namespace), but that adds complexity for a name that wasn't documented. Happy to switch on request.Test plan
grepconfirms no otherREAPER_IMAGEreferences remain in the reporeaper.tsalready use the lazy pattern; this change bringsRYUK_CONTAINER_IMAGEinto alignmentreaper.test.tsusingvi.stubEnv("RYUK_CONTAINER_IMAGE", "...")+vi.resetModules()— happy to add if maintainers want it in this PR