diff --git a/Dockerfile b/Dockerfile index b3cd26e88..519c8e235 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,3 +10,7 @@ RUN apt-get update && apt-get install -y gettext libgettextpo-dev tidy && apt-ge COPY requirements.txt /app/ RUN pip install -r requirements.txt --no-cache-dir +ADD . /app + + +ENTRYPOINT [ "/app/bookwyrm/setup.sh" ] diff --git a/bookwyrm/setup.sh b/bookwyrm/setup.sh new file mode 100755 index 000000000..6b2bd978b --- /dev/null +++ b/bookwyrm/setup.sh @@ -0,0 +1,33 @@ +#!/bin/bash +# Perform initial setup so that the users don't have to +# This should only be done in the web container; +# the celery and flower containers should wait for the canary to exist + +CANARY=/app/static/.dbinit_done + +info() { echo >&2 "$*" ; } +die() { echo >&2 "$*" ; exit 1 ; } + +if [ "$1" == "exit" ]; then + info "**** base container exiting" + exit 0 +fi + +if [ -z "$DB_INIT" ]; then + while [ ! -r "$CANARY" ]; do + info "**** Waiting for database and migrations to finish" + sleep 10 + done +elif [ ! -r "$CANARY" ]; then + info "**** Doing initial setup!" + python manage.py migrate || die "failed to migrate" + python manage.py migrate django_celery_beat || die "failed to migrate django" + python manage.py initdb || die "failed to initdb" + python manage.py collectstatic --no-input || die "failed to collect static" + python manage.py admin_code + + info "**** Done with initial setup!" + touch "$CANARY" +fi + +exec bash -c "$*"