1
0
Fork 0
mirror of https://github.com/overleaf/toolkit.git synced 2025-04-19 15:28:06 +02:00

Merge pull request #261 from overleaf/msm-prepare-mongo-6

Add support for Mongo 6.0
This commit is contained in:
Miguel Serrano 2024-07-16 16:57:05 +02:00 committed by GitHub
commit 9a7a0e8f21
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 76 additions and 9 deletions

View file

@ -1,5 +1,9 @@
# Changelog
## 2024-07-16
### Added
- Added support for Mongo 6.0.
## 2024-07-12
### Added
- Updated default [`version`](https://github.com/overleaf/toolkit/blob/master/lib/config-seed/version) to `5.0.7`.

View file

@ -123,7 +123,8 @@ function set_mongo_vars() {
export MONGO_ARGS
export MONGO_DATA_PATH
export MONGO_IMAGE
export MONGO_DOCKER_IMAGE
export MONGOSH
}
# Set environment variables for docker-compose.sibling-containers.yml
@ -208,6 +209,7 @@ function docker_compose() {
}
read_image_version
read_mongo_version
read_config
check_retracted_version
check_sharelatex_env_vars

View file

@ -15,8 +15,11 @@ if [[ ! -d "$TOOLKIT_ROOT/bin" ]] || [[ ! -d "$TOOLKIT_ROOT/config" ]]; then
exit 1
fi
source "$TOOLKIT_ROOT/lib/shared-functions.sh"
function __main__() {
exec "$TOOLKIT_ROOT/bin/docker-compose" exec mongo mongo sharelatex
read_mongo_version
exec env SKIP_WARNINGS=true "$TOOLKIT_ROOT/bin/docker-compose" exec mongo $MONGOSH sharelatex
}
__main__ "$@"

11
bin/up
View file

@ -37,13 +37,13 @@ function check_config() {
function initiate_mongo_replica_set() {
echo "Initiating Mongo replica set..."
"$TOOLKIT_ROOT/bin/docker-compose" up -d mongo
"$TOOLKIT_ROOT/bin/docker-compose" exec -T mongo sh -c '
while ! mongo --eval "db.version()" > /dev/null; do
SKIP_WARNINGS=true "$TOOLKIT_ROOT/bin/docker-compose" up -d mongo
SKIP_WARNINGS=true "$TOOLKIT_ROOT/bin/docker-compose" exec -T mongo sh -c '
while ! '$MONGOSH' --eval "db.version()" > /dev/null; do
echo "Waiting for Mongo..."
sleep 1
done
mongo --eval "rs.initiate({ _id: \"overleaf\", members: [ { _id: 0, host: \"mongo:27017\" } ] })" > /dev/null'
'$MONGOSH' --eval "db.isMaster().primary || rs.initiate({ _id: \"overleaf\", members: [ { _id: 0, host: \"mongo:27017\" } ] })" > /dev/null'
}
function pull_sandboxed_compiles() {
@ -76,6 +76,7 @@ function __main__() {
fi
read_image_version
read_mongo_version
check_config
read_config
@ -87,7 +88,7 @@ function __main__() {
pull_sandboxed_compiles
fi
exec "$TOOLKIT_ROOT/bin/docker-compose" up "$@"
exec env SKIP_WARNINGS=true "$TOOLKIT_ROOT/bin/docker-compose" up "$@"
}
__main__ "$@"

View file

@ -4,7 +4,7 @@ services:
mongo:
restart: always
image: "${MONGO_IMAGE}"
image: "${MONGO_DOCKER_IMAGE}"
command: "${MONGO_ARGS}"
container_name: mongo
volumes:
@ -12,7 +12,7 @@ services:
expose:
- 27017
healthcheck:
test: echo 'db.stats().ok' | mongo localhost:27017/test --quiet
test: echo 'db.stats().ok' | ${MONGOSH} localhost:27017/test --quiet
interval: 10s
timeout: 10s
retries: 5

View file

@ -19,6 +19,57 @@ function read_image_version() {
IMAGE_VERSION_PATCH=${BASH_REMATCH[3]}
}
function read_mongo_version() {
local mongo_image=$(read_configuration "MONGO_IMAGE")
local mongo_version=$(read_configuration "MONGO_VERSION")
if [ -z "${mongo_version}" ]; then
if [[ "$mongo_image" =~ ^mongo:([0-9]+)\.(.*)$ ]]; then
# when running a chain of commands (example: bin/up -> bin/docker-compose) we're passing
# SKIP_WARNINGS=true to prevent the warning message to be printed several times
if [[ -z ${SKIP_WARNINGS:-} ]]; then
echo "------------------- WARNING ----------------------"
echo " Deprecation warning: the mongo image is now split between MONGO_IMAGE"
echo " and MONGO_VERSION configurations. Please update your config/overleaf.rc as"
echo " your current configuration may stop working in future versions of the toolkit."
echo " Example: MONGO_IMAGE=mongo"
echo " MONGO_VERSION=6.0"
echo "------------------- WARNING ----------------------"
fi
MONGO_VERSION_MAJOR=${BASH_REMATCH[1]}
MONGO_DOCKER_IMAGE="$mongo_image"
else
echo "--------------------- ERROR -----------------------"
echo " The mongo image is now split between MONGO_IMAGE and MONGO_VERSION configurations."
echo " Please update your config/overleaf.rc."
echo ""
echo " MONGO_VERSION must start with the actual major version of mongo, followed by a dot."
echo " Example: MONGO_IMAGE=my.dockerhub.com/custom-mongo"
echo " MONGO_VERSION=6.0-custom"
echo "--------------------- ERROR -----------------------"
exit 1
fi
else
if [[ ! "$mongo_version" =~ ^([0-9]+)\.(.+)$ ]]; then
echo "--------------------- ERROR -----------------------"
echo " Invalid MONGO_VERSION: $mongo_version"
echo ""
echo " MONGO_VERSION must start with the actual major version of mongo, followed by a dot."
echo " Example: MONGO_IMAGE=my.dockerhub.com/custom-mongo"
echo " MONGO_VERSION=6.0-custom"
echo "--------------------- ERROR -----------------------"
exit 1
fi
MONGO_VERSION_MAJOR=${BASH_REMATCH[1]}
MONGO_DOCKER_IMAGE="$mongo_image:$mongo_version"
fi
if [[ "$MONGO_VERSION_MAJOR" -lt 6 ]]; then
MONGOSH="mongo"
else
MONGOSH="mongosh"
fi
}
function check_retracted_version() {
if [[ "${OVERLEAF_SKIP_RETRACTION_CHECK:-null}" == "$IMAGE_VERSION" ]]; then
return
@ -131,3 +182,9 @@ function read_variable() {
grep -E "^$name=" "$TOOLKIT_ROOT/config/variables.env" \
| sed -r "s/^$name=([\"']*)(.+)\1*\$/\2/"
}
function read_configuration() {
local name=$1
grep -E "^$name=" "$TOOLKIT_ROOT/config/overleaf.rc" \
| sed -r "s/^$name=([\"']*)(.+)\1*\$/\2/"
}