Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docker-compose.mongo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
services:
mongo:
container_name: ddev-${DDEV_SITENAME}-mongo
image: ${MONGO_DOCKER_IMAGE:-mongo:5-focal}
image: ${MONGO_DOCKER_IMAGE:-mongo:latest}
volumes:
- type: "volume"
source: mongo
Expand All @@ -28,7 +28,7 @@ services:
# See https://github.com/docker-library/docs/tree/master/mongo#mongo_initdb_database
# - MONGO_INITDB_DATABASE=db
healthcheck:
test: ["CMD-SHELL", "mongo --eval 'db.runCommand(\"ping\").ok' localhost:27017/test --quiet"]
test: ["CMD-SHELL", "M=$(command -v mongosh || command -v mongo) && $$M --eval 'db.runCommand(\"ping\").ok' localhost:27017/test --quiet"]
timeout: 60s

mongo-express:
Expand Down
1 change: 1 addition & 0 deletions install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: mongo
project_files:
- commands/mongo/mongosh
- commands/host/mongo-express
- web-build/Dockerfile.mongo
- config.mongo.yaml
- docker-compose.mongo.yaml
- docker-compose.mongo_norouter.yaml
Expand Down
8 changes: 8 additions & 0 deletions tests/test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ health_checks() {
assert_success
assert_output --partial '"ok":1'

# Check mongo CLI utils availability in the "web" container
run ddev exec "mongosh 'mongodb://db:db@mongo:27017/test?authSource=admin' --quiet --eval 'JSON.stringify(db.getUsers())'"
assert_success
assert_output --partial '"ok":1'
run ddev exec 'mongodump --version'
assert_success
assert_output --partial 'mongodump version:'

# Start mongo-express profile
DDEV_DEBUG=true run ddev mongo-express
assert_success
Expand Down
15 changes: 15 additions & 0 deletions web-build/Dockerfile.mongo
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ddev-generated
RUN <<EOF
LATEST_FULL_VERSION=$(curl -s "https://s3.amazonaws.com/repo.mongodb.org?list-type=2&prefix=apt/debian/dists/bookworm/mongodb-org/&delimiter=/" | grep -oP '(?<=<Prefix>)[^<]+mongodb-org/\K[0-9]+\.[0-9]+' | sort -V | tail -1 || echo "8.2")
# Extract major version for GPG key (e.g., "8.2" -> "8.0")
MAJOR_VERSION=$(echo "$LATEST_FULL_VERSION" | cut -d. -f1)
GPG_VERSION="${MAJOR_VERSION}.0"
echo "Latest MongoDB version: $LATEST_FULL_VERSION, using GPG key for: $GPG_VERSION"
# Add MongoDB GPG key using major version
wget -qO - https://www.mongodb.org/static/pgp/server-${GPG_VERSION}.asc | gpg --dearmor -o /usr/share/keyrings/mongodb-server-${GPG_VERSION}.gpg
# Add repository using the full version
KEYRING_PATH="/usr/share/keyrings/mongodb-server-${GPG_VERSION}.gpg"
printf "Types: deb\nURIs: http://repo.mongodb.org/apt/debian\nSuites: bookworm/mongodb-org/${LATEST_FULL_VERSION}\nComponents: main\nSigned-By: ${KEYRING_PATH}\n" > /etc/apt/sources.list.d/mongodb-archive.sources
(apt-get update || true)
apt-get install -y mongodb-mongosh mongodb-database-tools
EOF