From 8eb571bddf292d697b5a92672af7087be4550081 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sat, 10 Apr 2021 15:08:10 +1000 Subject: [PATCH] Update dockerfile --- InvenTree/InvenTree/settings.py | 2 +- docker/Dockerfile | 29 ++++++++++++---------------- docker/{start.sh => start_server.sh} | 4 ++-- docker/start_worker.sh | 24 +++++++++++++++++++++++ docker/supervisord.conf | 11 ++++++----- 5 files changed, 45 insertions(+), 25 deletions(-) rename docker/{start.sh => start_server.sh} (87%) create mode 100644 docker/start_worker.sh diff --git a/InvenTree/InvenTree/settings.py b/InvenTree/InvenTree/settings.py index 338a2dda9d..5e259a66e6 100644 --- a/InvenTree/InvenTree/settings.py +++ b/InvenTree/InvenTree/settings.py @@ -338,7 +338,7 @@ Q_CLUSTER = { 'queue_limit': 50, 'bulk': 10, 'orm': 'default', - 'sync': True, + 'sync': False, } # Markdownx configuration diff --git a/docker/Dockerfile b/docker/Dockerfile index a86fd09e45..893f028b9b 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -42,8 +42,6 @@ LABEL org.label-schema.schema-version="1.0" \ org.label-schema.vcs-branch=${BRANCH} \ org.label-schema.vcs-ref=${COMMIT} -RUN echo "Installing InvenTree '${INVENTREE_VERSION}' from ${INVENTREE_REPO}" - # Create user account RUN addgroup -S inventreegroup && adduser -S inventree -G inventreegroup WORKDIR ${INVENTREE_HOME} @@ -60,8 +58,8 @@ RUN apk add --no-cache python3 RUN apk add --no-cache postgresql-contrib postgresql-dev libpq RUN apk add --no-cache mariadb-connector-c mariadb-dev -# Clone source code -RUN git clone --branch ${INVENTREE_BRANCH} --depth 1 ${INVENTREE_REPO} ${INVENTREE_SRC_DIR} +# Create required directories +RUN mkdir ${INVENTREE_HOME}/media ${INVENTREE_HOME}/static ${INVENTREE_HOME}/backup # Setup Python virtual environment RUN python3 -m venv ${INVENTREE_VENV} @@ -72,25 +70,22 @@ RUN source ${INVENTREE_VENV}/bin/activate && pip install --no-cache-dir -U invok RUN source ${INVENTREE_VENV}/bin/activate && pip install --no-cache-dir -U psycopg2 mysqlclient pgcli mariadb RUN source ${INVENTREE_VENV}/bin/activate && pip install --no-cache-dir -U gunicorn +# Clone source code +RUN echo "Downloading InvenTree from ${INVENTREE_REPO}" +RUN git clone --branch ${INVENTREE_BRANCH} --depth 1 ${INVENTREE_REPO} ${INVENTREE_SRC_DIR} + # Install InvenTree packages RUN source ${INVENTREE_VENV}/bin/activate && pip install --no-cache-dir -U -r ${INVENTREE_SRC_DIR}/requirements.txt -# Install supervisor -RUN apk add --no-cache supervisor - -# Create required directories -RUN mkdir ${INVENTREE_HOME}/media ${INVENTREE_HOME}/static ${INVENTREE_HOME}/backup - -# Copy supervisor file -COPY supervisord.conf ${INVENTREE_HOME}/supervisord.conf - # Copy gunicorn config file COPY gunicorn.conf.py ${INVENTREE_HOME}/gunicorn.conf.py -# Copy startup script -COPY start.sh ${INVENTREE_HOME}/start.sh +# Copy startup scripts +COPY start_server.sh ${INVENTREE_HOME}/start_server.sh +COPY start_worker.sh ${INVENTREE_HOME}/start_worker.sh -RUN chmod 755 ${INVENTREE_HOME}/start.sh +RUN chmod 755 ${INVENTREE_HOME}/start_server.sh +RUN chmod 755 ${INVENTREE_HOME}/start_worker.sh # Let us begin -CMD ["bash", "./start.sh"] +CMD ["bash", "./start_server.sh"] diff --git a/docker/start.sh b/docker/start_server.sh similarity index 87% rename from docker/start.sh rename to docker/start_server.sh index f17150d0ca..fb84783829 100644 --- a/docker/start.sh +++ b/docker/start_server.sh @@ -29,5 +29,5 @@ 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 $INVENTREE_HOME/supervisord.conf \ No newline at end of file +# Now we can launch the server +gunicorn -c $INVENTREE_HOME/gunicorn.conf.py InvenTree.wsgi -b 0.0.0.0:8080 diff --git a/docker/start_worker.sh b/docker/start_worker.sh new file mode 100644 index 0000000000..9b7f3f408e --- /dev/null +++ b/docker/start_worker.sh @@ -0,0 +1,24 @@ +#!/bin/sh + +echo "Starting InvenTree worker..." + +# Check that the database engine is specified +if [ -z "$INVENTREE_DB_ENGINE" ]; then + echo "INVENTREE_DB_ENGINE not configured" + exit 1 +fi + +# Activate virtual environment +source ./env/bin/activate + +sleep 5 + +# Wait for the database to be ready +cd src/InvenTree + +python manage.py wait_for_db + +sleep 10 + +# Now we can launch the background worker process +python manage.py qcluster diff --git a/docker/supervisord.conf b/docker/supervisord.conf index 8dc8e77fc1..b99c48edcf 100644 --- a/docker/supervisord.conf +++ b/docker/supervisord.conf @@ -16,18 +16,20 @@ user=inventree nodaemon=true +[supervisorctl] +serverurl=unix:///var/run/supervisor.sock + [program:inventree-server] user=inventree directory=%(ENV_INVENTREE_SRC_DIR)s/InvenTree -command=%(ENV_INVENTREE_VENV)s/bin/gunicorn -c %(ENV_INVENTREE_HOME)s/gunicorn.conf.py InvenTree.wsgi -b 0.0.0.0:8080 +command=%(ENV_INVENTREE_VENV)s/bin/gunicorn -c %(ENV_INVENTREE_HOME)s/gunicorn.conf.py InvenTree.wsgi -b 127.0.0.1:8080 startsecs=10 autostart=true autorestart=true startretries=3 stdout_logfile=/dev/fd/1 stdout_logfile_maxbytes=0 -stderr_logfile=/dev/fd/2 -stderr_logfile_maxbytes=0 +redirect_stderr=true [program:inventree-cluster] user=inventree @@ -38,5 +40,4 @@ autostart=true autorestart=true stdout_logfile=/dev/fd/1 stdout_logfile_maxbytes=0 -stderr_logfile=/dev/fd/2 -stderr_logfile_maxbytes=0 \ No newline at end of file +redirect_stderr=true \ No newline at end of file