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 #639 failed with stages
in 51 seconds
...@@ -4,6 +4,17 @@ ...@@ -4,6 +4,17 @@
# #
set -e 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 ]] if [[ $# -ge 1 ]]
then then
cd $(dirname $1) cd $(dirname $1)
...@@ -11,7 +22,7 @@ else ...@@ -11,7 +22,7 @@ else
cd /app cd /app
fi fi
if [[ -n "${REQUIRED_PACKAGES}" ]] if [[ -n "${FIRST_RUN}" && -n "${REQUIRED_PACKAGES}" ]]
then then
apk update apk update
## we add gcc, g++, and libc-dev so that we can compile. ## we add gcc, g++, and libc-dev so that we can compile.
...@@ -19,16 +30,18 @@ then ...@@ -19,16 +30,18 @@ then
fi fi
# Install requirements # Install requirements
REQUIREMENTS_FILES=${REQUIREMENTS_FILES:-requirements.txt} if [[ -n "${FIRST_RUN}" ]]
for req in ${REQUIREMENTS_FILES} then
do REQUIREMENTS_FILES=${REQUIREMENTS_FILES:-requirements.txt}
REQUIREMENTS="${REQUIREMENTS} -r ${req}" for req in ${REQUIREMENTS_FILES}
done do
REQUIREMENTS="${REQUIREMENTS} -r ${req}"
pip install ${REQUIREMENTS} done
pip install ${REQUIREMENTS}
fi
## Remove gcc and friends but not the rest ## Remove gcc and friends but not the rest
if [[ -s "${REQUIRED_PACKAGES}" ]] if [[ -n "${FIRST_RUN}" -n "${REQUIRED_PACKAGES}" ]]
then then
apk del gcc g++ libc-dev apk del gcc g++ libc-dev
fi fi
...@@ -48,7 +61,7 @@ export DJANGO_LOG_LEVEL=${DJANGO_LOG_LEVEL:-info} ...@@ -48,7 +61,7 @@ export DJANGO_LOG_LEVEL=${DJANGO_LOG_LEVEL:-info}
# Select POSTGRES_HOST (if any and no other database definition available): # Select POSTGRES_HOST (if any and no other database definition available):
if [[ -z "${DJANGO_DATABASES}" && -z "${DATABASE_URL}" && -z "${POSTGRES_HOST}" ]] if [[ -z "${DJANGO_DATABASES}" && -z "${DATABASE_URL}" && -z "${POSTGRES_HOST}" ]]
then 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} ]] if [[ -n ${p_host} ]]
then then
export POSTGRES_HOST=${p_host} export POSTGRES_HOST=${p_host}
...@@ -87,6 +100,40 @@ python3 manage.py migrate --no-input ...@@ -87,6 +100,40 @@ python3 manage.py migrate --no-input
python3 manage.py collectstatic --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 \ gunicorn --bind 0.0.0.0:5000 \
--capture-output \ --capture-output \
--log-level=${DJANGO_LOG_LEVEL} \ --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