idhub: make it more dev env friendly

now idhub docker just has the dev env, you need to map the idhub repo
as a volume (there is a friendly error handling for that)
This commit is contained in:
pedro 2023-12-01 10:10:11 +01:00
parent 1585ece598
commit df05735979
3 changed files with 40 additions and 18 deletions

View File

@ -24,3 +24,5 @@ services:
- EMAIL_BACKEND=${IDHUB_EMAIL_BACKEND} - EMAIL_BACKEND=${IDHUB_EMAIL_BACKEND}
ports: ports:
- 7000:7000 - 7000:7000
volumes:
- ./IdHub:/opt/idhub

View File

@ -6,12 +6,12 @@ RUN apt update && apt-get install -y \
python3-dev \ python3-dev \
python-is-python3 python-is-python3
WORKDIR /home WORKDIR /opt/idhub
RUN python3 -m pip install --upgrade pip RUN python3 -m pip install --upgrade pip
COPY IdHub . COPY IdHub/requirements.txt /
RUN pip install -r requirements.txt RUN pip install -r /requirements.txt
COPY docker/idhub.entrypoint.sh . COPY docker/idhub.entrypoint.sh /
ENTRYPOINT sh ./idhub.entrypoint.sh ENTRYPOINT sh /idhub.entrypoint.sh

View File

@ -5,25 +5,45 @@ set -u
set -x set -x
main() { main() {
# go to the same path as the script idhub_dir='/opt/idhub'
cd "$(dirname ${0})" cd "${idhub_dir}"
if [ ! -f "./manage.py" ]; then
cat <<END
ERROR: you need to map your idhub git repo volume to docker, suggested volume mapping is:
volumes:
- ./IdHub:/opt/idhub
END
exit 1
fi
# detect if existing deployment
if [ -f "${idhub_dir}/db.sqlite3" ]; then
echo "INFO: detected EXISTING deployment"
./manage.py makemigrations
./manage.py migrate
else
# move the migrate thing in docker entrypoint # move the migrate thing in docker entrypoint
# inspired by https://medium.com/analytics-vidhya/django-with-docker-and-docker-compose-python-part-2-8415976470cc # inspired by https://medium.com/analytics-vidhya/django-with-docker-and-docker-compose-python-part-2-8415976470cc
echo "INFO detected NEW deployment"
./manage.py migrate ./manage.py migrate
if [ "${DEPLOYMENT}" = 'DEVELOPMENT' ]; then
printf "This is DEVELOPMENT DEPLOYMENT: including demo hardcoded data\n creating initial Datas\n" >&2
./manage.py initial_datas
else
printf "creating superuser \n user: ${DJANGO_SUPERUSER_USERNAME}\n password: ${DJANGO_SUPERUSER_PASSWORD}\n email: ${DJANGO_SUPERUSER_EMAIL}\n" >&2
## thanks https://stackoverflow.com/questions/6244382/how-to-automate-createsuperuser-on-django/59467533#59467533
./manage.py createsuperuser --no-input
fi
fi
# enable dev flags when DEVELOPMENT deployment # enable dev flags when DEVELOPMENT deployment
if [ "${DEPLOYMENT}" = 'DEVELOPMENT' ]; then if [ "${DEPLOYMENT}" = 'DEVELOPMENT' ]; then
export DEBUG=True export DEBUG=True
export DEVELOPMENT=True export DEVELOPMENT=True
printf "This is DEVELOPMENT DEPLOYMENT: including demo hardcoded data\n creating initial Datas\n" >&2
./manage.py initial_datas
else
printf "creating superuser \n user: ${DJANGO_SUPERUSER_USERNAME}\n password: ${DJANGO_SUPERUSER_PASSWORD}\n email: ${DJANGO_SUPERUSER_EMAIL}\n" >&2
## thanks https://stackoverflow.com/questions/6244382/how-to-automate-createsuperuser-on-django/59467533#59467533
./manage.py createsuperuser --no-input
fi fi
#./manage.py collectstatic #./manage.py collectstatic