From 6fa422a32b554bdff1280c518cde477628f1db8f Mon Sep 17 00:00:00 2001 From: Valentin Lab Date: Tue, 17 Dec 2024 10:30:12 +0100 Subject: [PATCH] new: [mongo] switch to pre-built images with upgrade directory --- mongo/README.org | 57 ++++++++++++++++++++++----- mongo/build/Dockerfile | 19 --------- mongo/hooks/init | 34 ++++++++++++++++ mongo/metadata.yml | 1 + mongo/upgrade/build/4.0.24/Dockerfile | 4 ++ mongo/upgrade/build/5.0.30/Dockerfile | 4 ++ mongo/upgrade/build/6.0.19/Dockerfile | 4 ++ mongo/upgrade/build/7.0.15/Dockerfile | 4 ++ 8 files changed, 99 insertions(+), 28 deletions(-) delete mode 100644 mongo/build/Dockerfile create mode 100644 mongo/upgrade/build/4.0.24/Dockerfile create mode 100644 mongo/upgrade/build/5.0.30/Dockerfile create mode 100644 mongo/upgrade/build/6.0.19/Dockerfile create mode 100644 mongo/upgrade/build/7.0.15/Dockerfile diff --git a/mongo/README.org b/mongo/README.org index aaa38e7..db1a5a3 100644 --- a/mongo/README.org +++ b/mongo/README.org @@ -9,19 +9,58 @@ Since 4.0.6 based on alpine 3.9, alpine is not packaging mongo anymore. So we use the official version (that is huge). We still must change entrypoint to enforce proper directory paths. -A ``Dockerfile`` is provided for this mean. +*** Build new images -You can fetch latest official tags: -#+begin_quote -docker-tags-fetch mongo -l 10 -f '^[0-9]+\.[0-9]+\.[0-9]+$' -#+end_quote +Get the last upstream images versions with: -change it in docker file, then +#+begin_src sh +actions/upstream-versions -l 10 +#+end_src -#+begin_quote -docker build . -t docker.0k.io/mongo:"$TAG"-myc -#+end_quote +Then use these function to help you manage the ~upgrade/build~ +directory and create the ~*-myc~ images from upstream images: +#+begin_src sh +MONGO_VERSION=$( + docker-tags-fetch nextcloud -l 10 -f "^[0-9]+\.[0-9]+\.[0-9]+$" | + sort -V | + tail -n 1 | + cut -f 1 -d "-" +) + + +mk_build_dir() { + local new_version="$1" VLV VV T + ( + cd upgrade/build + + MONGO_LAST_VERSION=$( + find . -maxdepth 1 -mindepth 1 -type d -regex "./[0-9]+\.[0-9]+\.[0-9]+" -printf "%f\n" | + sort -V | tail -n 1) + + for variant in ""; do + if [ -z "$variant" ]; then + VLV="${MONGO_LAST_VERSION}" + VV="${new_version}" + T="${new_version}-myc" + else + VLV="${MONGO_LAST_VERSION}-$variant" + VV="${new_version}-$variant" + T="${new_version}-myc-$variant" + fi + + cp -r "${VLV}" "${VV}" + + sed -ri "s/FROM mongo:.*/FROM mongo:${new_version}/g" "$VV"/Dockerfile + + docker build "$VV" -t docker.0k.io/mongo:${T} || return 1 + docker push "docker.0k.io/mongo:${T}" || return 1 + done + + ) +} +mk_build_dir "$MONGO_VERSION" +#+end_src ** General Access diff --git a/mongo/build/Dockerfile b/mongo/build/Dockerfile deleted file mode 100644 index 7bd8ef4..0000000 --- a/mongo/build/Dockerfile +++ /dev/null @@ -1,19 +0,0 @@ -## Note: alpine version >= 3.9 is required to get mongodb version 4 -## is a simple copy of alpine:3.9 -FROM docker.0k.io/alpine:3.9 as common - -## mongodb-tools is only required because we expect and use mongodump -## XXXvlab: bash is only required by mongo-backup, we could probably only use sh -RUN apk add --no-cache mongodb mongodb-tools bash - -RUN mkdir -p /var/lib/mongod -RUN chown -R mongodb:mongodb /var/lib/mongod - -VOLUME ["/var/lib/mongodb"] -EXPOSE 27017 28017 - -USER mongodb - -ENTRYPOINT [ "mongod", "--config", "/etc/mongod.conf" ] - - diff --git a/mongo/hooks/init b/mongo/hooks/init index 6824288..e140d0b 100755 --- a/mongo/hooks/init +++ b/mongo/hooks/init @@ -16,6 +16,37 @@ set -e uid=$(docker_get_uid "$SERVICE_NAME" "mongodb") +## Check for old bogus version, and stop and remove container +## if it is running. + +containers=($(get_running_containers_for_service "$SERVICE_NAME")) + +if [[ "${#containers[@]}" -gt 1 ]]; then + err "More than 1 container running for service $DARKYELLOW$SERVICE_NAME$NORMAL." + echo " Please contact administrator to fix this issue." >&2 + return 1 +fi + +if [[ "${#containers[@]}" == 1 ]]; then + ## We need to check that this running container + ## has same uid as the new image. If not, we need + ## to stop and remove it. + container_id=${containers[0]} + container_uid=$(docker exec "$container_id" id -u mongodb) + if [[ "$container_uid" != "$uid" ]]; then + info "Container $container_id is running with different uid than new image." + info "Stopping container $container_id." + docker stop "$container_id" && + docker rm "$container_id" + fi +fi + + +## +## Normal init +## + + CONFIG=$SERVICE_CONFIGSTORE/etc/mongod.conf mkdir -p "$(dirname "$CONFIG")" @@ -51,6 +82,9 @@ $MASTER_BASE_SERVICE_NAME: - compose.config_hash=$config_hash " + + + ensure_db_docker_running diff --git a/mongo/metadata.yml b/mongo/metadata.yml index 19b777c..6e7d490 100644 --- a/mongo/metadata.yml +++ b/mongo/metadata.yml @@ -1,5 +1,6 @@ summary: "MongoDB server" maintainer: "Valentin Lab " +docker-image: docker.0k.io/mongo:4.0.24-myc data-resources: - /var/lib/mongodb config-resources: diff --git a/mongo/upgrade/build/4.0.24/Dockerfile b/mongo/upgrade/build/4.0.24/Dockerfile new file mode 100644 index 0000000..76ff7df --- /dev/null +++ b/mongo/upgrade/build/4.0.24/Dockerfile @@ -0,0 +1,4 @@ +FROM mongo:4.0.24 + +ENTRYPOINT [ "mongod", "--config", "/etc/mongod.conf" ] + diff --git a/mongo/upgrade/build/5.0.30/Dockerfile b/mongo/upgrade/build/5.0.30/Dockerfile new file mode 100644 index 0000000..308dbd6 --- /dev/null +++ b/mongo/upgrade/build/5.0.30/Dockerfile @@ -0,0 +1,4 @@ +FROM mongo:5.0.30 + +ENTRYPOINT [ "mongod", "--config", "/etc/mongod.conf" ] + diff --git a/mongo/upgrade/build/6.0.19/Dockerfile b/mongo/upgrade/build/6.0.19/Dockerfile new file mode 100644 index 0000000..ea6f359 --- /dev/null +++ b/mongo/upgrade/build/6.0.19/Dockerfile @@ -0,0 +1,4 @@ +FROM mongo:6.0.19 + +ENTRYPOINT [ "mongod", "--config", "/etc/mongod.conf" ] + diff --git a/mongo/upgrade/build/7.0.15/Dockerfile b/mongo/upgrade/build/7.0.15/Dockerfile new file mode 100644 index 0000000..1fe39cd --- /dev/null +++ b/mongo/upgrade/build/7.0.15/Dockerfile @@ -0,0 +1,4 @@ +FROM mongo:7.0.15 + +ENTRYPOINT [ "mongod", "--config", "/etc/mongod.conf" ] +