mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-10-30 20:55:42 +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:
		
							
								
								
									
										85
									
								
								Dockerfile
									
									
									
									
									
								
							
							
						
						
									
										85
									
								
								Dockerfile
									
									
									
									
									
								
							| @@ -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.9-slim as inventree_base | FROM python:3.10-alpine3.18 as inventree_base | ||||||
|  |  | ||||||
| # Build arguments for this image | # Build arguments for this image | ||||||
| ARG commit_hash="" | ARG commit_hash="" | ||||||
| @@ -17,6 +17,8 @@ ARG commit_date="" | |||||||
| ARG commit_tag="" | ARG commit_tag="" | ||||||
|  |  | ||||||
| ENV PYTHONUNBUFFERED 1 | ENV PYTHONUNBUFFERED 1 | ||||||
|  | ENV PIP_DISABLE_PIP_VERSION_CHECK 1 | ||||||
|  | ENV INVOKE_RUN_SHELL="/bin/ash" | ||||||
|  |  | ||||||
| ENV INVENTREE_LOG_LEVEL="WARNING" | ENV INVENTREE_LOG_LEVEL="WARNING" | ||||||
| ENV INVENTREE_DOCKER="true" | 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-url="https://github.com/inventree/InvenTree.git" \ | ||||||
|       org.label-schema.vcs-ref=${commit_tag} |       org.label-schema.vcs-ref=${commit_tag} | ||||||
|  |  | ||||||
| # RUN apt-get upgrade && apt-get update | RUN apk add --no-cache \ | ||||||
| RUN apt-get update |     git gettext py-cryptography \ | ||||||
|  |  | ||||||
| # 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 \ |  | ||||||
|     # Image format support |     # 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 |     # SQLite support | ||||||
|     sqlite3 \ |     sqlite \ | ||||||
|     # PostgreSQL support |     # PostgreSQL support | ||||||
|     libpq-dev postgresql-client \ |     postgresql-libs postgresql-client \ | ||||||
|     # MySQL / MariaDB support |     # MySQL / MariaDB support | ||||||
|     default-libmysqlclient-dev mariadb-client && \ |     mariadb-connector-c-dev mariadb-client && \ | ||||||
|     apt-get autoclean && apt-get autoremove |     # fonts | ||||||
|  |     apk --update --upgrade --no-cache add fontconfig ttf-freefont font-noto terminus-font && fc-cache -f | ||||||
|  |  | ||||||
| # Update pip | EXPOSE 8000 | ||||||
| RUN pip install --upgrade pip |  | ||||||
|  |  | ||||||
| # 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 | # Otherwise, we have to build from source, which is difficult | ||||||
| # Ref: https://github.com/inventree/InvenTree/pull/4598 | # Ref: https://github.com/inventree/InvenTree/pull/4598 | ||||||
| RUN \ | RUN if [ `apk --print-arch` = "armv7" ]; then \ | ||||||
|    if [ `dpkg --print-architecture` = "armhf" ]; then \ |  | ||||||
|     printf "[global]\nextra-index-url=https://www.piwheels.org/simple\n" > /etc/pip.conf ; \ |     printf "[global]\nextra-index-url=https://www.piwheels.org/simple\n" > /etc/pip.conf ; \ | ||||||
|     fi |     fi | ||||||
|  |  | ||||||
| # Install required base-level python packages | RUN apk add --no-cache --virtual .build-deps \ | ||||||
| COPY ./docker/requirements.txt base_requirements.txt |     gcc g++ musl-dev openssl-dev libffi-dev cargo python3-dev \ | ||||||
| RUN pip install --disable-pip-version-check -U -r base_requirements.txt |     # 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: | # InvenTree production image: | ||||||
| # - Copies required files from local directory | # - Copies required files from local directory | ||||||
| # - Installs required python packages from requirements.txt |  | ||||||
| # - Starts a gunicorn webserver | # - Starts a gunicorn webserver | ||||||
|  |  | ||||||
| FROM inventree_base as production | FROM inventree_base as production | ||||||
|  |  | ||||||
| ENV INVENTREE_DEBUG=False | ENV INVENTREE_DEBUG=False | ||||||
| @@ -98,33 +110,14 @@ ENV INVENTREE_COMMIT_HASH="${commit_hash}" | |||||||
| ENV INVENTREE_COMMIT_DATE="${commit_date}" | ENV INVENTREE_COMMIT_DATE="${commit_date}" | ||||||
|  |  | ||||||
| # Copy source code | # Copy source code | ||||||
| COPY InvenTree ${INVENTREE_HOME}/InvenTree | COPY InvenTree ./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"] |  | ||||||
|  |  | ||||||
| # Launch the production server | # Launch the production server | ||||||
| # TODO: Work out why environment variables cannot be interpolated in this command | # TODO: Work out why environment variables cannot be interpolated in this command | ||||||
| # TODO: e.g. -b ${INVENTREE_WEB_ADDR}:${INVENTREE_WEB_PORT} fails here | # 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 | CMD gunicorn -c ./gunicorn.conf.py InvenTree.wsgi -b 0.0.0.0:8000 --chdir ./InvenTree | ||||||
|  |  | ||||||
|  |  | ||||||
| FROM inventree_base as dev | FROM inventree_base as dev | ||||||
|  |  | ||||||
| # 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/ | ||||||
| @@ -139,7 +132,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/bash", "./docker/init.sh"] | ENTRYPOINT ["/bin/ash", "./docker/init.sh"] | ||||||
|  |  | ||||||
| # Launch the development server | # Launch the development server | ||||||
| CMD ["invoke", "server", "-a", "${INVENTREE_WEB_ADDR}:${INVENTREE_WEB_PORT}"] | CMD ["invoke", "server", "-a", "${INVENTREE_WEB_ADDR}:${INVENTREE_WEB_PORT}"] | ||||||
|   | |||||||
| @@ -1,9 +1,11 @@ | |||||||
| #!/bin/bash | #!/bin/sh | ||||||
| # exit when any command fails | # exit when any command fails | ||||||
| set -e | set -e | ||||||
|  |  | ||||||
| # Required to suppress some git errors further down the line | # Required to suppress some git errors further down the line | ||||||
|  | if command -v git &> /dev/null; then | ||||||
|     git config --global --add safe.directory /home/*** |     git config --global --add safe.directory /home/*** | ||||||
|  | fi | ||||||
|  |  | ||||||
| # Create required directory structure (if it does not already exist) | # Create required directory structure (if it does not already exist) | ||||||
| if [[ ! -d "$INVENTREE_STATIC_ROOT" ]]; then | if [[ ! -d "$INVENTREE_STATIC_ROOT" ]]; then | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user