Browse Source

new: [mongo] add support for 6.0.* version

master
Valentin Lab 1 week ago
parent
commit
a24bf37825
  1. 48
      mongo/actions/upgrade
  2. 5
      mongo/hooks/init
  3. 6
      mongo/lib/common
  4. 3
      mongo/upgrade/build/6.0.19/Dockerfile
  5. 3
      mongo/upgrade/build/7.0.15/Dockerfile

48
mongo/actions/upgrade

@ -79,31 +79,45 @@ mongo:image:version() {
}
mongo:container:version() {
local container="$1"
if ! out=$(docker exec -i "$container" mongo --version); then
local container="$1" version
if ! out=$(docker exec "$container" mongod --version); then
err "Couldn't infer container's '$container' mongod's version."
exit 1
return 1
fi
out=${out%%$'\n'*}
out=${out%%$'\r'*}
image_version=${out#db version v}
echo "$image_version"
version=${out#db version v}
echo "$version"
}
mongo:container:mongo () {
local container="$1"
docker exec -i "$container" mongo 2>&1
}
mongo:container:fix_compat() {
local container="$1" image_version="$2"
out=$(echo "db.adminCommand( { setFeatureCompatibilityVersion: \"${image_version%.*}\" } )" |
mongo:container:mongo "$container" 2>&1)
if [[ "$out" == *"\"ok\" : 1"* ]]; then
local container="$1" image_version="$2" version
if ! version=$(mongo:container:version "$container"); then
err "Couldn't get container's mongod version"
return 1
fi
## No need of confirmation for version < 7.0.0
if version_gt 7.0.0 "$version"; then
mongo_cmd="db.adminCommand( { setFeatureCompatibilityVersion: \"${image_version%.*}\" } )"
else
mongo_cmd="db.adminCommand( { setFeatureCompatibilityVersion: \"${image_version%.*}\", confirm: true } )"
fi
out=$(echo "$mongo_cmd" | mongo:container:mongo "$container" 2>&1)
if [[ "$out" == *"\"ok\" : 1"* ]] || [[ "$out" == *"ok: 1"* ]]; then
debug "Feature Compatibility set to ${WHITE}${image_version%.*}${NORMAL}"
else
err "Failed to set feature compatibility version to ${WHITE}${image_version%.*}${NORMAL}:"
echo "$out" | prefix " | " >&2
printf "%s" "$out" | prefix " | " >&2
return 1
fi
}
@ -202,13 +216,18 @@ if [ -n "$containers" ]; then
#err "Running container(s) for $DARKYELLOW$SERVICE_NAME$NORMAL are still running:"
for container in $containers; do
debug "Stopping container $container"
docker stop "$container" >/dev/null || {
docker:container:stop "$container" >/dev/null || {
err "Failed to stop container '$container'."
exit 1
}
docker rm "$container" > /dev/null || {
err "Couldn't delete container '$container'."
}
docker rm "$container" > /dev/null
## Check that the container is actually removed
if [ -n "$(docker ps -q -f name="$container")" ]; then
err "Failed to remove container '$container'."
exit 1
fi
container_stopped+=("$container")
done
fi
@ -339,6 +358,7 @@ if [ -z "$unexpected_stop" -a -z "$expected_stop" ]; then
docker stop "$migration_container"
fi
if [ -n "$failed" ]; then
echo "${WHITE}Failing migration logs:${NORMAL}" >&2
cat "$MIGRATION_TMPDIR/migration.log" | prefix " ${GRAY}|${NORMAL} " >&2

5
mongo/hooks/init

@ -59,9 +59,10 @@ ensure_db_docker_running
cmd="rs.initiate({ _id: 'rs01', members: [ { _id: 0, host: '$SERVICE_NAME:27017' } ]})"
debug "${WHITE}running:$NORMAL $cmd"
out=$(ddb <<<"$cmd")
out=$(ddb 2>&1 <<<"$cmd") || true
if [[ "$out" == *"\"codeName\" : \"AlreadyInitialized\""* ]]; then
if [[ "$out" == *"\"codeName\" : \"AlreadyInitialized\""* ]] ||
[[ "$out" == *"MongoServerError: already initialized"* ]]; then
info "ReplicaSet already initialized."
elif [[ "$out" == *"\"ok\" : 1"* ]]; then
info "ReplicaSet initialized. "

6
mongo/lib/common

@ -46,7 +46,11 @@ _set_db_params() {
}
ddb() { dcmd mongo --quiet "$@"; }
ddb() {
local eval_code
eval_code="$(cat - )"
dcmd mongo --quiet "$@" --eval "$eval_code" </dev/null
}
djson() {

3
mongo/upgrade/build/6.0.19/Dockerfile

@ -1,4 +1,5 @@
FROM mongo:6.0.19
ENTRYPOINT [ "mongod", "--config", "/etc/mongod.conf" ]
RUN ln -sf /usr/bin/mongosh /usr/bin/mongo
ENTRYPOINT [ "mongod", "--config", "/etc/mongod.conf" ]

3
mongo/upgrade/build/7.0.15/Dockerfile

@ -1,4 +1,5 @@
FROM mongo:7.0.15
ENTRYPOINT [ "mongod", "--config", "/etc/mongod.conf" ]
RUN ln -sf /usr/bin/mongosh /usr/bin/mongo
ENTRYPOINT [ "mongod", "--config", "/etc/mongod.conf" ]
Loading…
Cancel
Save