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
|
|
|
|
2024-02-26 22:50:44 +00:00
|
|
|
ARG base_image=python:3.11-alpine3.18
|
2023-12-04 20:05:48 +00:00
|
|
|
FROM ${base_image} as inventree_base
|
2022-05-28 23:40:37 +00:00
|
|
|
|
|
|
|
# Build arguments for this image
|
2024-02-01 01:25:24 +00:00
|
|
|
ARG commit_tag=""
|
2022-05-28 23:40:37 +00:00
|
|
|
ARG commit_hash=""
|
|
|
|
ARG commit_date=""
|
2021-08-12 12:01:14 +00:00
|
|
|
|
2024-02-28 04:04:14 +00:00
|
|
|
ARG data_dir="data"
|
|
|
|
|
2021-03-31 11:45:42 +00:00
|
|
|
ENV PYTHONUNBUFFERED 1
|
2023-07-10 09:52:33 +00:00
|
|
|
ENV PIP_DISABLE_PIP_VERSION_CHECK 1
|
|
|
|
ENV INVOKE_RUN_SHELL="/bin/ash"
|
2021-03-31 11:45:42 +00:00
|
|
|
|
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"
|
2024-02-28 04:04:14 +00:00
|
|
|
ENV INVENTREE_DATA_DIR="${INVENTREE_HOME}/${data_dir}"
|
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
|
|
|
|
2023-12-04 20:05:48 +00:00
|
|
|
# Install required system level packages
|
2023-07-10 09:52:33 +00:00
|
|
|
RUN apk add --no-cache \
|
|
|
|
git gettext py-cryptography \
|
2022-05-28 23:40:37 +00:00
|
|
|
# Image format support
|
2023-07-10 09:52:33 +00:00
|
|
|
libjpeg libwebp zlib \
|
|
|
|
# Weasyprint requirements : https://doc.courtbouillon.org/weasyprint/stable/first_steps.html#alpine-3-12
|
2024-02-27 14:06:19 +00:00
|
|
|
py3-pip py3-pillow py3-cffi py3-brotli pango poppler-utils openldap \
|
2024-03-04 11:50:00 +00:00
|
|
|
# Postgres client
|
|
|
|
postgresql13-client \
|
|
|
|
# MySQL / MariaDB client
|
|
|
|
mariadb-client mariadb-connector-c \
|
|
|
|
&& \
|
2023-07-10 09:52:33 +00:00
|
|
|
# fonts
|
|
|
|
apk --update --upgrade --no-cache add fontconfig ttf-freefont font-noto terminus-font && fc-cache -f
|
|
|
|
|
|
|
|
EXPOSE 8000
|
|
|
|
|
|
|
|
RUN mkdir -p ${INVENTREE_HOME}
|
|
|
|
WORKDIR ${INVENTREE_HOME}
|
2021-03-31 11:45:42 +00:00
|
|
|
|
2023-07-10 09:52:33 +00:00
|
|
|
COPY ./docker/requirements.txt base_requirements.txt
|
|
|
|
COPY ./requirements.txt ./
|
2023-12-04 20:05:48 +00:00
|
|
|
COPY ./docker/install_build_packages.sh .
|
|
|
|
RUN chmod +x install_build_packages.sh
|
2021-10-12 13:52:48 +00:00
|
|
|
|
2023-07-10 09:52:33 +00:00
|
|
|
# For ARMv7 architecture, add the piwheels repo (for cryptography library)
|
2023-04-11 05:23:36 +00:00
|
|
|
# Otherwise, we have to build from source, which is difficult
|
|
|
|
# Ref: https://github.com/inventree/InvenTree/pull/4598
|
2023-07-10 09:52:33 +00:00
|
|
|
RUN if [ `apk --print-arch` = "armv7" ]; then \
|
|
|
|
printf "[global]\nextra-index-url=https://www.piwheels.org/simple\n" > /etc/pip.conf ; \
|
|
|
|
fi
|
2023-04-11 05:23:36 +00:00
|
|
|
|
2023-07-10 09:52:33 +00:00
|
|
|
COPY tasks.py docker/gunicorn.conf.py docker/init.sh ./
|
|
|
|
RUN chmod +x init.sh
|
|
|
|
|
2024-02-07 11:33:37 +00:00
|
|
|
ENTRYPOINT ["/bin/ash", "./init.sh"]
|
2022-05-28 23:40:37 +00:00
|
|
|
|
2023-12-04 20:05:48 +00:00
|
|
|
FROM inventree_base as prebuild
|
|
|
|
|
2023-12-10 22:57:37 +00:00
|
|
|
ENV PATH=/root/.local/bin:$PATH
|
2023-12-04 20:05:48 +00:00
|
|
|
RUN ./install_build_packages.sh --no-cache --virtual .build-deps && \
|
2024-03-04 11:50:00 +00:00
|
|
|
pip install --user -r base_requirements.txt -r requirements.txt --no-cache && \
|
2023-12-04 20:05:48 +00:00
|
|
|
apk --purge del .build-deps
|
|
|
|
|
2023-07-18 12:45:49 +00:00
|
|
|
# Frontend builder image:
|
2023-12-04 20:05:48 +00:00
|
|
|
FROM prebuild as frontend
|
2023-07-18 12:45:49 +00:00
|
|
|
|
|
|
|
RUN apk add --no-cache --update nodejs npm && npm install -g yarn
|
2023-09-05 03:10:00 +00:00
|
|
|
RUN yarn config set network-timeout 600000 -g
|
2023-07-18 12:45:49 +00:00
|
|
|
COPY InvenTree ${INVENTREE_HOME}/InvenTree
|
|
|
|
COPY src ${INVENTREE_HOME}/src
|
|
|
|
COPY tasks.py ${INVENTREE_HOME}/tasks.py
|
|
|
|
RUN cd ${INVENTREE_HOME}/InvenTree && inv frontend-compile
|
|
|
|
|
2022-05-28 23:40:37 +00:00
|
|
|
# InvenTree production image:
|
|
|
|
# - Copies required files from local directory
|
|
|
|
# - Starts a gunicorn webserver
|
2023-12-10 22:57:37 +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
|
|
|
|
2023-12-10 22:57:37 +00:00
|
|
|
# use dependencies and compiled wheels from the prebuild image
|
|
|
|
ENV PATH=/root/.local/bin:$PATH
|
|
|
|
COPY --from=prebuild /root/.local /root/.local
|
|
|
|
|
2022-05-28 23:40:37 +00:00
|
|
|
# Copy source code
|
2023-07-10 09:52:33 +00:00
|
|
|
COPY InvenTree ./InvenTree
|
2023-07-18 12:45:49 +00:00
|
|
|
COPY --from=frontend ${INVENTREE_HOME}/InvenTree/web/static/web ./InvenTree/web/static/web
|
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
|
|
|
|
2023-12-04 20:05:48 +00:00
|
|
|
# Vite server (for local frontend development)
|
|
|
|
EXPOSE 5173
|
|
|
|
|
|
|
|
# Install packages required for building python packages
|
|
|
|
RUN ./install_build_packages.sh
|
|
|
|
|
2024-02-28 04:04:14 +00:00
|
|
|
RUN pip install uv --no-cache-dir && pip install -r base_requirements.txt --no-cache
|
2023-12-04 20:05:48 +00:00
|
|
|
|
2023-07-18 12:45:49 +00:00
|
|
|
# Install nodejs / npm / yarn
|
2023-09-05 03:10:00 +00:00
|
|
|
|
2023-07-18 20:28:00 +00:00
|
|
|
RUN apk add --no-cache --update nodejs npm && npm install -g yarn
|
2023-09-05 03:10:00 +00:00
|
|
|
RUN yarn config set network-timeout 600000 -g
|
2023-07-18 12:45:49 +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
|
2023-07-10 09:52:33 +00:00
|
|
|
ENTRYPOINT ["/bin/ash", "./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}"]
|