37 lines
1.0 KiB
Bash
37 lines
1.0 KiB
Bash
#!/bin/bash
|
|
|
|
# Default to sqlite if not specified
|
|
DB_TYPE="${DB_TYPE:-sqlite}"
|
|
|
|
# Wait for PostgreSQL if needed
|
|
if [ "$DB_TYPE" = "postgresql" ]; then
|
|
MAX_WAIT=180
|
|
WAIT_INTERVAL=2
|
|
WAITED=0
|
|
echo "Database type is PostgreSQL. Waiting for database to be ready..."
|
|
until pg_isready -h "$DB_HOST" -p "$DB_PORT" -U "$DB_USER" > /dev/null 2>&1; do
|
|
if [ $WAITED -ge $MAX_WAIT ]; then
|
|
echo "Timeout: Could not connect to the database at $DB_HOST:$DB_PORT within $MAX_WAIT seconds."
|
|
exit 1
|
|
fi
|
|
echo "Waiting for database at $DB_HOST:$DB_PORT... ($WAITED/$MAX_WAIT seconds)"
|
|
sleep $WAIT_INTERVAL
|
|
WAITED=$((WAITED + WAIT_INTERVAL))
|
|
done
|
|
echo "Database is ready."
|
|
else
|
|
echo "Database type is SQLite. Skipping PostgreSQL readiness check."
|
|
fi
|
|
|
|
# Apply migrations
|
|
echo "Applying database migrations..."
|
|
flask db upgrade
|
|
|
|
# Start periodic image import in background
|
|
echo "import worker waiting for flag"
|
|
python image_import_worker.py &
|
|
|
|
# Start the Flask app
|
|
echo "Starting Flask app..."
|
|
exec flask run --host=0.0.0.0 --port=5000
|