Browse Source

new: [mongo] switch to pre-built images with upgrade directory

pull/48/head
Valentin Lab 2 months ago
parent
commit
6fa422a32b
  1. 57
      mongo/README.org
  2. 19
      mongo/build/Dockerfile
  3. 34
      mongo/hooks/init
  4. 1
      mongo/metadata.yml
  5. 4
      mongo/upgrade/build/4.0.24/Dockerfile
  6. 4
      mongo/upgrade/build/5.0.30/Dockerfile
  7. 4
      mongo/upgrade/build/6.0.19/Dockerfile
  8. 4
      mongo/upgrade/build/7.0.15/Dockerfile

57
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

19
mongo/build/Dockerfile

@ -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" ]

34
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

1
mongo/metadata.yml

@ -1,5 +1,6 @@
summary: "MongoDB server"
maintainer: "Valentin Lab <valentin.lab@kalysto.org>"
docker-image: docker.0k.io/mongo:4.0.24-myc
data-resources:
- /var/lib/mongodb
config-resources:

4
mongo/upgrade/build/4.0.24/Dockerfile

@ -0,0 +1,4 @@
FROM mongo:4.0.24
ENTRYPOINT [ "mongod", "--config", "/etc/mongod.conf" ]

4
mongo/upgrade/build/5.0.30/Dockerfile

@ -0,0 +1,4 @@
FROM mongo:5.0.30
ENTRYPOINT [ "mongod", "--config", "/etc/mongod.conf" ]

4
mongo/upgrade/build/6.0.19/Dockerfile

@ -0,0 +1,4 @@
FROM mongo:6.0.19
ENTRYPOINT [ "mongod", "--config", "/etc/mongod.conf" ]

4
mongo/upgrade/build/7.0.15/Dockerfile

@ -0,0 +1,4 @@
FROM mongo:7.0.15
ENTRYPOINT [ "mongod", "--config", "/etc/mongod.conf" ]
Loading…
Cancel
Save