2020-06-02 14:20:23 +01:00
#! /usr/bin/env bash
2023-04-27 16:51:40 -04:00
# shellcheck source-path=..
2020-06-02 14:20:23 +01:00
set -euo pipefail
#### Detect Toolkit Project Root ####
# if realpath is not available, create a semi-equivalent function
command -v realpath >/dev/null 2>&1 || realpath() {
[[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"
}
SCRIPT_PATH="$(realpath "${BASH_SOURCE[0]}")"
SCRIPT_DIR="$(dirname "$SCRIPT_PATH")"
TOOLKIT_ROOT="$(realpath "$SCRIPT_DIR/..")"
if [[ ! -d "$TOOLKIT_ROOT/bin" ]] || [[ ! -d "$TOOLKIT_ROOT/config" ]]; then
echo "ERROR: could not find root of overleaf-toolkit project (inferred project root as '$TOOLKIT_ROOT')"
exit 1
fi
2023-04-27 16:51:40 -04:00
source "$TOOLKIT_ROOT/lib/shared-functions.sh"
2020-10-20 11:39:00 +01:00
function usage() {
echo "Usage: bin/up [FLAGS...]"
echo ""
2023-05-16 15:43:51 -04:00
echo "A wrapper around 'docker compose up'."
2020-10-20 11:39:00 +01:00
echo ""
2023-05-16 15:43:51 -04:00
echo "This program will pass any extra flags to docker compose,"
2020-10-20 11:39:00 +01:00
echo "for example: 'bin/up -d' will run in detached mode"
}
2020-06-02 14:20:23 +01:00
function check_config() {
if [[ ! -f "$TOOLKIT_ROOT/config/overleaf.rc" ]] \
|| [[ ! -f "$TOOLKIT_ROOT/config/variables.env" ]]; then
echo "Config files not found! exiting"
exit 1
fi
}
2023-04-27 16:51:40 -04:00
function initiate_mongo_replica_set() {
echo "Initiating Mongo replica set..."
2024-08-30 17:26:37 +01:00
env SKIP_WARNINGS=true "$TOOLKIT_ROOT/bin/docker-compose" up -d mongo
env SKIP_WARNINGS=true "$TOOLKIT_ROOT/bin/docker-compose" exec -T mongo sh -c '
2024-07-16 15:50:42 +02:00
while ! '$MONGOSH' --eval "db.version()" > /dev/null; do
2023-04-27 16:51:40 -04:00
echo "Waiting for Mongo..."
sleep 1
done
2024-07-16 15:50:42 +02:00
'$MONGOSH' --eval "db.isMaster().primary || rs.initiate({ _id: \"overleaf\", members: [ { _id: 0, host: \"mongo:27017\" } ] })" > /dev/null'
2023-04-27 16:51:40 -04:00
}
2024-05-27 15:32:53 +01:00
function pull_sandboxed_compiles() {
if [[ "${SIBLING_CONTAINERS_PULL:-true}" == "false" ]]; then
echo "Skipping pulling of TeX Live images"
return
fi
local images=$(read_variable "ALL_TEX_LIVE_DOCKER_IMAGES")
if [[ -z "$images" ]]; then
echo
echo "Please configure ALL_TEX_LIVE_DOCKER_IMAGES in $TOOLKIT_ROOT/config/variables.env"
echo
echo "You can read more about configuring Sandboxed Compiles in our documentation:"
echo " https://github.com/overleaf/overleaf/wiki/Server-Pro:-sandboxed-compiles#changing-the-texlive-image"
echo
exit 1
fi
echo "Pulling TeX Live images..."
for image in ${images//,/ }; do
echo " - $image download started (may take some time)"
docker pull $image
echo " - $image download finished"
done
}
2024-09-24 11:31:35 +02:00
function notify_about_not_using_detach_mode() {
local detached=false
for arg in "$@"; do
case "$arg" in
-d|--detach) detached=true;;
esac
done
if [[ "$detached" == false ]]; then
echo
echo '---'
echo
echo ' NOTICE: You are running "bin/up" without the detach mode ("-d" or "--detach" option). Behind the scenes, we will invoke "docker compose up", which will tail the container logs indefinitely until you issue a keyboard interrupt (CTRL+C).'
echo
echo '---'
echo
fi
}
2020-06-02 14:20:23 +01:00
function __main__() {
2020-10-20 11:39:00 +01:00
if [[ "${1:-null}" == "help" ]] || [[ "${1:-null}" == "--help" ]]; then
usage
exit
fi
2023-04-27 16:51:40 -04:00
2024-02-14 10:08:04 +01:00
read_image_version
2024-08-30 17:26:37 +01:00
SKIP_WARNINGS=true read_mongo_version
2020-06-02 14:20:23 +01:00
check_config
2023-04-27 16:51:40 -04:00
read_config
if [[ "$MONGO_ENABLED" == "true" && "$IMAGE_VERSION_MAJOR" -ge 4 ]]; then
initiate_mongo_replica_set
fi
2024-07-29 16:56:23 +01:00
if [[ $SERVER_PRO == "true" && "$SIBLING_CONTAINERS_ENABLED" == "true" ]]; then
2024-05-27 15:32:53 +01:00
pull_sandboxed_compiles
fi
2024-09-24 11:31:35 +02:00
notify_about_not_using_detach_mode "$@"
2024-08-30 17:26:37 +01:00
exec "$TOOLKIT_ROOT/bin/docker-compose" up "$@"
2020-06-02 14:20:23 +01:00
}
__main__ "$@"