mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Refactor: Dockerimage (#5007)
* refactor docker image to reduce size * Added required deps for database drivers * Added alpine test dockerfile * Readded image libs to Dockerfile * Fix link in dockerfile * Replaced Dockerfile * Remove bash from image * Added base target to Dockerfile * Added missing mysql dev headers * Add dev target back to Dockerfile * fix: Dockerfile style * Add old comments back to dockerfile * Removed wrong comment * Added back piwheels repo
This commit is contained in:
parent
8fb7612894
commit
4a1f73331f
89
Dockerfile
89
Dockerfile
@ -9,7 +9,7 @@
|
||||
# - Runs InvenTree web server under django development server
|
||||
# - Monitors source files for any changes, and live-reloads server
|
||||
|
||||
FROM python:3.9-slim as inventree_base
|
||||
FROM python:3.10-alpine3.18 as inventree_base
|
||||
|
||||
# Build arguments for this image
|
||||
ARG commit_hash=""
|
||||
@ -17,6 +17,8 @@ ARG commit_date=""
|
||||
ARG commit_tag=""
|
||||
|
||||
ENV PYTHONUNBUFFERED 1
|
||||
ENV PIP_DISABLE_PIP_VERSION_CHECK 1
|
||||
ENV INVOKE_RUN_SHELL="/bin/ash"
|
||||
|
||||
ENV INVENTREE_LOG_LEVEL="WARNING"
|
||||
ENV INVENTREE_DOCKER="true"
|
||||
@ -51,44 +53,54 @@ LABEL org.label-schema.schema-version="1.0" \
|
||||
org.label-schema.vcs-url="https://github.com/inventree/InvenTree.git" \
|
||||
org.label-schema.vcs-ref=${commit_tag}
|
||||
|
||||
# RUN apt-get upgrade && apt-get update
|
||||
RUN apt-get update
|
||||
|
||||
# Install required system packages
|
||||
RUN apt-get install -y --no-install-recommends \
|
||||
git gcc g++ gettext gnupg libffi-dev libssl-dev \
|
||||
# Weasyprint requirements : https://doc.courtbouillon.org/weasyprint/stable/first_steps.html#debian-11
|
||||
poppler-utils libpango-1.0-0 libpangoft2-1.0-0 \
|
||||
RUN apk add --no-cache \
|
||||
git gettext py-cryptography \
|
||||
# Image format support
|
||||
libjpeg-dev webp libwebp-dev \
|
||||
libjpeg libwebp zlib \
|
||||
# Weasyprint requirements : https://doc.courtbouillon.org/weasyprint/stable/first_steps.html#alpine-3-12
|
||||
py3-pip py3-pillow py3-cffi py3-brotli pango \
|
||||
# SQLite support
|
||||
sqlite3 \
|
||||
sqlite \
|
||||
# PostgreSQL support
|
||||
libpq-dev postgresql-client \
|
||||
postgresql-libs postgresql-client \
|
||||
# MySQL / MariaDB support
|
||||
default-libmysqlclient-dev mariadb-client && \
|
||||
apt-get autoclean && apt-get autoremove
|
||||
mariadb-connector-c-dev mariadb-client && \
|
||||
# fonts
|
||||
apk --update --upgrade --no-cache add fontconfig ttf-freefont font-noto terminus-font && fc-cache -f
|
||||
|
||||
# Update pip
|
||||
RUN pip install --upgrade pip
|
||||
EXPOSE 8000
|
||||
|
||||
# For ARMv7 architecture, add the pinwheels repo (for cryptography library)
|
||||
RUN mkdir -p ${INVENTREE_HOME}
|
||||
WORKDIR ${INVENTREE_HOME}
|
||||
|
||||
COPY ./docker/requirements.txt base_requirements.txt
|
||||
COPY ./requirements.txt ./
|
||||
|
||||
# For ARMv7 architecture, add the piwheels 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
|
||||
RUN if [ `apk --print-arch` = "armv7" ]; then \
|
||||
printf "[global]\nextra-index-url=https://www.piwheels.org/simple\n" > /etc/pip.conf ; \
|
||||
fi
|
||||
|
||||
# Install required base-level python packages
|
||||
COPY ./docker/requirements.txt base_requirements.txt
|
||||
RUN pip install --disable-pip-version-check -U -r base_requirements.txt
|
||||
RUN apk add --no-cache --virtual .build-deps \
|
||||
gcc g++ musl-dev openssl-dev libffi-dev cargo python3-dev \
|
||||
# Image format dev libs
|
||||
jpeg-dev openjpeg-dev libwebp-dev zlib-dev \
|
||||
# DB specific dev libs
|
||||
postgresql-dev sqlite-dev mariadb-dev && \
|
||||
pip install -r base_requirements.txt -r requirements.txt --no-cache-dir && \
|
||||
apk --purge del .build-deps
|
||||
|
||||
COPY tasks.py docker/gunicorn.conf.py docker/init.sh ./
|
||||
|
||||
RUN chmod +x init.sh
|
||||
|
||||
ENTRYPOINT ["/bin/sh", "./init.sh"]
|
||||
|
||||
# InvenTree production image:
|
||||
# - Copies required files from local directory
|
||||
# - Installs required python packages from requirements.txt
|
||||
# - Starts a gunicorn webserver
|
||||
|
||||
FROM inventree_base as production
|
||||
|
||||
ENV INVENTREE_DEBUG=False
|
||||
@ -98,33 +110,14 @@ ENV INVENTREE_COMMIT_HASH="${commit_hash}"
|
||||
ENV INVENTREE_COMMIT_DATE="${commit_date}"
|
||||
|
||||
# Copy source code
|
||||
COPY InvenTree ${INVENTREE_HOME}/InvenTree
|
||||
|
||||
# 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
|
||||
|
||||
# Need to be running from within this directory
|
||||
WORKDIR ${INVENTREE_MNG_DIR}
|
||||
|
||||
# Drop to the inventree user for the production image
|
||||
#RUN adduser inventree
|
||||
#RUN chown -R inventree:inventree ${INVENTREE_HOME}
|
||||
#USER inventree
|
||||
|
||||
# Install InvenTree packages
|
||||
RUN pip3 install --user --disable-pip-version-check -r ${INVENTREE_HOME}/requirements.txt
|
||||
|
||||
# Server init entrypoint
|
||||
ENTRYPOINT ["/bin/bash", "./init.sh"]
|
||||
COPY InvenTree ./InvenTree
|
||||
|
||||
# Launch the production server
|
||||
# TODO: Work out why environment variables cannot be interpolated in this command
|
||||
# TODO: e.g. -b ${INVENTREE_WEB_ADDR}:${INVENTREE_WEB_PORT} fails here
|
||||
CMD gunicorn -c ./gunicorn.conf.py InvenTree.wsgi -b 0.0.0.0:8000 --chdir ./InvenTree
|
||||
|
||||
|
||||
FROM inventree_base as dev
|
||||
|
||||
# The development image requires the source code to be mounted to /home/inventree/
|
||||
@ -139,7 +132,7 @@ ENV INVENTREE_PY_ENV="${INVENTREE_DATA_DIR}/env"
|
||||
WORKDIR ${INVENTREE_HOME}
|
||||
|
||||
# Entrypoint ensures that we are running in the python virtual environment
|
||||
ENTRYPOINT ["/bin/bash", "./docker/init.sh"]
|
||||
ENTRYPOINT ["/bin/ash", "./docker/init.sh"]
|
||||
|
||||
# Launch the development server
|
||||
CMD ["invoke", "server", "-a", "${INVENTREE_WEB_ADDR}:${INVENTREE_WEB_PORT}"]
|
||||
|
@ -1,9 +1,11 @@
|
||||
#!/bin/bash
|
||||
#!/bin/sh
|
||||
# exit when any command fails
|
||||
set -e
|
||||
|
||||
# Required to suppress some git errors further down the line
|
||||
git config --global --add safe.directory /home/***
|
||||
if command -v git &> /dev/null; then
|
||||
git config --global --add safe.directory /home/***
|
||||
fi
|
||||
|
||||
# Create required directory structure (if it does not already exist)
|
||||
if [[ ! -d "$INVENTREE_STATIC_ROOT" ]]; then
|
||||
|
Loading…
Reference in New Issue
Block a user