2017-04-19 16:48:21 +02:00
|
|
|
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
|
|
|
|
# run db migrations (retry on error)
|
2017-08-30 11:09:24 +02:00
|
|
|
while ! ./manage.py migrate 2>&1; do
|
2017-04-19 16:48:21 +02:00
|
|
|
sleep 5
|
|
|
|
done
|
|
|
|
|
|
|
|
# create superuser silently
|
|
|
|
if [[ -z ${SUPERUSER_NAME} || -z ${SUPERUSER_EMAIL} || -z ${SUPERUSER_PASSWORD} ]]; then
|
|
|
|
SUPERUSER_NAME='admin'
|
|
|
|
SUPERUSER_EMAIL='admin@example.com'
|
|
|
|
SUPERUSER_PASSWORD='admin'
|
|
|
|
echo "Using defaults: Username: ${SUPERUSER_NAME}, E-Mail: ${SUPERUSER_EMAIL}, Password: ${SUPERUSER_PASSWORD}"
|
|
|
|
fi
|
2017-04-21 13:43:44 +02:00
|
|
|
|
2017-08-30 11:09:24 +02:00
|
|
|
./manage.py shell --plain << END
|
2017-04-21 13:43:44 +02:00
|
|
|
from django.contrib.auth.models import User
|
|
|
|
if not User.objects.filter(username='${SUPERUSER_NAME}'):
|
|
|
|
User.objects.create_superuser('${SUPERUSER_NAME}', '${SUPERUSER_EMAIL}', '${SUPERUSER_PASSWORD}')
|
|
|
|
END
|
2017-04-19 16:48:21 +02:00
|
|
|
|
|
|
|
# copy static files
|
2017-08-30 11:09:24 +02:00
|
|
|
./manage.py collectstatic --no-input
|
2017-04-19 16:48:21 +02:00
|
|
|
|
2017-08-30 11:09:56 +02:00
|
|
|
echo "✅ Initialisation is done. Launching CMD:"
|
|
|
|
echo "exec ${@}"
|
|
|
|
|
|
|
|
# launch whatever is passed by docker via RUN
|
|
|
|
exec ${@}
|