#!/bin/sh

if [ "$DATABASE" = "postgres" ]
then
    echo "Waiting for postgres..."

    while ! nc -z $SQL_HOST $SQL_PORT; do
      sleep 0.1
    done

    echo "PostgreSQL started"
fi

npm install
gulp deploy
python manage.py createcachetable
python manage.py collectstatic --noinput --verbosity=0
python manage.py migrate
python manage.py createsuperuser --email=dev@hypha.test --no-input
python manage.py wagtailsiteupdate hypha.test apply.hypha.test 80
python manage.py runserver 0.0.0.0:8080
# gunicorn opentech.wsgi:application --reload --daemon --workers 3 --bind 0.0.0.0::8080 --env DJANGO_SETTINGS_MODULE=opentech.settings.dev

exec "$@"
