From d86d6dabd8cac21a5d5c94e40c4aea794fb0e449 Mon Sep 17 00:00:00 2001 From: Jason Montleon Date: Mon, 1 Jul 2024 23:22:11 -0400 Subject: [PATCH] :sparkles entrypoint.sh container script improvements Signed-off-by: Jason Montleon --- build/entrypoint.sh | 34 +++++++++++++++++++++++++++------- compose.yaml | 9 ++++++--- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/build/entrypoint.sh b/build/entrypoint.sh index 818a7321..61c97d44 100755 --- a/build/entrypoint.sh +++ b/build/entrypoint.sh @@ -9,18 +9,38 @@ if [ -f /podman_compose/kai/config.toml ]; then sed -i "s/^password =.*/password =\"$POSTGRES_PASSWORD\"/g" /kai/kai/config.toml fi +until PGPASSWORD="$POSTGRES_PASSWORD" pg_isready -q -h kai_db -U $POSTGRES_USER -d $POSTGRES_DB ; do + sleep 1 +done + TABLE=applications -SQL_EXISTS=$(printf '\dt "%s"' "$TABLE") -if [[ $(PGPASSWORD="$POSTGRES_PASSWORD" psql -h "kai_db" -U $POSTGRES_USER -d $POSTGRES_DB -c "$SQL_EXISTS") ]] -then - echo "load-data has run already" +SQL_EXISTS=$(printf "\dt %s" "$TABLE") +STDERR="Did not find any relation" +if PGPASSWORD="$POSTGRES_PASSWORD" psql -h kai_db -U $POSTGRES_USER -d $POSTGRES_DB -c "$SQL_EXISTS" 2>&1 | grep -q -v "$STDERR"; then + echo "################################################" + echo "load-data has run already run, starting server.#" + echo "################################################" else - echo "load-data has not run yet, starting ..." - echo "Fetching examples" + echo "################################################" + echo "load-data has never been run. #" + echo "Please wait, this will take a few minutes. #" + echo "################################################" + sleep 5 + + if [ "$USE_HUB_IMPORTER" = "True" ]; then + cd /kai + python ./kai/hub_importer.py --loglevel ${LOGLEVEL} --config_filepath ./kai/config.toml ${IMPORTER_ARGS} ${HUB_URL} + else cd /kai/samples ./fetch_apps.py cd /kai - python ./kai/service/incident_store/psql.py --config_filepath ./kai/config.toml --drop_tables False + python ./kai/service/incident_store/psql.py --config_filepath ./kai/config.toml --drop_tables False + fi + + echo "################################################" + echo "load-data has completed, starting server. #" + echo "################################################" + sleep 5 fi PYTHONPATH="/kai/kai" exec gunicorn --timeout 3600 -w $NUM_WORKERS --bind 0.0.0.0:8080 --worker-class aiohttp.GunicornWebWorker 'kai.server:app()' diff --git a/compose.yaml b/compose.yaml index b66fa134..2e11975e 100644 --- a/compose.yaml +++ b/compose.yaml @@ -1,9 +1,9 @@ version: "3.4" x-common-variables: &common-variables - POSTGRES_USER: foo - POSTGRES_PASSWORD: bar - POSTGRES_DB: baz + POSTGRES_USER: kai + POSTGRES_PASSWORD: dog8code + POSTGRES_DB: kai services: kai: @@ -12,6 +12,9 @@ services: LOGLEVEL: info DEMO_MODE: False NUM_WORKERS: 8 + USE_HUB_IMPORTER: False + HUB_URL: "https://localhost" + IMPORTER_ARGS: "" # Do not edit the variables below otherwise # you risk committing keys to a public repo # These lines will pass in the environment