optimize Dockerfile (#2036)

* remove build-essentials after opencv is built
also remo unecesarry python3-opencv dependencie (its already in venv)

* use branch name as tag

* leave pip and setuptools on the preinstalled vers.

* Rename Argument from WORKDIR to APPDIR

Co-authored-by: Lincoln Stein <lincoln.stein@gmail.com>
This commit is contained in:
Matthias Wild 2022-12-19 23:53:19 +01:00 committed by GitHub
parent f69fc68e06
commit 1ba40db361
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 22 deletions

View File

@ -15,9 +15,9 @@ RUN apt-get update \
&& rm -rf /var/lib/apt/lists/*
# set WORKDIR, PATH and copy sources
ARG WORKDIR=/usr/src/app
WORKDIR ${WORKDIR}
ENV PATH ${WORKDIR}/.venv/bin:$PATH
ARG APPDIR=/usr/src/app
WORKDIR ${APPDIR}
ENV PATH ${APPDIR}/.venv/bin:$PATH
ARG PIP_REQUIREMENTS=requirements-lin-cuda.txt
COPY . ./environments-and-requirements/${PIP_REQUIREMENTS} ./
@ -26,8 +26,6 @@ RUN python3 -m venv .venv \
&& pip install \
--upgrade \
--no-cache-dir \
'pip>=22.3.1' \
'setuptools>=65.5.0' \
'wheel>=0.38.4' \
&& pip install \
--no-cache-dir \
@ -35,6 +33,15 @@ RUN python3 -m venv .venv \
FROM python:3.10-slim AS runtime
# setup environment
ARG APPDIR=/usr/src/app
WORKDIR ${APPDIR}
COPY --from=builder ${APPDIR} .
ENV \
PATH=${APPDIR}/.venv/bin:$PATH \
INVOKEAI_ROOT=/data \
INVOKE_MODEL_RECONFIGURE=--yes
# Install necesarry packages
RUN apt-get update \
&& apt-get install -y \
@ -43,24 +50,16 @@ RUN apt-get update \
libgl1-mesa-glx=20.3.* \
libglib2.0-0=2.66.* \
libopencv-dev=4.5.* \
python3-opencv=4.5.* \
&& apt-get clean \
&& ln -sf \
/usr/lib/"$(arch)"-linux-gnu/pkgconfig/opencv4.pc \
/usr/lib/"$(arch)"-linux-gnu/pkgconfig/opencv.pc \
&& python3 -c "from patchmatch import patch_match" \
&& apt-get remove -y \
--autoremove \
build-essential \
&& apt-get autoclean \
&& rm -rf /var/lib/apt/lists/*
# setup environment
ARG WORKDIR=/usr/src/app
WORKDIR ${WORKDIR}
COPY --from=builder ${WORKDIR} .
ENV PATH=${WORKDIR}/.venv/bin:$PATH
ENV INVOKEAI_ROOT /data
ENV INVOKE_MODEL_RECONFIGURE --yes
# Initialize patchmatch
RUN ln -sf \
/usr/lib/"$(arch)"-linux-gnu/pkgconfig/opencv4.pc \
/usr/lib/"$(arch)"-linux-gnu/pkgconfig/opencv.pc \
&& python3 -c "from patchmatch import patch_match"
# set Entrypoint and default CMD
ENTRYPOINT [ "python3", "scripts/invoke.py" ]
CMD [ "--web", "--host=0.0.0.0" ]

View File

@ -6,4 +6,5 @@ VOLUMENAME=${VOLUMENAME:-${REPOSITORY_NAME,,}_data}
ARCH=${ARCH:-$(arch)}
PLATFORM=${PLATFORM:-Linux/${ARCH}}
CONTAINER_FLAVOR=${CONTAINER_FLAVOR:-cuda}
INVOKEAI_TAG=${REPOSITORY_NAME,,}-${CONTAINER_FLAVOR}:${INVOKEAI_TAG:-latest}
INVOKEAI_BRANCH=$(git branch --show)
INVOKEAI_TAG=${REPOSITORY_NAME,,}-${CONTAINER_FLAVOR}:${INVOKEAI_TAG:-${INVOKEAI_BRANCH/\//-}}