mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
ad7917c7aa
* add docker build optimized for size; do not copy models to image useful for cloud deployments. attempts to utilize docker layer caching as effectively as possible. also some quick tools to help with building * add workflow to build cloud img in ci * push cloud image in addition to building * (ci) also tag docker images with git SHA * (docker) rework Makefile for easy cache population and local use * support the new conda-less install; further optimize docker build * (ci) clean up the build-cloud-img action * improve the Makefile for local use * move execution of invoke script from entrypoint to cmd, allows overriding the cmd if needed (e.g. in Runpod * remove unnecessary copyright statements * (docs) add a section on running InvokeAI in the cloud using Docker * (docker) add patchmatch to the cloud image; improve build caching; simplify Makefile * (docker) fix pip requirements path to use binary_installer directory
87 lines
2.4 KiB
Docker
87 lines
2.4 KiB
Docker
#######################
|
|
#### Builder stage ####
|
|
|
|
FROM library/ubuntu:22.04 AS builder
|
|
|
|
ARG DEBIAN_FRONTEND=noninteractive
|
|
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
|
|
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
|
|
--mount=type=cache,target=/var/lib/apt,sharing=locked \
|
|
apt update && apt-get install -y \
|
|
git \
|
|
libglib2.0-0 \
|
|
libgl1-mesa-glx \
|
|
python3-venv \
|
|
python3-pip \
|
|
build-essential \
|
|
python3-opencv \
|
|
libopencv-dev
|
|
|
|
# This is needed for patchmatch support
|
|
RUN cd /usr/lib/x86_64-linux-gnu/pkgconfig/ &&\
|
|
ln -sf opencv4.pc opencv.pc
|
|
|
|
ARG WORKDIR=/invokeai
|
|
WORKDIR ${WORKDIR}
|
|
|
|
ENV VIRTUAL_ENV=${WORKDIR}/.venv
|
|
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
|
|
|
|
RUN --mount=type=cache,target=/root/.cache/pip \
|
|
python3 -m venv ${VIRTUAL_ENV} &&\
|
|
pip install --extra-index-url https://download.pytorch.org/whl/cu116 \
|
|
torch==1.12.0+cu116 \
|
|
torchvision==0.13.0+cu116 &&\
|
|
pip install -e git+https://github.com/invoke-ai/PyPatchMatch@0.1.3#egg=pypatchmatch
|
|
|
|
COPY . .
|
|
RUN --mount=type=cache,target=/root/.cache/pip \
|
|
cp binary_installer/py3.10-linux-x86_64-cuda-reqs.txt requirements.txt && \
|
|
pip install -r requirements.txt &&\
|
|
pip install -e .
|
|
|
|
|
|
#######################
|
|
#### Runtime stage ####
|
|
|
|
FROM library/ubuntu:22.04 as runtime
|
|
|
|
ARG DEBIAN_FRONTEND=noninteractive
|
|
ENV PYTHONUNBUFFERED=1
|
|
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
|
|
--mount=type=cache,target=/var/lib/apt,sharing=locked \
|
|
apt update && apt install -y --no-install-recommends \
|
|
git \
|
|
curl \
|
|
ncdu \
|
|
iotop \
|
|
bzip2 \
|
|
libglib2.0-0 \
|
|
libgl1-mesa-glx \
|
|
python3-venv \
|
|
python3-pip \
|
|
build-essential \
|
|
python3-opencv \
|
|
libopencv-dev &&\
|
|
apt-get clean && apt-get autoclean
|
|
|
|
ARG WORKDIR=/invokeai
|
|
WORKDIR ${WORKDIR}
|
|
|
|
ENV INVOKEAI_ROOT=/mnt/invokeai
|
|
ENV VIRTUAL_ENV=${WORKDIR}/.venv
|
|
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
|
|
|
|
COPY --from=builder ${WORKDIR} ${WORKDIR}
|
|
COPY --from=builder /usr/lib/x86_64-linux-gnu/pkgconfig /usr/lib/x86_64-linux-gnu/pkgconfig
|
|
|
|
# build patchmatch
|
|
RUN python -c "from patchmatch import patch_match"
|
|
|
|
## workaround for non-existent initfile when runtime directory is mounted; see #1613
|
|
RUN touch /root/.invokeai
|
|
|
|
ENTRYPOINT ["bash"]
|
|
|
|
CMD ["-c", "python3 scripts/invoke.py --web --host 0.0.0.0"]
|