2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-09-13 14:11:37 +00:00

Debian docker image (#10227)

* Debian docker image

- Swap from alpine to debian slim-trixie
- Refactor Dockerfile
- Optimize image size
- Reduce @vitejs/plugin-react version

* Remove commented-out lines

* Ensure invoke is installed

* Adjust Dockerfile

* Actually build the python libs

* Adjust dockerfile

* Install git in dev image

* Tweaks
This commit is contained in:
Oliver
2025-09-03 17:05:03 +10:00
committed by GitHub
parent 7969d2d9ce
commit 085381fa70
5 changed files with 68 additions and 80 deletions

View File

@@ -36,7 +36,7 @@ RUN apt install -y \
yarn nodejs npm yarn nodejs npm
# Update to the latest stable node version # Update to the latest stable node version
RUN npm install -g n@10.1.0 --ignore-scripts && n lts RUN npm install -g n --ignore-scripts && n lts
RUN yarn config set network-timeout 600000 -g RUN yarn config set network-timeout 600000 -g

View File

@@ -9,7 +9,7 @@
# - Runs InvenTree web server under django development server # - Runs InvenTree web server under django development server
# - Monitors source files for any changes, and live-reloads server # - Monitors source files for any changes, and live-reloads server
FROM python:3.11-alpine3.20@sha256:520924f35357a374aa1beaa81b867f449f9f12a53f00b69ad03c3d697fdf4aad AS inventree_base FROM python:3.11-slim-trixie AS inventree_base
# Build arguments for this image # Build arguments for this image
ARG commit_tag="" ARG commit_tag=""
@@ -20,7 +20,7 @@ ARG data_dir="data"
ENV PYTHONUNBUFFERED=1 ENV PYTHONUNBUFFERED=1
ENV PIP_DISABLE_PIP_VERSION_CHECK=1 ENV PIP_DISABLE_PIP_VERSION_CHECK=1
ENV INVOKE_RUN_SHELL="/bin/ash" ENV INVOKE_RUN_SHELL="/bin/bash"
ENV INVENTREE_DOCKER="true" ENV INVENTREE_DOCKER="true"
@@ -58,63 +58,75 @@ LABEL org.opencontainers.image.vendor="inventree" \
org.opencontainers.image.licenses="MIT" \ org.opencontainers.image.licenses="MIT" \
org.opencontainers.image.version=${commit_tag} org.opencontainers.image.version=${commit_tag}
# Install basic system level packages
# Install required system level packages RUN apt-get update && apt-get install -y --no-install-recommends \
RUN apk add --no-cache \ git gettext libldap2 wget curl ssh \
git gettext py-cryptography \
# Image format support
libjpeg libwebp zlib \
# Weasyprint requirements : https://doc.courtbouillon.org/weasyprint/stable/first_steps.html#alpine-3-12 # Weasyprint requirements : https://doc.courtbouillon.org/weasyprint/stable/first_steps.html#alpine-3-12
py3-pip py3-pillow py3-cffi py3-brotli pango poppler-utils openldap \ weasyprint libpango-1.0-0 libcairo2 poppler-utils \
# Postgres client (note: backwards compatible with postgres server <= 16) # Database client libraries
postgresql16-client \ postgresql-client mariadb-client \
# MySQL / MariaDB client
mariadb-client mariadb-connector-c \
&& \
# font support # font support
apk --update --upgrade --no-cache add fontconfig ttf-freefont font-terminus font-noto font-noto-cjk font-noto-extra \ fontconfig fonts-freefont-ttf fonts-terminus fonts-noto-core fonts-noto-cjk \
&& fc-cache -f # Cleanup
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Remove heavy python packages installed by weasyprint (that we don't need)
RUN rm -rf /usr/lib/python3/dist-packages/numpy \
&& rm -rf /usr/lib/python3/dist-packages/scipy \
&& rm -rf /usr/lib/python3/dist-packages/sympy
EXPOSE 8000 EXPOSE 8000
# Fix invoke command path for InvenTree environment check
RUN python -m pip install -U invoke
RUN mkdir -p ${INVENTREE_HOME} RUN mkdir -p ${INVENTREE_HOME}
WORKDIR ${INVENTREE_HOME} WORKDIR ${INVENTREE_HOME}
COPY contrib/container/requirements.txt base_requirements.txt COPY contrib/container/requirements.txt base_requirements.txt
COPY src/backend/requirements.txt ./
COPY contrib/container/install_build_packages.sh .
RUN chmod +x install_build_packages.sh
# For ARMv7 architecture, add the piwheels repo (for cryptography library) COPY tasks.py \
# Otherwise, we have to build from source, which is difficult src/backend/requirements.txt \
# Ref: https://github.com/inventree/InvenTree/pull/4598 contrib/container/gunicorn.conf.py \
RUN if [ `apk --print-arch` = "armv7" ]; then \ contrib/container/init.sh \
printf "[global]\nextra-index-url=https://www.piwheels.org/simple\n" > /etc/pip.conf ; \ ./
fi
COPY tasks.py contrib/container/gunicorn.conf.py contrib/container/init.sh ./
RUN chmod +x init.sh RUN chmod +x init.sh
ENTRYPOINT ["/bin/ash", "./init.sh"] ENTRYPOINT ["/bin/bash", "./init.sh"]
FROM inventree_base AS prebuild # Multi-stage build to compile project requirements
FROM inventree_base AS builder_stage
ENV PATH=/root/.local/bin:$PATH # Copy source files
RUN ./install_build_packages.sh --no-cache --virtual .build-deps && \
pip install --user --require-hashes -r base_requirements.txt --no-cache && \
pip install --user --require-hashes -r requirements.txt --no-cache && \
apk --purge del .build-deps
# Frontend builder image:
FROM prebuild AS frontend
RUN apk add --no-cache --update nodejs npm yarn bash
RUN npm install -g n --ignore-scripts
RUN bash -c "n lts"
RUN yarn config set network-timeout 600000 -g
COPY src ${INVENTREE_HOME}/src COPY src ${INVENTREE_HOME}/src
COPY tasks.py ${INVENTREE_HOME}/tasks.py COPY tasks.py ${INVENTREE_HOME}/tasks.py
RUN cd ${INVENTREE_HOME} && invoke int.frontend-compile
# Install backend build dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
pkg-config build-essential \
libldap2-dev libsasl2-dev libssl-dev \
libmariadb-dev \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Build and install python dependencies
RUN pip install --user --require-hashes -r base_requirements.txt --no-cache && \
pip install --user --require-hashes -r requirements.txt --no-cache && \
pip cache purge && \
rm -rf /root/.cache/pip
# Install frontend build dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
nodejs npm \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
RUN npm install -g n --ignore-scripts
RUN npm install -g yarn
RUN bash -c "n lts"
RUN yarn config set network-timeout 600000 -g
RUN cd ${INVENTREE_HOME} && invoke int.frontend-compile --extract
# InvenTree production image: # InvenTree production image:
# - Copies required files from local directory # - Copies required files from local directory
@@ -127,39 +139,26 @@ ENV INVENTREE_DEBUG=False
ENV INVENTREE_COMMIT_HASH="${commit_hash}" ENV INVENTREE_COMMIT_HASH="${commit_hash}"
ENV INVENTREE_COMMIT_DATE="${commit_date}" ENV INVENTREE_COMMIT_DATE="${commit_date}"
# use dependencies and compiled wheels from the prebuild image
ENV PATH=/root/.local/bin:$PATH
COPY --from=prebuild /root/.local /root/.local
# Copy source code # Copy source code
COPY src/backend/InvenTree ${INVENTREE_BACKEND_DIR}/InvenTree COPY src/backend/InvenTree ${INVENTREE_BACKEND_DIR}/InvenTree
COPY src/backend/requirements.txt ${INVENTREE_BACKEND_DIR}/requirements.txt COPY src/backend/requirements.txt ${INVENTREE_BACKEND_DIR}/requirements.txt
COPY --from=frontend ${INVENTREE_BACKEND_DIR}/InvenTree/web/static/web ${INVENTREE_BACKEND_DIR}/InvenTree/web/static/web
# Fix invoke command path for InvenTree environment check # Copy compiled dependencies from prebuild image
RUN ln -sf /root/.local/bin/invoke /bin/invoke ENV PATH=/root/.local/bin:$PATH
COPY --from=builder_stage ${INVENTREE_BACKEND_DIR}/InvenTree/web/static/web ${INVENTREE_BACKEND_DIR}/InvenTree/web/static/web
COPY --from=builder_stage /root/.local /root/.local
# Launch the production server # Launch the production server
CMD gunicorn -c ./gunicorn.conf.py InvenTree.wsgi -b 0.0.0.0:8000 --chdir ${INVENTREE_BACKEND_DIR}/InvenTree CMD ["sh", "-c", "exec gunicorn -c ./gunicorn.conf.py InvenTree.wsgi -b 0.0.0.0:8000 --chdir ${INVENTREE_BACKEND_DIR}/InvenTree"]
FROM inventree_base AS dev FROM builder_stage AS dev
ENV PATH=/root/.local/bin:$PATH
# Vite server (for local frontend development) # Vite server (for local frontend development)
EXPOSE 5173 EXPOSE 5173
# Install packages required for building python packages
RUN ./install_build_packages.sh
RUN pip install --require-hashes -r base_requirements.txt --no-cache
# Install nodejs / npm / yarn
RUN apk add --no-cache --update nodejs npm yarn bash
RUN npm install -g n --ignore-scripts
RUN bash -c "n lts"
RUN yarn config set network-timeout 600000 -g
# The development image requires the source code to be mounted to /home/inventree/ # 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 # So from here, we don't actually "do" anything, apart from some file management
@@ -172,7 +171,7 @@ ENV INVENTREE_PY_ENV="${INVENTREE_DATA_DIR}/env"
WORKDIR ${INVENTREE_HOME} WORKDIR ${INVENTREE_HOME}
# Entrypoint ensures that we are running in the python virtual environment # Entrypoint ensures that we are running in the python virtual environment
ENTRYPOINT ["/bin/ash", "./contrib/container/init.sh"] ENTRYPOINT ["/bin/bash", "./contrib/container/init.sh"]
# Launch the development server # Launch the development server
CMD ["invoke", "dev.server", "-a", "${INVENTREE_WEB_ADDR}:${INVENTREE_WEB_PORT}"] CMD ["invoke", "dev.server", "-a", "${INVENTREE_WEB_ADDR}:${INVENTREE_WEB_PORT}"]

View File

@@ -18,7 +18,7 @@ services:
# Use PostgreSQL as the database backend # Use PostgreSQL as the database backend
# Note: This can be changed to a different backend if required # Note: This can be changed to a different backend if required
inventree-dev-db: inventree-dev-db:
image: postgres:13 image: postgres:17
expose: expose:
- 5432/tcp - 5432/tcp
environment: environment:

View File

@@ -42,7 +42,7 @@ services:
# Database service # Database service
# Use PostgreSQL as the database backend # Use PostgreSQL as the database backend
inventree-db: inventree-db:
image: postgres:16 image: postgres:17
container_name: inventree-db container_name: inventree-db
expose: expose:
- ${INVENTREE_DB_PORT:-5432}/tcp - ${INVENTREE_DB_PORT:-5432}/tcp

View File

@@ -1,11 +0,0 @@
#!/bin/ash
# Install system packages required for building InvenTree python libraries
apk add gcc g++ musl-dev openssl-dev libffi-dev cargo python3-dev openldap-dev \
libstdc++ build-base linux-headers py3-grpcio \
jpeg-dev openjpeg-dev libwebp-dev zlib-dev \
sqlite sqlite-dev \
mariadb-connector-c-dev mariadb-client mariadb-dev \
postgresql16-dev postgresql-libs \
$@