Skip to content

Added .env.example file to simplify getting started with docker compose#22247

Merged
cmraible merged 2 commits into
TryGhost:mainfrom
cmraible:add-env-example
Feb 19, 2025
Merged

Added .env.example file to simplify getting started with docker compose#22247
cmraible merged 2 commits into
TryGhost:mainfrom
cmraible:add-env-example

Conversation

@cmraible
Copy link
Copy Markdown
Collaborator

@cmraible cmraible commented Feb 19, 2025

no issue

  • To run Ghost itself in docker compose, you need to enable the ghost profile by setting COMPOSE_PROFILES=ghost.
  • This is done for you if you use the yarn docker:* commands, but if you run any other docker compose ... commands manually, the ghost profile won't be enabled by default.
  • The easiest way to set COMPOSE_PROFILES is with a .env file in the root of the repo. This .env.example file is a template than can be easily copied to .env by running cp .env.example .env, which will in turn enable the ghost profile.
  • It also includes commented out environment variables that are useful when running Ghost in Docker compose, such as stripe keys, app flags (for running e.g. portal), and DEBUG modes.

This commit also includes some minor changes to the dev.js script:

  • Adds a list of availableFlags, including all the app flags that it will accept
  • Adds validation to log an error and exit if any invalid flags are passed. This will force us to keep this list up to date if/when we add more app flags
  • Adds a show-flags flag, which will print all the available flags, along with a description, then immediately exit.

Ultimately this makes getting started with docker compose more straight forward:

  • Clone the repo
  • Run cp .env.example .env to enable the ghost profile
  • Run docker compose up

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 19, 2025

Walkthrough

The pull request introduces a new .env.example file that outlines environment variables necessary for Ghost development using Docker Compose. This file serves as a template, guiding users on how to create and configure a .env file by providing placeholders and comments for settings such as the Docker Compose profile, debug level, application flags, and Stripe keys. Additionally, the pull request updates the development script located in .github/scripts/dev.js by adding an availableAppFlags object that describes valid application flags. The script now validates the flags provided through the GHOST_APP_FLAGS environment variable, displaying available flags and exiting the process if any invalid flags are detected. These changes collectively enhance the management of environment configuration and application flag handling for developers.

Possibly Related PRs

  • Rename compose profile to ghost #22223: Modifies the Docker Compose configuration and introduces the GHOST_DEV_IS_DOCKER variable, closely aligning with the environment variable setup in the new .env.example file.
  • Removed env_file from compose.yml #22104: Removes the env_file configuration from compose.yml, impacting how environment variables are managed, which is related to the new configuration approach provided in the .env.example file.
  • Improved configuration setup for Docker development #22224: Enhances the configuration setup for Docker development by adding a new configuration file and streamlining the process, focusing on improving configuration management for running Ghost in a Docker environment.
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
.github/scripts/dev.js (1)

51-68: Consider consolidating announcement bar flag variations.

The availableAppFlags object includes three variations of the announcement bar flag: 'announcementBar', 'announcementbar', and 'announcement-bar'. This could lead to maintenance issues and confusion.

Consider standardizing on a single flag name, preferably 'announcement-bar' to match the kebab-case pattern used in other flags like 'show-flags' and 'browser-tests'. Update the corresponding check at line 200 accordingly.

const availableAppFlags = {
    'show-flags': 'Show available app flags, then exit',
    stripe: 'Run `stripe listen` to forward Stripe webhooks to the Ghost instance',
    all: 'Run all apps',
    ghost: 'Run only Ghost',
    admin: 'Run only Admin',
    'browser-tests': 'Run browser tests',
-   announcementBar: 'Run Announcement Bar',
-   announcementbar: 'Run Announcement Bar',
    'announcement-bar': 'Run Announcement Bar',
    portal: 'Run Portal',
    signup: 'Run Signup Form',
    search: 'Run Sodo Search',
    lexical: 'Use your local instance of the Lexical editor running in a separate process',
    comments: 'Run Comments UI',
    https: 'Serve apps using HTTPS',
    offline: 'Run in offline mode (no Stripe webhooks will be forwarded)'
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cee2b99 and 89f214420f07d9ce79c862a2985e15b9238024a6.

📒 Files selected for processing (2)
  • .env.example (1 hunks)
  • .github/scripts/dev.js (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .env.example
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: Regression tests (Node 20.11.1, mysql8)
  • GitHub Check: Database tests (Node 20.11.1, sqlite3)
  • GitHub Check: Database tests (Node 22.13.1, mysql8)
  • GitHub Check: Database tests (Node 20.11.1, mysql8)
  • GitHub Check: Ghost-CLI tests
  • GitHub Check: Database tests (Node 18.12.1, mysql8)
  • GitHub Check: Admin-X Settings tests
  • GitHub Check: Admin tests - Chrome
🔇 Additional comments (2)
.github/scripts/dev.js (2)

73-97: LGTM! Well-implemented flag validation and help display.

The implementation includes:

  • Clear and informative help text with proper formatting
  • Robust flag validation against available flags
  • Consistent debug logging
  • Appropriate error handling and process exit

71-71: LGTM! Improved flag handling robustness.

The addition of .filter(flag => flag.trim().length > 0) prevents issues with empty flags that could arise from trailing commas in the environment variable.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
.github/scripts/dev.js (2)

51-68: Standardize flag naming convention.

The availableAppFlags object contains inconsistent naming patterns and multiple aliases for the same functionality:

  • Mixed usage of camelCase (announcementBar), kebab-case (announcement-bar), and lowercase (announcementbar)
  • Multiple aliases increase maintenance overhead and may confuse users

Consider standardizing on kebab-case for all flags and deprecating aliases:

 const availableAppFlags = {
     'show-flags': 'Show available app flags, then exit',
     stripe: 'Run `stripe listen` to forward Stripe webhooks to the Ghost instance',
     all: 'Run all apps',
     ghost: 'Run only Ghost',
     admin: 'Run only Admin',
     'browser-tests': 'Run browser tests',
-    announcementBar: 'Run Announcement Bar',
-    announcementbar: 'Run Announcement Bar',
     'announcement-bar': 'Run Announcement Bar (preferred)',
     portal: 'Run Portal',
     signup: 'Run Signup Form',
     search: 'Run Sodo Search',
     lexical: 'Use your local instance of the Lexical editor running in a separate process',
     comments: 'Run Comments UI',
     https: 'Serve apps using HTTPS',
     offline: 'Run in offline mode (no Stripe webhooks will be forwarded)'
 }

83-96: Consider enhancing flag validation.

The current validation is good but could be more robust by:

  1. Checking for mutually exclusive flags (e.g., 'all' with individual app flags)
  2. Validating flag combinations (e.g., 'https' requires at least one app flag)

Example implementation:

 if (GHOST_APP_FLAGS.includes('show-flags')) {
     showAvailableAppFlags();
     process.exit(0);
 }

+// Check for mutually exclusive flags
+if (GHOST_APP_FLAGS.includes('all') && 
+    (GHOST_APP_FLAGS.includes('ghost') || 
+     GHOST_APP_FLAGS.includes('admin') || 
+     GHOST_APP_FLAGS.includes('portal'))) {
+    console.error(chalk.red('Error: The "all" flag cannot be used with individual app flags'));
+    showAvailableAppFlags();
+    process.exit(1);
+}
+
+// Check for required flag combinations
+if (GHOST_APP_FLAGS.includes('https') && 
+    !GHOST_APP_FLAGS.some(flag => ['all', 'portal', 'comments'].includes(flag))) {
+    console.error(chalk.red('Error: The "https" flag requires at least one app flag'));
+    showAvailableAppFlags();
+    process.exit(1);
+}

 // Check for invalid flags
 debug('checking for invalid flags', GHOST_APP_FLAGS);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 89f214420f07d9ce79c862a2985e15b9238024a6 and dd2b766.

📒 Files selected for processing (2)
  • .env.example (1 hunks)
  • .github/scripts/dev.js (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • .env.example
🔇 Additional comments (2)
.github/scripts/dev.js (2)

73-81: LGTM! Clear and helpful flag documentation.

The showAvailableAppFlags function provides excellent user guidance by:

  • Explaining both environment variable and command-line flag usage
  • Clarifying Docker-specific limitations
  • Listing all available flags with descriptions

156-258: LGTM! Well-structured flag handling with clear documentation.

The implementation demonstrates:

  • Consistent flag usage pattern
  • Clear documentation of HTTPS configurations with Caddyfile examples
  • Proper environment variable handling for each feature

@cmraible cmraible merged commit 5547c0b into TryGhost:main Feb 19, 2025
@cmraible cmraible deleted the add-env-example branch February 19, 2025 21:16
cmraible added a commit to cmraible/Ghost that referenced this pull request Feb 21, 2025
@coderabbitai coderabbitai Bot mentioned this pull request Feb 21, 2025
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