-
Notifications
You must be signed in to change notification settings - Fork 169
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
base: master
Are you sure you want to change the base?
Conversation
mongo/docker-healthcheck
Outdated
# 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 |
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.
I think I'd rather make sure we still support both versions with something slightly more complex/less repetitive like this:
# 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 🙇)
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.
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.
I notice the
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:
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:
|
Due an upgrade of mongodb version 6.0.0+ The
mongo
command was changed tomongosh
command.