2022-05-28 23:40:37 +00:00
|
|
|
# The InvenTree dockerfile provides two build targets:
|
|
|
|
#
|
|
|
|
# production:
|
|
|
|
# - Required files are copied into the image
|
|
|
|
# - Runs InvenTree web server under gunicorn
|
|
|
|
#
|
|
|
|
# dev:
|
|
|
|
# - Expects source directories to be loaded as a run-time volume
|
|
|
|
# - Runs InvenTree web server under django development server
|
|
|
|
# - Monitors source files for any changes, and live-reloads server
|
2021-03-31 11:45:42 +00:00
|
|
|
|
2023-04-11 05:23:36 +00:00
|
|
|
FROM python:3.9-slim as inventree_base
|
2022-05-28 23:40:37 +00:00
|
|
|
|
|
|
|
# Build arguments for this image
|
|
|
|
ARG commit_hash=""
|
|
|
|
ARG commit_date=""
|
|
|
|
ARG commit_tag=""
|
2021-08-12 12:01:14 +00:00
|
|
|
|
2021-03-31 11:45:42 +00:00
|
|
|
ENV PYTHONUNBUFFERED 1
|
|
|
|
|
2022-07-03 11:44:40 +00:00
|
|
|
ENV INVENTREE_LOG_LEVEL="WARNING"
|
2021-05-16 16:19:35 +00:00
|
|
|
ENV INVENTREE_DOCKER="true"
|
2021-04-01 13:40:47 +00:00
|
|
|
|
2021-03-31 11:45:42 +00:00
|
|
|
# InvenTree paths
|
2022-05-28 23:40:37 +00:00
|
|
|
ENV INVENTREE_HOME="/home/inventree"
|
2021-06-16 12:36:05 +00:00
|
|
|
ENV INVENTREE_MNG_DIR="${INVENTREE_HOME}/InvenTree"
|
2021-04-10 07:36:19 +00:00
|
|
|
ENV INVENTREE_DATA_DIR="${INVENTREE_HOME}/data"
|
2021-06-16 12:36:05 +00:00
|
|
|
ENV INVENTREE_STATIC_ROOT="${INVENTREE_DATA_DIR}/static"
|
2021-04-10 09:01:02 +00:00
|
|
|
ENV INVENTREE_MEDIA_ROOT="${INVENTREE_DATA_DIR}/media"
|
2022-10-16 13:09:31 +00:00
|
|
|
ENV INVENTREE_BACKUP_DIR="${INVENTREE_DATA_DIR}/backup"
|
2022-01-06 01:37:12 +00:00
|
|
|
ENV INVENTREE_PLUGIN_DIR="${INVENTREE_DATA_DIR}/plugins"
|
2021-04-01 09:14:17 +00:00
|
|
|
|
2022-05-28 23:40:37 +00:00
|
|
|
# InvenTree configuration files
|
2021-04-10 07:36:19 +00:00
|
|
|
ENV INVENTREE_CONFIG_FILE="${INVENTREE_DATA_DIR}/config.yaml"
|
2021-04-10 09:01:02 +00:00
|
|
|
ENV INVENTREE_SECRET_KEY_FILE="${INVENTREE_DATA_DIR}/secret_key.txt"
|
2022-01-06 02:31:04 +00:00
|
|
|
ENV INVENTREE_PLUGIN_FILE="${INVENTREE_DATA_DIR}/plugins.txt"
|
2021-04-10 07:36:19 +00:00
|
|
|
|
2021-07-29 06:37:34 +00:00
|
|
|
# Worker configuration (can be altered by user)
|
|
|
|
ENV INVENTREE_GUNICORN_WORKERS="4"
|
|
|
|
ENV INVENTREE_BACKGROUND_WORKERS="4"
|
|
|
|
|
2021-08-17 09:58:55 +00:00
|
|
|
# Default web server address:port
|
2021-08-17 23:34:09 +00:00
|
|
|
ENV INVENTREE_WEB_ADDR=0.0.0.0
|
|
|
|
ENV INVENTREE_WEB_PORT=8000
|
2021-04-18 05:05:52 +00:00
|
|
|
|
2021-04-01 00:35:03 +00:00
|
|
|
LABEL org.label-schema.schema-version="1.0" \
|
2021-04-01 09:14:17 +00:00
|
|
|
org.label-schema.build-date=${DATE} \
|
2021-04-01 00:35:03 +00:00
|
|
|
org.label-schema.vendor="inventree" \
|
|
|
|
org.label-schema.name="inventree/inventree" \
|
2021-04-01 13:40:47 +00:00
|
|
|
org.label-schema.url="https://hub.docker.com/r/inventree/inventree" \
|
2022-05-28 23:40:37 +00:00
|
|
|
org.label-schema.vcs-url="https://github.com/inventree/InvenTree.git" \
|
|
|
|
org.label-schema.vcs-ref=${commit_tag}
|
2021-04-01 00:35:03 +00:00
|
|
|
|
2022-05-28 23:40:37 +00:00
|
|
|
# RUN apt-get upgrade && apt-get update
|
|
|
|
RUN apt-get update
|
2021-10-12 13:53:41 +00:00
|
|
|
|
2021-03-31 11:45:42 +00:00
|
|
|
# Install required system packages
|
2022-05-28 23:40:37 +00:00
|
|
|
RUN apt-get install -y --no-install-recommends \
|
2023-04-11 05:23:36 +00:00
|
|
|
git gcc g++ gettext gnupg libffi-dev libssl-dev \
|
2022-05-28 23:40:37 +00:00
|
|
|
# Weasyprint requirements : https://doc.courtbouillon.org/weasyprint/stable/first_steps.html#debian-11
|
|
|
|
poppler-utils libpango-1.0-0 libpangoft2-1.0-0 \
|
|
|
|
# Image format support
|
2023-02-11 20:10:48 +00:00
|
|
|
libjpeg-dev webp libwebp-dev \
|
2021-08-17 12:58:44 +00:00
|
|
|
# SQLite support
|
2022-05-28 23:40:37 +00:00
|
|
|
sqlite3 \
|
2021-08-17 12:58:44 +00:00
|
|
|
# PostgreSQL support
|
2022-10-17 03:50:05 +00:00
|
|
|
libpq-dev postgresql-client \
|
2022-05-28 23:40:37 +00:00
|
|
|
# MySQL / MariaDB support
|
|
|
|
default-libmysqlclient-dev mariadb-client && \
|
|
|
|
apt-get autoclean && apt-get autoremove
|
2021-03-31 11:45:42 +00:00
|
|
|
|
2021-10-12 13:52:48 +00:00
|
|
|
# Update pip
|
|
|
|
RUN pip install --upgrade pip
|
|
|
|
|
2023-04-11 05:23:36 +00:00
|
|
|
# For ARMv7 architecture, add the pinwheels repo (for cryptography library)
|
|
|
|
# Otherwise, we have to build from source, which is difficult
|
|
|
|
# Ref: https://github.com/inventree/InvenTree/pull/4598
|
|
|
|
RUN \
|
|
|
|
if [ `dpkg --print-architecture` = "armhf" ]; then \
|
|
|
|
printf "[global]\nextra-index-url=https://www.piwheels.org/simple\n" > /etc/pip.conf ; \
|
|
|
|
fi
|
|
|
|
|
2021-08-18 02:03:24 +00:00
|
|
|
# Install required base-level python packages
|
2022-05-28 23:40:37 +00:00
|
|
|
COPY ./docker/requirements.txt base_requirements.txt
|
|
|
|
RUN pip install --disable-pip-version-check -U -r base_requirements.txt
|
|
|
|
|
|
|
|
# InvenTree production image:
|
|
|
|
# - Copies required files from local directory
|
|
|
|
# - Installs required python packages from requirements.txt
|
|
|
|
# - Starts a gunicorn webserver
|
2021-08-18 04:47:34 +00:00
|
|
|
|
2023-04-11 05:23:36 +00:00
|
|
|
FROM inventree_base as production
|
2021-08-17 12:58:44 +00:00
|
|
|
|
2022-05-28 23:40:37 +00:00
|
|
|
ENV INVENTREE_DEBUG=False
|
2021-08-12 12:01:14 +00:00
|
|
|
|
2022-05-28 23:40:37 +00:00
|
|
|
# As .git directory is not available in production image, we pass the commit information via ENV
|
|
|
|
ENV INVENTREE_COMMIT_HASH="${commit_hash}"
|
|
|
|
ENV INVENTREE_COMMIT_DATE="${commit_date}"
|
2021-08-12 12:01:14 +00:00
|
|
|
|
2022-05-28 23:40:37 +00:00
|
|
|
# Copy source code
|
|
|
|
COPY InvenTree ${INVENTREE_HOME}/InvenTree
|
2022-05-10 13:24:32 +00:00
|
|
|
|
2022-05-28 23:40:37 +00:00
|
|
|
# Copy other key files
|
|
|
|
COPY requirements.txt ${INVENTREE_HOME}/requirements.txt
|
|
|
|
COPY tasks.py ${INVENTREE_HOME}/tasks.py
|
|
|
|
COPY docker/gunicorn.conf.py ${INVENTREE_HOME}/gunicorn.conf.py
|
|
|
|
COPY docker/init.sh ${INVENTREE_MNG_DIR}/init.sh
|
2021-04-10 05:08:10 +00:00
|
|
|
|
2022-05-28 23:40:37 +00:00
|
|
|
# Need to be running from within this directory
|
|
|
|
WORKDIR ${INVENTREE_MNG_DIR}
|
|
|
|
|
|
|
|
# Drop to the inventree user for the production image
|
2022-05-29 22:37:58 +00:00
|
|
|
#RUN adduser inventree
|
|
|
|
#RUN chown -R inventree:inventree ${INVENTREE_HOME}
|
|
|
|
#USER inventree
|
2021-04-01 13:40:47 +00:00
|
|
|
|
2021-08-17 12:58:44 +00:00
|
|
|
# Install InvenTree packages
|
2022-05-28 23:40:37 +00:00
|
|
|
RUN pip3 install --user --disable-pip-version-check -r ${INVENTREE_HOME}/requirements.txt
|
2021-08-18 06:29:54 +00:00
|
|
|
|
2021-08-17 12:58:44 +00:00
|
|
|
# Server init entrypoint
|
2022-05-28 23:40:37 +00:00
|
|
|
ENTRYPOINT ["/bin/bash", "./init.sh"]
|
2021-04-10 12:25:07 +00:00
|
|
|
|
2021-08-17 12:58:44 +00:00
|
|
|
# Launch the production server
|
2021-08-19 01:14:13 +00:00
|
|
|
# TODO: Work out why environment variables cannot be interpolated in this command
|
|
|
|
# TODO: e.g. -b ${INVENTREE_WEB_ADDR}:${INVENTREE_WEB_PORT} fails here
|
2022-05-28 23:40:37 +00:00
|
|
|
CMD gunicorn -c ./gunicorn.conf.py InvenTree.wsgi -b 0.0.0.0:8000 --chdir ./InvenTree
|
2021-05-10 04:23:17 +00:00
|
|
|
|
2023-04-11 05:23:36 +00:00
|
|
|
FROM inventree_base as dev
|
2021-05-12 10:53:50 +00:00
|
|
|
|
2021-06-15 13:05:03 +00:00
|
|
|
# The development image requires the source code to be mounted to /home/inventree/
|
|
|
|
# So from here, we don't actually "do" anything, apart from some file management
|
2021-05-10 04:23:17 +00:00
|
|
|
|
2022-05-28 23:40:37 +00:00
|
|
|
ENV INVENTREE_DEBUG=True
|
|
|
|
|
2021-08-17 12:58:44 +00:00
|
|
|
# Location for python virtual environment
|
|
|
|
# If the INVENTREE_PY_ENV variable is set, the entrypoint script will use it!
|
2022-07-19 23:05:05 +00:00
|
|
|
ENV INVENTREE_PY_ENV="${INVENTREE_DATA_DIR}/env"
|
2022-01-06 02:31:04 +00:00
|
|
|
|
2021-06-15 13:05:03 +00:00
|
|
|
WORKDIR ${INVENTREE_HOME}
|
2021-05-12 10:53:50 +00:00
|
|
|
|
2021-08-17 23:52:27 +00:00
|
|
|
# Entrypoint ensures that we are running in the python virtual environment
|
|
|
|
ENTRYPOINT ["/bin/bash", "./docker/init.sh"]
|
2021-08-17 12:58:44 +00:00
|
|
|
|
2021-06-16 12:36:05 +00:00
|
|
|
# Launch the development server
|
2021-08-17 23:52:27 +00:00
|
|
|
CMD ["invoke", "server", "-a", "${INVENTREE_WEB_ADDR}:${INVENTREE_WEB_PORT}"]
|