pretendo-docker/scripts/internal/firstrun-mongodb-container.sh
Matthew Lopez 05a67989cd
Rewrite scripts and improve user-friendliness
- Update all of the scripts to use Bash instead of sh so I can use arrays and other bashisms
- Create a complete Bash option parsing framework to replace function-lib.sh
- Rewrite all of the scripts to use this framework
- General script user-friendliness improvements, including loading existing environment variables by default instead of always requiring them to be specified
2024-05-10 17:22:25 -04:00

22 lines
728 B
Bash
Executable File

#!/usr/bin/env bash
# shellcheck source=./framework.sh
source "$(dirname "$(realpath "$0")")/framework.sh"
parse_arguments "$@"
mongodb_init_script=$(cat "$git_base_dir/scripts/run-in-container/mongodb-init.js")
docker compose up -d mongodb
# This won't work in /docker-entrypoint-initdb.d/ because MongoDB is in a
# special init state where it will refuse to resolve anything but localhost.
# This needs to be run after it initializes.
# https://github.com/docker-library/mongo/issues/339
while ! docker compose exec mongodb mongosh --eval "db.adminCommand('ping')" >/dev/null 2>&1; do
print_info "Waiting for mongodb to be ready..."
sleep 2
done
docker compose exec mongodb mongosh --eval "$mongodb_init_script"