From 2436b1f2c985a36abf72dde35bd365790ed184db Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Fri, 2 Apr 2021 00:40:47 +1100 Subject: [PATCH] Entrypoint script - start.sh --- InvenTree/config_template.yaml | 4 ++-- docker/Dockerfile | 18 ++++++++++++++--- docker/start.sh | 35 ++++++++++++++++++++++++++++++++++ tasks.py | 2 +- 4 files changed, 53 insertions(+), 6 deletions(-) create mode 100644 docker/start.sh diff --git a/InvenTree/config_template.yaml b/InvenTree/config_template.yaml index 7ce62e887d..fb30f2d339 100644 --- a/InvenTree/config_template.yaml +++ b/InvenTree/config_template.yaml @@ -28,7 +28,7 @@ database: # NAME: '/home/inventree/database.sqlite3' # --- Example Configuration - MySQL --- - #ENGINE: django.db.backends.mysql + #ENGINE: mysql #NAME: inventree #USER: inventree #PASSWORD: inventree_password @@ -36,7 +36,7 @@ database: #PORT: '3306' # --- Example Configuration - Postgresql --- - #ENGINE: django.db.backends.postgresql + #ENGINE: postgresql #NAME: inventree #USER: inventree #PASSWORD: inventree_password diff --git a/docker/Dockerfile b/docker/Dockerfile index c49c6e53f0..a9eaef612b 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -3,12 +3,13 @@ FROM python:alpine as production # GitHub source ARG INVENTREE_REPO="https://github.com/inventree/InvenTree.git" ARG INVENTREE_VERSION="master" +ARG INVENTREE_CONFIG_FILE="InvenTree/config_template.yaml" # InvenTree server port ARG INVENTREE_PORT="80" # Database configuration options -ARG INVENTREE_DB_ENGINE="sqlite" +ARG INVENTREE_DB_ENGINE="sqlite3" ARG INVENTREE_DB_NAME="inventree_db.sqlite3" ARG INVENTREE_DB_HOST="127.0.0.1" ARG INVENTREE_DB_PORT="" @@ -21,6 +22,8 @@ ENV PYTHONUNBUFFERED 1 ENV INVENTREE_HOME="/home/inventree" ENV INVENTREE_PORT="${INVENTREE_PORT}" +ENV INVENTREE_LOG_LEVEL="INFO" + # InvenTree paths ENV INVENTREE_SRC_DIR="${INVENTREE_HOME}/src" ENV INVENTREE_MNG_DIR="${INVENTREE_SRC_DIR}/InvenTree" @@ -42,7 +45,7 @@ LABEL org.label-schema.schema-version="1.0" \ org.label-schema.build-date=${DATE} \ org.label-schema.vendor="inventree" \ org.label-schema.name="inventree/inventree" \ - org.label-schema.url="https://hub.docker.com/r/inventree/inventree-docker" \ + org.label-schema.url="https://hub.docker.com/r/inventree/inventree" \ org.label-schema.version=${INVENTREE_VERSION} \ org.label-schema.vcs-url=${INVENTREE_REPO} \ org.label-schema.vcs-branch=${BRANCH} \ @@ -93,4 +96,13 @@ COPY docker/supervisor.conf /etc/supervisord.conf # Copy gunicorn config file COPY docker/gunicorn.conf.py ${INVENTREE_HOME}/gunicorn.conf.py -CMD ["/usr/bin/supervisord", "-c", "/etc/supervisord.conf"] +# Copy default InvenTree config file +COPY ${INVENTREE_CONFIG_FILE} ${INVENTREE_SRC_DIR}/InvenTree/config.yaml + +# Copy startup script +COPY docker/start.sh ${INVENTREE_HOME}/start.sh + +RUN chmod 755 ${INVENTREE_HOME}/start.sh + +# Let us begin +CMD "./start.sh" diff --git a/docker/start.sh b/docker/start.sh new file mode 100644 index 0000000000..3e1287527b --- /dev/null +++ b/docker/start.sh @@ -0,0 +1,35 @@ +#!/bin/sh + +# Check that the database engine is specified +if [ -z "$INVENTREE_DB_ENGINE" ]; then + echo "INVENTREE_DB_ENGINE not configured" + exit 1 +fi + +# Check that the base dir is set +if [ -z "$INVENTREE_HOME" ]; then + echo "INVENTREE_HOME not configured" + exit 1 +fi + +# Activate virtual environment +source $INVENTREE_VENV/bin/activate + +# Wait for the database to be ready +cd $INVENTREE_MNG_DIR +python manage.py wait_for_db + +sleep 10 + +echo "Running InvenTree database migrations and collecting static files..." + +# We assume at this stage that the database is up and running +# Ensure that the database schema are up to date +python manage.py check || exit 1 +python manage.py migrate --noinput || exit 1 +python manage.py migrate --run-syncdb || exit 1 +python manage.py collectstatic --noinput || exit 1 +python manage.py clearsessions || exit 1 + +# Now we can launch the server and background worker +/usr/bin/supervisord -c /etc/supervisord.conf diff --git a/tasks.py b/tasks.py index 83a99949f3..c6d7dd0173 100644 --- a/tasks.py +++ b/tasks.py @@ -143,7 +143,7 @@ def static(c): as per Django requirements. """ - manage(c, "collectstatic") + manage(c, "collectstatic --no-input") @task(pre=[install, migrate, static])