From 90cda118688eeec86ba1ad927e0a230b431c5e3b Mon Sep 17 00:00:00 2001 From: mauwii Date: Fri, 24 Feb 2023 03:51:18 +0100 Subject: [PATCH] separate installation of requirements and source this should highly increase rebuilding of the image when: - version did not change - requirements didn't change --- docker/Dockerfile | 45 +++++++++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 230c7e584e..629d252d0b 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -8,11 +8,11 @@ FROM python:${PYTHON_VERSION}-slim AS python-base LABEL org.opencontainers.image.authors="mauwii@outlook.de" -# prepare for buildkit cache +# Prepare apt for buildkit cache RUN rm -f /etc/apt/apt.conf.d/docker-clean \ && echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' >/etc/apt/apt.conf.d/keep-cache -# Install necessary packages +# Install dependencies RUN \ --mount=type=cache,target=/var/cache/apt,sharing=locked \ --mount=type=cache,target=/var/lib/apt,sharing=locked \ @@ -23,7 +23,7 @@ RUN \ libglib2.0-0=2.66.* \ libopencv-dev=4.5.* -# set working directory and env +# Set working directory and env ARG APPDIR=/usr/src ARG APPNAME=InvokeAI WORKDIR ${APPDIR} @@ -32,7 +32,7 @@ ENV PATH ${APPDIR}/${APPNAME}/bin:$PATH ENV PYTHONDONTWRITEBYTECODE 1 # Turns off buffering for easier container logging ENV PYTHONUNBUFFERED 1 -# don't fall back to legacy build system +# Don't fall back to legacy build system ENV PIP_USE_PEP517=1 ####################### @@ -40,7 +40,7 @@ ENV PIP_USE_PEP517=1 ####################### FROM python-base AS pyproject-builder -# Install dependencies +# Install build dependencies RUN \ --mount=type=cache,target=/var/cache/apt,sharing=locked \ --mount=type=cache,target=/var/lib/apt,sharing=locked \ @@ -51,26 +51,39 @@ RUN \ gcc=4:10.2.* \ python3-dev=3.9.* -# prepare pip for buildkit cache +# Install pip-tools +RUN pip install \ + --no-cache-dir \ + pip-tools==6.12.2 + +# Prepare pip for buildkit cache ARG PIP_CACHE_DIR=/var/cache/buildkit/pip ENV PIP_CACHE_DIR ${PIP_CACHE_DIR} RUN mkdir -p ${PIP_CACHE_DIR} -# create virtual environment -RUN --mount=type=cache,target=${PIP_CACHE_DIR},sharing=locked \ +# Create virtual environment +RUN --mount=type=cache,target=${PIP_CACHE_DIR} \ python3 -m venv "${APPNAME}" \ --upgrade-deps -# copy sources -COPY --link . . - -# install pyproject.toml +# Install requirements +COPY --link pyproject.toml . +COPY --link ldm/invoke/_version.py ldm/invoke/__init__.py ldm/invoke/ ARG PIP_EXTRA_INDEX_URL ENV PIP_EXTRA_INDEX_URL ${PIP_EXTRA_INDEX_URL} -RUN --mount=type=cache,target=${PIP_CACHE_DIR},sharing=locked \ +RUN --mount=type=cache,target=${PIP_CACHE_DIR} \ + pip-compile \ + --resolver=backtracking \ + --output-file=requirements.txt \ + pyproject.toml && "${APPNAME}"/bin/pip install \ + -r requirements.txt + +# Install pyproject.toml +COPY --link . . +RUN --mount=type=cache,target=${PIP_CACHE_DIR} \ "${APPNAME}/bin/pip" install . -# build patchmatch +# Build patchmatch RUN python3 -c "from patchmatch import patch_match" ##################### @@ -86,12 +99,12 @@ RUN useradd \ -U \ "${UNAME}" -# create volume directory +# Create volume directory ARG VOLUME_DIR=/data RUN mkdir -p "${VOLUME_DIR}" \ && chown -R "${UNAME}" "${VOLUME_DIR}" -# setup runtime environment +# Setup runtime environment USER ${UNAME} COPY --chown=${UNAME} --from=pyproject-builder ${APPDIR}/${APPNAME} ${APPNAME} ENV INVOKEAI_ROOT ${VOLUME_DIR}