UPDATE
This commit is contained in:
@@ -1,10 +1,47 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
wait_for_db() {
|
||||
python - <<'PY'
|
||||
import os
|
||||
import socket
|
||||
import sys
|
||||
import time
|
||||
|
||||
host = os.environ.get("DB_HOST", "db")
|
||||
port = int(os.environ.get("DB_PORT", "3306"))
|
||||
deadline = time.time() + 90
|
||||
|
||||
while time.time() < deadline:
|
||||
try:
|
||||
with socket.create_connection((host, port), timeout=3):
|
||||
print(f"Database is reachable at {host}:{port}")
|
||||
sys.exit(0)
|
||||
except OSError as exc:
|
||||
print(f"Waiting for database {host}:{port}... {exc}")
|
||||
time.sleep(2)
|
||||
|
||||
print(f"Timed out waiting for database {host}:{port}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
PY
|
||||
}
|
||||
|
||||
if [ "${SKIP_MIGRATE}" != "1" ]; then
|
||||
wait_for_db
|
||||
echo "Running migrations..."
|
||||
python manage.py repair_location_tables
|
||||
python manage.py migrate --noinput
|
||||
echo "Migrations done."
|
||||
fi
|
||||
|
||||
if [ -n "${DEVELOP}" ] && [ "${SKIP_MIGRATE}" != "1" ]; then
|
||||
echo "DEVELOP is set. Seeding demo plant, location_data, weather_data, and farm_data..."
|
||||
python manage.py seed_plants
|
||||
python manage.py seed_location_data
|
||||
python manage.py seed_weather_data
|
||||
python manage.py seed_farm_data
|
||||
echo "Demo seeders done."
|
||||
fi
|
||||
|
||||
echo "Starting command: $*"
|
||||
exec "$@"
|
||||
|
||||
Reference in New Issue
Block a user