Skip to content

Commit

Permalink
✨ entrypoint.sh container script improvements
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Montleon <jmontleo@redhat.com>
  • Loading branch information
jmontleon committed Jul 2, 2024
1 parent bff90e0 commit cdbf900
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
34 changes: 27 additions & 7 deletions build/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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()'
9 changes: 6 additions & 3 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
Expand Down

0 comments on commit cdbf900

Please sign in to comment.