From b9df60c45254acf9953ffbbb0ada7fd5f4b0a6bb Mon Sep 17 00:00:00 2001 From: BogPlaymate Date: Wed, 10 Jul 2024 07:00:15 +0900 Subject: [PATCH] Three changes: 1) Check whether a directory exists before attempting to create it (avoids warning message) 2) Check whether podman volume exists before attempting to create it (avoids warning message) 3) Check which Linux distribution is running, so that Redis can be launched. I have only tested this on Linux Mint (which is Ubunto based) so please check the uname -rv command on your machine. It should return a string which includes "Alpine". The mechanism for checking the Linux version is not perfect, but we probably want to keep the run_tests as short as possible. Any feedback welcomed. Have a great day! --- run_tests.sh | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/run_tests.sh b/run_tests.sh index be9904b..c2ecefc 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -9,17 +9,36 @@ run_tests() { } stop() { - $CONTAINER_BIN container stop classquiz_db - $CONTAINER_BIN container stop test_redis - $CONTAINER_BIN container stop test_meili + $CONTAINER_BIN container stop classquiz_db + $CONTAINER_BIN container stop test_redis + $CONTAINER_BIN container stop test_meili } init() { - mkdir /tmp/storage - $CONTAINER_BIN run --rm -d -p 6379:6379 --name test_redis redis:alpine - $CONTAINER_BIN run -it --rm -d -p 7700:7700 --name test_meili getmeili/meilisearch:v0.28.0 - $CONTAINER_BIN volume create classquiz_db_data - $CONTAINER_BIN run --name classquiz_db -p 5432:5432 --rm -d -e POSTGRES_PASSWORD=mysecretpassword -v classquiz_db_data:/var/lib/postgresql/data -e POSTGRES_DB=classquiz postgres + if [ ! -d /tmp/storage ]; then + mkdir /tmp/storage + fi + + $CONTAINER_BIN volume exists classquiz_db_data + if [ ! $? ]; then + $CONTAINER_BIN volume create classquiz_db_data + fi + + #Check Linux distribution, which is necessary for using Redis + SYSINFO=$(uname -rv) + CONTAINER_REDIS="" + if [[ ${SYSINFO} == *"Ubuntu"* ]]; then + CONTAINER_REDIS=redis:buster + elif [[ ${SYSINFO} == *"Alpine"* ]]; then + CONTAINER_REDIS=redis:alpine + else + echo "Warning. Defaulting to Alpine Redis. If Redis error follows, please add your Linux distribution. Then make this script addition your first Class Quiz contribution! We will appreciate it!" + CONTAINER_REDIS=redis:alpine + fi + + $CONTAINER_BIN run --rm -d -p 6379:6379 --name test_redis $CONTAINER_REDIS + $CONTAINER_BIN run -it --rm -d -p 7700:7700 --name test_meili docker.io/getmeili/meilisearch:v0.28.0 + $CONTAINER_BIN run --name classquiz_db -p 5432:5432 --rm -d -e POSTGRES_PASSWORD=mysecretpassword -v classquiz_db_data:/var/lib/postgresql/data -e POSTGRES_DB=classquiz docker.io/postgres sleep 1 pipenv run alembic upgrade head }