-
Notifications
You must be signed in to change notification settings - Fork 0
add mongodb config #4
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: nurok
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -177,6 +177,65 @@ else | |||||
| echo "NextMTA configuration not found in .env file, skipping nextMTA setup" | ||||||
| fi | ||||||
|
|
||||||
| # Configure external MongoDB from environment variables if set | ||||||
| if [ -n "$MONGO_URL" ]; then | ||||||
| echo "Configuring external MongoDB from environment variables" | ||||||
|
|
||||||
| # Escape special characters in MONGO_URL for sed | ||||||
| MONGO_URL_ESCAPED=$(echo "$MONGO_URL" | sed 's/[[\.*^$()+?{|]/\\&/g') | ||||||
|
|
||||||
| # Update Wildduck dbs.toml | ||||||
| WILDDUCK_DBS="./config-generated/config-generated/wildduck/dbs.toml" | ||||||
| sed -i "s|mongo = \"mongodb://mongo:27017/wildduck\"|mongo = \"$MONGO_URL_ESCAPED\"|" "$WILDDUCK_DBS" | ||||||
|
|
||||||
| # Update Zone-MTA dbs-production.toml | ||||||
| ZONEMTA_DBS_PROD="./config-generated/config-generated/zone-mta/dbs-production.toml" | ||||||
| sed -i "s|mongo = \"mongodb://mongo:27017/wildduck\"|mongo = \"$MONGO_URL_ESCAPED\"|" "$ZONEMTA_DBS_PROD" | ||||||
|
|
||||||
| # Update Zone-MTA dbs-development.toml (extract database name from URL if needed) | ||||||
| ZONEMTA_DBS_DEV="./config-generated/config-generated/zone-mta/dbs-development.toml" | ||||||
| # Extract database name from MONGO_URL (default to wildduck if not specified) | ||||||
| MONGO_DB_NAME=$(echo "$MONGO_URL" | sed -n 's|.*/\([^?]*\).*|\1|p') | ||||||
| if [ -z "$MONGO_DB_NAME" ]; then | ||||||
| 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|") | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Suggested change
|
||||||
| MONGO_URL_DEV_ESCAPED=$(echo "$MONGO_URL_DEV" | sed 's/[[\.*^$()+?{|]/\\&/g') | ||||||
| sed -i "s|mongo = \"mongodb://mongo:27017/zone-mta\"|mongo = \"$MONGO_URL_DEV_ESCAPED\"|" "$ZONEMTA_DBS_DEV" | ||||||
|
|
||||||
| # Update Haraka wildduck.yaml | ||||||
| HARAKA_WILDDUCK="./config-generated/config-generated/haraka/wildduck.yaml" | ||||||
| sed -i "s|url: \"mongodb://mongo:27017/wildduck\"|url: \"$MONGO_URL_ESCAPED\"|" "$HARAKA_WILDDUCK" | ||||||
|
|
||||||
| echo "External MongoDB configured: $MONGO_URL" | ||||||
|
|
||||||
| # Remove mongo from depends_on in docker-compose.yml if using external MongoDB | ||||||
| DOCKER_COMPOSE="./config-generated/docker-compose.yml" | ||||||
| echo "Removing mongo service dependencies from docker-compose.yml" | ||||||
|
|
||||||
| # Remove mongo from depends_on lists (keep redis) | ||||||
| # Handle different indentation levels | ||||||
| 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" | ||||||
|
Comment on lines
+219
to
+231
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The For more robust modifications of YAML files, consider using a YAML-aware command-line tool like |
||||||
|
|
||||||
| echo "MongoDB service and dependencies removed from docker-compose.yml" | ||||||
| echo "Note: Please review docker-compose.yml and ensure mongo dependencies are properly removed" | ||||||
| else | ||||||
| echo "MONGO_URL not set in .env file, using default MongoDB container" | ||||||
| fi | ||||||
|
|
||||||
| # Wildduck | ||||||
| sed -i "s/hostname=\"email.example.com\"/hostname=\"$HOSTNAME\"/" ./config-generated/config-generated/wildduck/imap.toml | ||||||
| sed -i "s/hostname=\"email.example.com\"/hostname=\"$HOSTNAME\"/" ./config-generated/config-generated/wildduck/pop3.toml | ||||||
|
|
||||||
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.
The
sedcommand to escapeMONGO_URLhas a syntax error. The character class[["\.*^$()+?{|]is not terminated with a]. This will cause the script to fail with anunterminated [error whenMONGO_URLis set.Additionally, this command is attempting to escape regex metacharacters. For a
sedreplacement string, you should instead escape&,\, and the delimiter (in this case|).