From 7dd63b36dacec70ce440eebe4ecb5613133b79a0 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Wed, 16 Jun 2021 22:36:05 +1000 Subject: [PATCH] Simplify dockerfile / docker-compose - Single data volume now also includes 'static' files - InvenTree source repo is now cloned into /home/inventree (to match the "dev" image) --- docker/Dockerfile | 31 +++++++++++-------- docker/docker-compose.yml | 17 +++++----- docker/start_prod_server.sh | 2 +- .../{start_worker.sh => start_prod_worker.sh} | 0 4 files changed, 27 insertions(+), 23 deletions(-) rename docker/{start_worker.sh => start_prod_worker.sh} (100%) diff --git a/docker/Dockerfile b/docker/Dockerfile index 9d85b8d4b6..e27bd5591a 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -7,6 +7,8 @@ ARG branch="master" ENV PYTHONUNBUFFERED 1 # InvenTree key settings + +# The INVENTREE_HOME directory is where the InvenTree source repository will be located ENV INVENTREE_HOME="/home/inventree" # GitHub settings @@ -17,10 +19,9 @@ ENV INVENTREE_LOG_LEVEL="INFO" ENV INVENTREE_DOCKER="true" # InvenTree paths -ENV INVENTREE_SRC_DIR="${INVENTREE_HOME}/src" -ENV INVENTREE_MNG_DIR="${INVENTREE_SRC_DIR}/InvenTree" +ENV INVENTREE_MNG_DIR="${INVENTREE_HOME}/InvenTree" ENV INVENTREE_DATA_DIR="${INVENTREE_HOME}/data" -ENV INVENTREE_STATIC_ROOT="${INVENTREE_HOME}/static" +ENV INVENTREE_STATIC_ROOT="${INVENTREE_DATA_DIR}/static" ENV INVENTREE_MEDIA_ROOT="${INVENTREE_DATA_DIR}/media" ENV INVENTREE_CONFIG_FILE="${INVENTREE_DATA_DIR}/config.yaml" @@ -44,8 +45,6 @@ RUN addgroup -S inventreegroup && adduser -S inventree -G inventreegroup WORKDIR ${INVENTREE_HOME} -RUN mkdir -p ${INVENTREE_STATIC_ROOT} - # Install required system packages RUN apk add --no-cache git make bash \ gcc libgcc g++ libstdc++ \ @@ -78,23 +77,22 @@ RUN pip install --no-cache-dir -U gunicorn FROM base as production # Clone source code RUN echo "Downloading InvenTree from ${INVENTREE_REPO}" -RUN git clone --branch ${INVENTREE_BRANCH} --depth 1 ${INVENTREE_REPO} ${INVENTREE_SRC_DIR} +RUN git clone --branch ${INVENTREE_BRANCH} --depth 1 ${INVENTREE_REPO} ${INVENTREE_HOME} # Install InvenTree packages -RUN pip install --no-cache-dir -U -r ${INVENTREE_SRC_DIR}/requirements.txt +RUN pip install --no-cache-dir -U -r ${INVENTREE_HOME}/requirements.txt # Copy gunicorn config file COPY gunicorn.conf.py ${INVENTREE_HOME}/gunicorn.conf.py # Copy startup scripts -COPY start_prod_server.sh ${INVENTREE_SRC_DIR}/start_prod_server.sh -COPY start_worker.sh ${INVENTREE_SRC_DIR}/start_worker.sh +COPY start_prod_server.sh ${INVENTREE_HOME}/start_prod_server.sh +COPY start_prod_worker.sh ${INVENTREE_HOME}/start_prod_worker.sh -RUN chmod 755 ${INVENTREE_SRC_DIR}/start_prod_server.sh -RUN chmod 755 ${INVENTREE_SRC_DIR}/start_worker.sh +RUN chmod 755 ${INVENTREE_HOME}/start_prod_server.sh +RUN chmod 755 ${INVENTREE_HOME}/start_prod_worker.sh -# exec commands should be executed from the "src" directory -WORKDIR ${INVENTREE_SRC_DIR} +WORKDIR ${INVENTREE_HOME} # Let us begin CMD ["bash", "./start_prod_server.sh"] @@ -106,6 +104,13 @@ FROM base as dev ENV INVENTREE_DEV_DIR = "${INVENTREE_HOME}/dev" +# Override default path settings +ENV INVENTREE_STATIC_ROOT="${INVENTREE_DEV_DIR}/static" +ENV INVENTREE_MEDIA_ROOT="${INVENTREE_DEV_DIR}/media" +ENV INVENTREE_CONFIG_FILE="${INVENTREE_DEV_DIR}/config.yaml" +ENV INVENTREE_SECRET_KEY_FILE="${INVENTREE_DEV_DIR}/secret_key.txt" + WORKDIR ${INVENTREE_HOME} +# Launch the development server CMD ["bash", "/home/inventree/docker/start_dev_server.sh"] diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 9e77dd1181..0ec135c7bb 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -30,6 +30,7 @@ services: - POSTGRES_USER=pguser - POSTGRES_PASSWORD=pgpassword volumes: + # Map 'data' volume such that postgres database is stored externally - data:/var/lib/postgresql/data/ restart: unless-stopped @@ -43,8 +44,8 @@ services: depends_on: - inventree-db volumes: + # Map 'data' volume - data:/home/inventree/data - - static:/home/inventree/static environment: # Default environment variables are configured to match the 'db' container # Note: If you change the database image, these will need to be adjusted @@ -67,7 +68,6 @@ services: - inventree-server volumes: - data:/home/inventree/data - - static:/home/inventree/static environment: # Default environment variables are configured to match the 'db' container # Note: If you change the database image, these will need to be adjusted @@ -81,7 +81,8 @@ services: restart: unless-stopped # nginx acts as a reverse proxy - # static files are served by nginx + # static files are served directly by nginx + # media files are served by nginx, although authentication is redirected to inventree-server # web requests are redirected to gunicorn # NOTE: You will need to provide a working nginx.conf file! inventree-proxy: @@ -93,11 +94,11 @@ services: # Change "1337" to the port that you want InvenTree web server to be available on - 1337:80 volumes: - # Provide nginx.conf file to the container + # Provide ./nginx.conf file to the container # Refer to the provided example file as a starting point - ./nginx.conf:/etc/nginx/conf.d/default.conf:ro - # Static data volume is mounted to /var/www/static - - static:/var/www/static:ro + # nginx proxy needs access to static and media files + - data:/var/www restart: unless-stopped volumes: @@ -110,6 +111,4 @@ volumes: o: bind # This directory specified where InvenTree data are stored "outside" the docker containers # Change this path to a local system path where you want InvenTree data stored - device: /path/to/data - # Static files, shared between containers - static: \ No newline at end of file + device: /path/to/data \ No newline at end of file diff --git a/docker/start_prod_server.sh b/docker/start_prod_server.sh index 2e5acb5c9d..9d86b331eb 100644 --- a/docker/start_prod_server.sh +++ b/docker/start_prod_server.sh @@ -16,7 +16,7 @@ if test -f "$INVENTREE_CONFIG_FILE"; then echo "$INVENTREE_CONFIG_FILE exists - skipping" else echo "Copying config file to $INVENTREE_CONFIG_FILE" - cp $INVENTREE_SRC_DIR/InvenTree/config_template.yaml $INVENTREE_CONFIG_FILE + cp $INVENTREE_HOME/InvenTree/config_template.yaml $INVENTREE_CONFIG_FILE fi echo "Starting InvenTree server..." diff --git a/docker/start_worker.sh b/docker/start_prod_worker.sh similarity index 100% rename from docker/start_worker.sh rename to docker/start_prod_worker.sh