Commit 3a7acbcb authored by Evili del Rio's avatar Evili del Rio

.- Correct syntax

.- Add create superuser if settings available
.- Add FIRST_RUN so that we do not repeat commands again
parent 022deaf3
Pipeline #1803 failed with stages
in 51 seconds
......@@ -4,6 +4,17 @@
#
set -e
#
# Set FIRST_RUN
#
NOT_FIRST_RUN="/.NOT_FIRST_RUN"
if [[ -f ${NOT_FIRST_RUN} ]]
then
export FIRST_RUN=
else
export FIRST_RUN=1
fi
if [[ $# -ge 1 ]]
then
cd $(dirname $1)
......@@ -11,7 +22,7 @@ else
cd /app
fi
if [[ -n "${REQUIRED_PACKAGES}" ]]
if [[ -n "${FIRST_RUN}" && -n "${REQUIRED_PACKAGES}" ]]
then
apk update
## we add gcc, g++, and libc-dev so that we can compile.
......@@ -19,16 +30,18 @@ then
fi
# Install requirements
REQUIREMENTS_FILES=${REQUIREMENTS_FILES:-requirements.txt}
for req in ${REQUIREMENTS_FILES}
do
REQUIREMENTS="${REQUIREMENTS} -r ${req}"
done
pip install ${REQUIREMENTS}
if [[ -n "${FIRST_RUN}" ]]
then
REQUIREMENTS_FILES=${REQUIREMENTS_FILES:-requirements.txt}
for req in ${REQUIREMENTS_FILES}
do
REQUIREMENTS="${REQUIREMENTS} -r ${req}"
done
pip install ${REQUIREMENTS}
fi
## Remove gcc and friends but not the rest
if [[ -s "${REQUIRED_PACKAGES}" ]]
if [[ -n "${FIRST_RUN}" -n "${REQUIRED_PACKAGES}" ]]
then
apk del gcc g++ libc-dev
fi
......@@ -48,7 +61,7 @@ export DJANGO_LOG_LEVEL=${DJANGO_LOG_LEVEL:-info}
# Select POSTGRES_HOST (if any and no other database definition available):
if [[ -z "${DJANGO_DATABASES}" && -z "${DATABASE_URL}" && -z "${POSTGRES_HOST}" ]]
then
p_host = $(/bin/printenv | /bin/egrep -e 'POSTGRES.*HOST' | /usr/bin/sort | /usr/bin/head -1)
p_host=$(/bin/printenv | /bin/egrep -e 'POSTGRES.*HOST' | /usr/bin/sort | /usr/bin/head -1)
if [[ -n ${p_host} ]]
then
export POSTGRES_HOST=${p_host}
......@@ -87,6 +100,40 @@ python3 manage.py migrate --no-input
python3 manage.py collectstatic --no-input
#
# Create Super User
#
if [[ -n "${FIRST_RUN}" && \
-n "${DJANGO_SUPERUSER_USERNAME}" && \
-n "${DJANGO_SUPERUSER_EMAIL}" && \
-n "${DJANGO_SUPERUSER_PASSWORD}" ]]
then
# Try Django>=3.0
python manage.py createsuperuser --no-input
if [[ $? -ne 0]]
then
# Try Django < 3.0
python manage.py shell <<EOF
import os
from django.contrib.auth.models import User
User.objects.create_superuser(
os.getenv('DJANGO_SUPERUSER_USERNAME'),
email=os.getenv('DJANGO_SUPERUSER_EMAIL'),
password=os.getenv('DJANGO_SUPERUSER_PASSWORD'),
)
EOF
fi
fi
#
# Mark NOT_FIRST_RUN for later.
#
touch ${NOT_FIRST_RUN}
#
# Run app
#
gunicorn --bind 0.0.0.0:5000 \
--capture-output \
--log-level=${DJANGO_LOG_LEVEL} \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment