You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
Valentin Lab a24bf37825 new: [mongo] add support for 6.0.* version 3 weeks ago
..
actions new: [mongo] add support for 6.0.* version 2 weeks ago
hooks new: [mongo] add support for 6.0.* version 2 weeks ago
lib new: [mongo] add support for 6.0.* version 2 weeks ago
resources/bin new: [mongo] added regular dump for backup 5 years ago
upgrade/build new: [mongo] add support for 6.0.* version 2 weeks ago
README.org new: [mongo] switch to pre-built images with upgrade directory 2 weeks ago
metadata.yml new: [mongo] switch to pre-built images with upgrade directory 2 weeks ago

README.org

Mongo Charm

Quick information

Upgrade

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.

Build new images

Get the last upstream images versions with:

actions/upstream-versions -l 10

Then use these function to help you manage the upgrade/build directory and create the *-myc images from upstream images:

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"

General Access

You can access mondo db, if running, through

SERVICENAME=mongo
compose exec "$SERVICENAME" /usr/bin/mongo --quiet --eval "some js code"

if not running, you might want to run it.

The following could be added to actions

list databases

SERVICENAME=mongo
compose exec -T mongo /usr/bin/mongo --quiet \
    --eval "JSON.stringify(db.adminCommand({listDatabases: 1}))" | \
    jq -r '.databases[] | .name'

Dump database

This one will use the probably already builded image from your project on your host to run a competing mongo with a host directory to store the dump.

PROJECTNAME=myc
SERVICENAME=mongo
docker run --rm --name mongo_client -ti \
     -v /tmp/mongo:/tmp/mongo --network "${PROJECTNAME}_default" \
     -u root \
     --entrypoint /bin/sh "${PROJECTNAME}_$SERVICENAME"

Then inside docker:

apk add mongodb-tools

Then for each databases:

DBNAME="xxx"
cd /tmp/mongo
mongodump -h mongo -d "$DBNAME" -o mdump/

Drop database

DBNAME=xxx
PROJECTNAME=myc
SERVICENAME=mongo
docker exec -i "${PROJECTNAME}_${SERVICE}_1" /usr/bin/mongo --quiet < \
    <(echo "
use $DBNAME;
db.dropDatabase();
")

Note: if some connection are active to the database, it might not be deleted, you should check by relisting the database.

Restore database

SOURCE_DIR=/tmp/gogocarto
docker run --rm -ti \
    -v "$SOURCE_DIR":/tmp/backups/gogocarto \
    -w /tmp/backups \
    --entrypoint mongorestore \
    --network myc_default \
    myc_mongo \
    --host rs01/mongo /tmp/backups/

There should not have any errors.

Please note that '/tmp/backups' in the last example should contain one directory per database.

Note also that you should drop database (see previous section) prior to restore them.