Skip to content

add mongodb config - #4

Open
grok97 wants to merge 1 commit into
nurokfrom
grok
Open

add mongodb config#4
grok97 wants to merge 1 commit into
nurokfrom
grok

Conversation

@grok97

@grok97 grok97 commented Dec 5, 2025

Copy link
Copy Markdown

No description provided.

@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello @grok97, 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 enables the integration of an external MongoDB instance with the application. By defining the MONGO_URL environment variable, users can now opt out of using the default Dockerized MongoDB container. The setup.sh script has been enhanced to automatically reconfigure all relevant application components and adjust the docker-compose.yml file to reflect this change, streamlining the process of connecting to an external database.

Highlights

  • External MongoDB Support: Introduced configuration options and setup logic to allow the use of an external MongoDB instance, providing greater deployment flexibility.
  • Environment Variable Configuration: Added MONGO_URL examples to example.env to guide users on how to configure an external MongoDB connection string.
  • Automated Setup Script Updates: The setup.sh script now automatically updates various application configuration files (e.g., wildduck/dbs.toml, zone-mta/dbs-production.toml, haraka/wildduck.yaml) to use the specified external MongoDB URL if MONGO_URL is provided.
  • Docker Compose Integration: The setup.sh script modifies docker-compose.yml to remove dependencies on and comment out the local MongoDB service definition when an external MONGO_URL is configured, preventing conflicts and unnecessary resource usage.
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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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.

@grok97
grok97 requested a review from jasonaix December 5, 2025 09:47

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

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 functionality to configure an external MongoDB instance by setting a MONGO_URL in the .env file. The changes in setup.sh correctly identify when the variable is set and proceed to update various configuration files and the docker-compose.yml.

My review has identified a critical issue that will cause the script to fail, a high-severity bug that could lead to incorrect MongoDB connection strings for development environments, and some medium-severity concerns about the script's robustness when modifying the YAML configuration. I've provided suggestions to fix these issues.

Comment thread setup.sh
echo "Configuring external MongoDB from environment variables"

# Escape special characters in MONGO_URL for sed
MONGO_URL_ESCAPED=$(echo "$MONGO_URL" | sed 's/[[\.*^$()+?{|]/\\&/g')

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

critical

The sed command to escape MONGO_URL has a syntax error. The character class [["\.*^$()+?{|] is not terminated with a ]. This will cause the script to fail with an unterminated [ error when MONGO_URL is set.

Additionally, this command is attempting to escape regex metacharacters. For a sed replacement string, you should instead escape &, \, and the delimiter (in this case |).

Suggested change
MONGO_URL_ESCAPED=$(echo "$MONGO_URL" | sed 's/[[\.*^$()+?{|]/\\&/g')
MONGO_URL_ESCAPED=$(echo "$MONGO_URL" | sed -e 's/\\/\\\\/g' -e 's/|/\\|/g' -e 's/&/\\&/g')

Comment thread setup.sh
MONGO_DB_NAME="wildduck"
fi
# Replace the database name in the connection string for development
MONGO_URL_DEV=$(echo "$MONGO_URL" | sed "s|/[^/]*$|/$MONGO_DB_NAME|")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The sed command used to generate MONGO_URL_DEV incorrectly strips query parameters from the original MONGO_URL. The regex s|/[^/]*$|... matches from the last / to the end of the string, which includes any ?options part. For example, if MONGO_URL is mongodb://.../db?authSource=admin, MONGO_URL_DEV will become mongodb://.../db, losing the authSource option. This is likely to cause connection issues.

Suggested change
MONGO_URL_DEV=$(echo "$MONGO_URL" | sed "s|/[^/]*$|/$MONGO_DB_NAME|")
MONGO_URL_DEV=$(echo "$MONGO_URL" | sed 's#/[^/?]*#/'"$MONGO_DB_NAME"'#')

Comment thread setup.sh
Comment on lines +219 to +231
sed -i '/depends_on:/,/^ [a-z]/ { /^[[:space:]]*- mongo$/s/^/#/; }' "$DOCKER_COMPOSE"

# Comment out the mongo service definition
# Find the mongo service block and comment it out
awk '
/^ mongo:/ { in_mongo=1 }
in_mongo && /^ [a-z]/ && !/^ mongo/ { in_mongo=0 }
in_mongo { print "#" $0; next }
{ print }
' "$DOCKER_COMPOSE" > "$DOCKER_COMPOSE.tmp" && mv "$DOCKER_COMPOSE.tmp" "$DOCKER_COMPOSE"

# Comment out mongo volume
sed -i 's/^ mongo:$/# mongo: # Removed: using external MongoDB/' "$DOCKER_COMPOSE"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The sed and awk commands used to modify docker-compose.yml are brittle. They rely on specific indentation (e.g., exactly two spaces) and assumptions about service naming (/^ [a-z]/). If the formatting of docker-compose.yml changes, these commands may fail or have unintended side effects. The note at the end of the script to manually review the file indicates awareness of this fragility.

For more robust modifications of YAML files, consider using a YAML-aware command-line tool like yq. This would make the script more reliable against formatting changes.

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