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 ENV PYTHONUNBUFFERED 1
# InvenTree key settings # InvenTree key settings
# The INVENTREE_HOME directory is where the InvenTree source repository will be located
ENV INVENTREE_HOME="/home/inventree" ENV INVENTREE_HOME="/home/inventree"
# GitHub settings # GitHub settings
@ -17,10 +19,9 @@ ENV INVENTREE_LOG_LEVEL="INFO"
ENV INVENTREE_DOCKER="true" ENV INVENTREE_DOCKER="true"
# InvenTree paths # InvenTree paths
ENV INVENTREE_SRC_DIR="${INVENTREE_HOME}/src" ENV INVENTREE_MNG_DIR="${INVENTREE_HOME}/InvenTree"
ENV INVENTREE_MNG_DIR="${INVENTREE_SRC_DIR}/InvenTree"
ENV INVENTREE_DATA_DIR="${INVENTREE_HOME}/data" 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_MEDIA_ROOT="${INVENTREE_DATA_DIR}/media"
ENV INVENTREE_CONFIG_FILE="${INVENTREE_DATA_DIR}/config.yaml" 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} WORKDIR ${INVENTREE_HOME}
RUN mkdir -p ${INVENTREE_STATIC_ROOT}
# Install required system packages # Install required system packages
RUN apk add --no-cache git make bash \ RUN apk add --no-cache git make bash \
gcc libgcc g++ libstdc++ \ gcc libgcc g++ libstdc++ \
@ -78,23 +77,22 @@ RUN pip install --no-cache-dir -U gunicorn
FROM base as production FROM base as production
# Clone source code # Clone source code
RUN echo "Downloading InvenTree from ${INVENTREE_REPO}" 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 # 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 config file
COPY gunicorn.conf.py ${INVENTREE_HOME}/gunicorn.conf.py COPY gunicorn.conf.py ${INVENTREE_HOME}/gunicorn.conf.py
# Copy startup scripts # Copy startup scripts
COPY start_prod_server.sh ${INVENTREE_SRC_DIR}/start_prod_server.sh COPY start_prod_server.sh ${INVENTREE_HOME}/start_prod_server.sh
COPY start_worker.sh ${INVENTREE_SRC_DIR}/start_worker.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_HOME}/start_prod_server.sh
RUN chmod 755 ${INVENTREE_SRC_DIR}/start_worker.sh RUN chmod 755 ${INVENTREE_HOME}/start_prod_worker.sh
# exec commands should be executed from the "src" directory WORKDIR ${INVENTREE_HOME}
WORKDIR ${INVENTREE_SRC_DIR}
# Let us begin # Let us begin
CMD ["bash", "./start_prod_server.sh"] CMD ["bash", "./start_prod_server.sh"]
@ -106,6 +104,13 @@ FROM base as dev
ENV INVENTREE_DEV_DIR = "${INVENTREE_HOME}/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} WORKDIR ${INVENTREE_HOME}
# Launch the development server
CMD ["bash", "/home/inventree/docker/start_dev_server.sh"] CMD ["bash", "/home/inventree/docker/start_dev_server.sh"]

View File

@ -30,6 +30,7 @@ services:
- POSTGRES_USER=pguser - POSTGRES_USER=pguser
- POSTGRES_PASSWORD=pgpassword - POSTGRES_PASSWORD=pgpassword
volumes: volumes:
# Map 'data' volume such that postgres database is stored externally
- data:/var/lib/postgresql/data/ - data:/var/lib/postgresql/data/
restart: unless-stopped restart: unless-stopped
@ -43,8 +44,8 @@ services:
depends_on: depends_on:
- inventree-db - inventree-db
volumes: volumes:
# Map 'data' volume
- data:/home/inventree/data - data:/home/inventree/data
- static:/home/inventree/static
environment: environment:
# Default environment variables are configured to match the 'db' container # Default environment variables are configured to match the 'db' container
# Note: If you change the database image, these will need to be adjusted # Note: If you change the database image, these will need to be adjusted
@ -67,7 +68,6 @@ services:
- inventree-server - inventree-server
volumes: volumes:
- data:/home/inventree/data - data:/home/inventree/data
- static:/home/inventree/static
environment: environment:
# Default environment variables are configured to match the 'db' container # Default environment variables are configured to match the 'db' container
# Note: If you change the database image, these will need to be adjusted # Note: If you change the database image, these will need to be adjusted
@ -81,7 +81,8 @@ services:
restart: unless-stopped restart: unless-stopped
# nginx acts as a reverse proxy # 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 # web requests are redirected to gunicorn
# NOTE: You will need to provide a working nginx.conf file! # NOTE: You will need to provide a working nginx.conf file!
inventree-proxy: inventree-proxy:
@ -93,11 +94,11 @@ services:
# Change "1337" to the port that you want InvenTree web server to be available on # Change "1337" to the port that you want InvenTree web server to be available on
- 1337:80 - 1337:80
volumes: 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 # Refer to the provided example file as a starting point
- ./nginx.conf:/etc/nginx/conf.d/default.conf:ro - ./nginx.conf:/etc/nginx/conf.d/default.conf:ro
# Static data volume is mounted to /var/www/static # nginx proxy needs access to static and media files
- static:/var/www/static:ro - data:/var/www
restart: unless-stopped restart: unless-stopped
volumes: volumes:
@ -110,6 +111,4 @@ volumes:
o: bind o: bind
# This directory specified where InvenTree data are stored "outside" the docker containers # 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 # Change this path to a local system path where you want InvenTree data stored
device: /path/to/data 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" echo "$INVENTREE_CONFIG_FILE exists - skipping"
else else
echo "Copying config file to $INVENTREE_CONFIG_FILE" 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 fi
echo "Starting InvenTree server..." echo "Starting InvenTree server..."