Creates a token for admin by default

This commit is contained in:
Christian Mäder 2017-11-29 15:08:55 +01:00
parent d3dd6a2f69
commit 7b69fd8a1c
No known key found for this signature in database
GPG Key ID: 92FFD0A711F196BB
2 changed files with 22 additions and 11 deletions

View File

@ -1,30 +1,40 @@
#!/bin/bash
set -e
# run db migrations (retry on error)
# wait shortly and then run db migrations (retry on error)
while ! ./manage.py migrate 2>&1; do
sleep 5
echo "⏳ Waiting on DB..."
sleep 3
done
# create superuser silently
if [[ -z ${SUPERUSER_NAME} || -z ${SUPERUSER_EMAIL} || -z ${SUPERUSER_PASSWORD} ]]; then
if [[ -z ${SUPERUSER_NAME} ]]; 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
if [[ -z ${SUPERUSER_EMAIL} ]]; then
SUPERUSER_EMAIL='admin@example.com'
fi
if [[ -z ${SUPERUSER_PASSWORD} ]]; then
SUPERUSER_PASSWORD='admin'
fi
if [[ -z ${SUPERUSER_API_TOKEN} ]]; then
SUPERUSER_API_TOKEN='0123456789abcdef0123456789abcdef01234567'
fi
echo "💡 Username: ${SUPERUSER_NAME}, E-Mail: ${SUPERUSER_EMAIL}, Password: ${SUPERUSER_PASSWORD}, Token: ${SUPERUSER_API_TOKEN}"
./manage.py shell --plain << END
from django.contrib.auth.models import User
from users.models import Token
if not User.objects.filter(username='${SUPERUSER_NAME}'):
User.objects.create_superuser('${SUPERUSER_NAME}', '${SUPERUSER_EMAIL}', '${SUPERUSER_PASSWORD}')
u=User.objects.create_superuser('${SUPERUSER_NAME}', '${SUPERUSER_EMAIL}', '${SUPERUSER_PASSWORD}')
Token.objects.create(user=u, key='${SUPERUSER_API_TOKEN}')
END
# copy static files
./manage.py collectstatic --no-input
echo "✅ Initialisation is done. Launching CMD:"
echo "exec ${@}"
echo "✅ Initialisation is done."
# launch whatever is passed by docker via RUN
exec ${@}

View File

@ -1,7 +1,8 @@
SUPERUSER_NAME=admin
SUPERUSER_EMAIL=admin@example.com
SUPERUSER_PASSWORD=admin
ALLOWED_HOSTS=localhost 0.0.0.0 127.0.0.1 [::1] netboxdocker.docker nginx.netboxdocker.docker
SUPERUSER_API_TOKEN=0123456789abcdef0123456789abcdef01234567
ALLOWED_HOSTS=localhost 0.0.0.0 127.0.0.1 [::1] netbox nginx netboxdocker.docker nginx.netboxdocker.docker
DB_NAME=netbox
DB_USER=netbox
DB_PASSWORD=J5brHrAXFLQSif0K