Update docker-healthcheck for mongodb 6.0+ - #27
Open
edualb wants to merge 2 commits into
Open
Conversation
tianon
reviewed
Jun 13, 2023
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 |
Member
There was a problem hiding this comment.
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 🙇)
Author
There was a problem hiding this comment.
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.
Author
|
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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Due an upgrade of mongodb version 6.0.0+ The
mongocommand was changed tomongoshcommand.