#!/bin/bash -xe

python3 setup.py build

if [ ! -f /attachments/inited ];
then
    echo "Giving Postgres time to start"
    sleep 10
    touch /attachments/inited
    PAGURE_CONFIG=/code/dev/openshift.cfg python3 createdb.py --initial /code/dev/openshift_alembic.ini
else
    alembic-3 --config /code/dev/openshift_alembic.ini upgrade head
fi

exec /usr/bin/python3 /code/runserver.py --host 0.0.0.0 --config /code/dev/openshift.cfg
