-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
28 lines (23 loc) · 1.03 KB
/
entrypoint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/bin/bash
set -a # automatically export all variables
source .env
set +a
echo "Checking if database is initialized...(currently running entrypoint)"
sleep 10
# Wait for the database service to be ready
until mariadb -h "${DB_HOST}" -u "${DB_USER}" -p"${DB_PASSWD}" -e ";" ; do
>&2 echo "MariaDB is unavailable - sleeping"
sleep 1
done
DB_EXISTS=$(mariadb -h "${DB_HOST}" -u "${DB_USER}" -p"${DB_PASSWD}" -e "SHOW DATABASES LIKE '${DB_NAME}';" | grep "${DB_NAME}" > /dev/null; echo "$?")
DDL_SCRIPT_PATH="back-end/db/ntuaflix_ddl.sql"
# If the database does not exist, run the DDL script
if [[ "${DB_EXISTS}" -ne 0 ]]; then
echo "Database does not exist. Initializing database..."
mariadb -h "${DB_HOST}" -u "${DB_USER}" -p"${DB_PASSWD}" < "${DDL_SCRIPT_PATH}"
else
echo "Database exists. Skipping initialization."
fi
# This will wait for the database to be ready before starting the application
exec uvicorn back-end.api.main:app --host 0.0.0.0 --port 9876 --ssl-keyfile /certs/localhost.key --ssl-certfile /certs/localhost.crt
```