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

Add support for Mongo 6

This commit is contained in:
mserranom 2024-07-16 15:50:42 +02:00
parent 49ca0914f3
commit 73661ed2b1
6 changed files with 73 additions and 9 deletions

View file

@ -1,5 +1,9 @@
# Changelog # Changelog
## 2024-07-16
### Added
- Added support for Mongo 6.0.
## 2024-07-12 ## 2024-07-12
### Added ### Added
- Updated default [`version`](https://github.com/overleaf/toolkit/blob/master/lib/config-seed/version) to `5.0.7`. - 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_ARGS
export MONGO_DATA_PATH export MONGO_DATA_PATH
export MONGO_IMAGE export MONGO_DOCKER_IMAGE
export MONGOSH
} }
# Set environment variables for docker-compose.sibling-containers.yml # Set environment variables for docker-compose.sibling-containers.yml
@ -208,6 +209,7 @@ function docker_compose() {
} }
read_image_version read_image_version
read_mongo_version
read_config read_config
check_retracted_version check_retracted_version
check_sharelatex_env_vars check_sharelatex_env_vars

View file

@ -15,8 +15,11 @@ if [[ ! -d "$TOOLKIT_ROOT/bin" ]] || [[ ! -d "$TOOLKIT_ROOT/config" ]]; then
exit 1 exit 1
fi fi
source "$TOOLKIT_ROOT/lib/shared-functions.sh"
function __main__() { 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__ "$@" __main__ "$@"

11
bin/up
View file

@ -37,13 +37,13 @@ function check_config() {
function initiate_mongo_replica_set() { function initiate_mongo_replica_set() {
echo "Initiating Mongo replica set..." echo "Initiating Mongo replica set..."
"$TOOLKIT_ROOT/bin/docker-compose" up -d mongo SKIP_WARNINGS=true "$TOOLKIT_ROOT/bin/docker-compose" up -d mongo
"$TOOLKIT_ROOT/bin/docker-compose" exec -T mongo sh -c ' SKIP_WARNINGS=true "$TOOLKIT_ROOT/bin/docker-compose" exec -T mongo sh -c '
while ! mongo --eval "db.version()" > /dev/null; do while ! '$MONGOSH' --eval "db.version()" > /dev/null; do
echo "Waiting for Mongo..." echo "Waiting for Mongo..."
sleep 1 sleep 1
done 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() { function pull_sandboxed_compiles() {
@ -76,6 +76,7 @@ function __main__() {
fi fi
read_image_version read_image_version
read_mongo_version
check_config check_config
read_config read_config
@ -87,7 +88,7 @@ function __main__() {
pull_sandboxed_compiles pull_sandboxed_compiles
fi fi
exec "$TOOLKIT_ROOT/bin/docker-compose" up "$@" exec env SKIP_WARNINGS=true "$TOOLKIT_ROOT/bin/docker-compose" up "$@"
} }
__main__ "$@" __main__ "$@"

View file

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

View file

@ -19,6 +19,54 @@ function read_image_version() {
IMAGE_VERSION_PATCH=${BASH_REMATCH[3]} 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"
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/mongo"
echo " MONGO_VERSION=6.0-custom"
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.hotfix-1"
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() { function check_retracted_version() {
if [[ "${OVERLEAF_SKIP_RETRACTION_CHECK:-null}" == "$IMAGE_VERSION" ]]; then if [[ "${OVERLEAF_SKIP_RETRACTION_CHECK:-null}" == "$IMAGE_VERSION" ]]; then
return return
@ -131,3 +179,9 @@ function read_variable() {
grep -E "^$name=" "$TOOLKIT_ROOT/config/variables.env" \ grep -E "^$name=" "$TOOLKIT_ROOT/config/variables.env" \
| sed -r "s/^$name=([\"']*)(.+)\1*\$/\2/" | 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/"
}