-
-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Add support for uppercase GHOST_ environment variables
#25324
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
base: main
Are you sure you want to change the base?
Conversation
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. WalkthroughA specialized environment variable loader was added to the Nconf configuration setup to selectively process environment variables prefixed with Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Pre-merge checks and finishing touches✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
ghost/core/core/shared/config/loader.js(1 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: kevinansfield
Repo: TryGhost/Ghost PR: 25031
File: ghost/core/test/utils/fixtures/config/defaults.json:68-80
Timestamp: 2025-10-07T12:19:15.174Z
Learning: In Ghost's configuration system (ghost/core/core/shared/config/), environment-specific config files (e.g., config.development.json, config.production.json) automatically fall back to values defined in defaults.json. It's only necessary to specify changed overrides on a per-env basis. Missing keys in env configs are not an issue—they're intentional and will use the default values.
📚 Learning: 2025-10-07T12:19:15.174Z
Learnt from: kevinansfield
Repo: TryGhost/Ghost PR: 25031
File: ghost/core/test/utils/fixtures/config/defaults.json:68-80
Timestamp: 2025-10-07T12:19:15.174Z
Learning: In Ghost's configuration system (ghost/core/core/shared/config/), environment-specific config files (e.g., config.development.json, config.production.json) automatically fall back to values defined in defaults.json. It's only necessary to specify changed overrides on a per-env basis. Missing keys in env configs are not an issue—they're intentional and will use the default values.
Applied to files:
ghost/core/core/shared/config/loader.js
📚 Learning: 2025-10-30T17:13:26.190Z
Learnt from: sam-lord
Repo: TryGhost/Ghost PR: 25303
File: ghost/core/core/server/services/email-service/BatchSendingService.js:19-19
Timestamp: 2025-10-30T17:13:26.190Z
Learning: In ghost/core/core/server/services/email-service/BatchSendingService.js and similar files in the Ghost codebase, prefer using `{...options}` spread syntax without explicit guards like `...(options || {})` when spreading potentially undefined objects, as the maintainer prefers cleaner syntax over defensive patterns when the behavior is safe.
Applied to files:
ghost/core/core/shared/config/loader.js
🪛 ESLint
ghost/core/core/shared/config/loader.js
[error] 34-34: Expected { after 'if' condition.
(curly)
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
| obj.key = obj.key.replace(prefix, '').toLowerCase(); | ||
| return obj; | ||
| } | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Exclude GHOST_ vars in repeated env parsing
The second nconf.env() call will process all environment variables including those with the GHOST_ prefix, causing duplicate processing. Variables like GHOST_MAIL_OPTIONS_HOST will be stored twice: once as mail:options:host (from the first nconf.env call at line 29-43) and once as GHOST_MAIL_OPTIONS_HOST (from this call). This creates redundant entries and potential conflicts. The second call should exclude GHOST_ prefixed variables by adding a transform function that returns false for keys matching /^GHOST_/.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is done to allow for backwards compatibility. However, tell me if you prefer to do as suggested here.
Motivation: Ensure best practices for environment variables by using uppercase naming and the
GHOST_prefix (to avoid collisions with generic variables likeurl), such asGHOST_MAIL_OPTIONS_HOST.What: Add
nconfconfiguration to load environmental variables prefixed withGHOST_. The prefix is stripped and the variable is converted to lower case. These environment variables take higher precedence than the previous lowercase ones likemail__options__host.Why: This change was requested by the community (#21021) and aligns with recommended environment variable practices.
Testing
I haven't added an automated test. Two possible approaches:
Ghost/e2e/compose.yml
Lines 27 to 31 in d3ee99c
Please tell me which approach (or alternatives) you recommend to test this. Thanks!
PR checklist
Note
Adds
nconfhandling forGHOST_-prefixed env vars (e.g., GHOST_MAIL_OPTIONS_HOST), stripping the prefix, lowercasing keys, and loading them before existing__-based vars.core/shared/config/loader.js):nconf.envhandler forGHOST_-prefixed environment variables._separator, stripsGHOST_prefix, lowercases keys, and parses values.nconf.envwith__separator to take precedence.Written by Cursor Bugbot for commit 44b8694. This will update automatically on new commits. Configure here.