Skip to content
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

Update docker-healthcheck for mongodb 6.0+ #27

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

edualb
Copy link

@edualb edualb commented Jun 13, 2023

Due an upgrade of mongodb version 6.0.0+ The mongo command was changed to mongosh command.

Comment on lines 6 to 14
# version < 6.0.0
# if mongo --quiet "$host/test" --eval 'quit(db.runCommand({ ping: 1 }).ok ? 0 : 2)'; then
# exit 0
# fi

# version > 6.0.0
if mongosh --quiet "$host/test" --eval 'quit(db.runCommand({ ping: 1 }).ok ? 0 : 2)'; then
exit 0
fi
Copy link
Member

Choose a reason for hiding this comment

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

I think I'd rather make sure we still support both versions with something slightly more complex/less repetitive like this:

Suggested change
# version < 6.0.0
# if mongo --quiet "$host/test" --eval 'quit(db.runCommand({ ping: 1 }).ok ? 0 : 2)'; then
# exit 0
# fi
# version > 6.0.0
if mongosh --quiet "$host/test" --eval 'quit(db.runCommand({ ping: 1 }).ok ? 0 : 2)'; then
exit 0
fi
for cmd in mongosh mongo; do
if command -v "$cmd" > /dev/null; then
if "$cmd" --quiet "$host/test" --eval 'quit(db.runCommand({ ping: 1 }).ok ? 0 : 2)'; then
exit 0
else
exit 1
fi
fi
done
echo >&2 'error: neither of "mongo" or "mongosh" available'

(thanks for the PR and I'm happy to take over from here if you'd prefer 🙇)

Copy link
Author

Choose a reason for hiding this comment

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

Makes sense. To be honest I was lazy yesterday hahaha I can apply and test it soon 😄

Include Dockerfiles for mongo version 4.4, 5.0 and latest in order to test mongo and mongosh commands.
@edualb
Copy link
Author

edualb commented Jun 14, 2023

I notice the mongosh was introduced in 4.2 version: https://www.mongodb.com/docs/mongodb-shell/install/#std-label-mdb-shell-install

  • "You can use the MongoDB Shell to connect to MongoDB version 4.2 or greater."

However, I notice version 4.4 was not working and the mongosh was included just in 5.0+, so, I decided to build 3 images:

  • 4.4 version
  • 5.0 version
  • latest version

With these images I can test using the following command:

git clone https://github.com/edualb/healthcheck.git
cd ./healthcheck

git switch patch-1
cd ./mongo

docker build -f ./Dockerfile.4.4 -t mongo-healthy:4.4 . \
    && docker build -f ./Dockerfile.5.0 -t mongo-healthy:5.0 . \
    && docker build -f ./Dockerfile.latest -t mongo-healthy:latest .

docker run -d mongo-healthy:4.4 \
    && docker run -d mongo-healthy:5.0 \
    && docker run -d mongo-healthy:latest

# You can follow the healthy of each container by running docker ps
docker ps

# After checking if it is working or not you can remove all containers:
docker rm -rf $(docker ps -q)

output:

CONTAINER ID   IMAGE                  COMMAND                  CREATED         STATUS                   PORTS       NAMES
d2b77d5bcc46   mongo-healthy:latest   "docker-entrypoint.s…"   6 minutes ago   Up 6 minutes (healthy)   27017/tcp   funny_shaw
8032e78b6f79   mongo-healthy:5.0      "docker-entrypoint.s…"   6 minutes ago   Up 6 minutes (healthy)   27017/tcp   admiring_beaver
52a25acfe7e6   mongo-healthy:4.4      "docker-entrypoint.s…"   6 minutes ago   Up 6 minutes (healthy)   27017/tcp   boring_gould

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.

2 participants