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)
This commit is contained in:
Oliver Walters 2021-06-16 22:36:05 +10:00
parent acd7322ff0
commit 7dd63b36da
4 changed files with 27 additions and 23 deletions

View File

@ -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"]

View File

@ -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:
@ -111,5 +112,3 @@ volumes:
# 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:

View File

@ -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..."