Skip to content

Commit 2ba9480

Browse files
committed
(docker) add patchmatch to the cloud image; improve build caching; simplify Makefile
1 parent 79bf79e commit 2ba9480

File tree

3 files changed

+68
-51
lines changed

3 files changed

+68
-51
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
!static
1010
!setup.py
1111
!docker-build
12+
!docs
1213
docker-build/Dockerfile
1314

1415
# Guard against pulling in any models that might exist in the directory tree

docker-build/Dockerfile.cloud

Lines changed: 60 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,85 @@
1+
#######################
12
#### Builder stage ####
23

34
FROM library/ubuntu:22.04 AS builder
45

5-
ENV DEBIAN_FRONTEND=noninteractive
6-
ENV PYTHONDONTWRITEBYTECODE=1
7-
# unbuffered output, ensures stdout and stderr are printed in the correct order
8-
ENV PYTHONUNBUFFERED=1
9-
10-
RUN --mount=type=cache,target=/var/cache/apt \
11-
apt update && apt install -y \
12-
libglib2.0-0 \
13-
libgl1-mesa-glx \
14-
python3-venv \
15-
python3-pip
6+
ARG DEBIAN_FRONTEND=noninteractive
7+
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
8+
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
9+
--mount=type=cache,target=/var/lib/apt,sharing=locked \
10+
apt update && apt-get install -y \
11+
git \
12+
libglib2.0-0 \
13+
libgl1-mesa-glx \
14+
python3-venv \
15+
python3-pip \
16+
build-essential \
17+
python3-opencv \
18+
libopencv-dev
1619

20+
# This is needed for patchmatch support
21+
RUN cd /usr/lib/x86_64-linux-gnu/pkgconfig/ &&\
22+
ln -sf opencv4.pc opencv.pc
1723

18-
ARG APP_ROOT=/invokeai
19-
WORKDIR ${APP_ROOT}
24+
ARG WORKDIR=/invokeai
25+
WORKDIR ${WORKDIR}
2026

21-
ENV VIRTUAL_ENV=${APP_ROOT}/.venv
27+
ENV VIRTUAL_ENV=${WORKDIR}/.venv
2228
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
2329

24-
COPY . .
2530
RUN --mount=type=cache,target=/root/.cache/pip \
26-
cp installer/py3.10-linux-x86_64-cuda-reqs.txt requirements.txt && \
2731
python3 -m venv ${VIRTUAL_ENV} &&\
2832
pip install --extra-index-url https://download.pytorch.org/whl/cu116 \
2933
torch==1.12.0+cu116 \
3034
torchvision==0.13.0+cu116 &&\
35+
pip install -e git+https://github.com/invoke-ai/PyPatchMatch@0.1.3#egg=pypatchmatch
36+
37+
COPY . .
38+
RUN --mount=type=cache,target=/root/.cache/pip \
39+
cp installer/py3.10-linux-x86_64-cuda-reqs.txt requirements.txt && \
3140
pip install -r requirements.txt &&\
3241
pip install -e .
3342

3443

44+
#######################
3545
#### Runtime stage ####
3646

37-
FROM ubuntu:22.04 as runtime
38-
RUN apt update && apt install -y \
39-
git \
40-
curl \
41-
ncdu \
42-
iotop \
43-
bzip2 \
44-
libglib2.0-0 \
45-
libgl1-mesa-glx \
46-
python3-venv \
47-
python3-pip \
48-
&& apt-get clean
49-
50-
ARG APP_ROOT=/invokeai
51-
WORKDIR ${APP_ROOT}
52-
53-
ENV VIRTUAL_ENV=${APP_ROOT}/.venv
47+
FROM library/ubuntu:22.04 as runtime
48+
49+
ARG DEBIAN_FRONTEND=noninteractive
50+
ENV PYTHONUNBUFFERED=1
51+
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
52+
--mount=type=cache,target=/var/lib/apt,sharing=locked \
53+
apt update && apt install -y --no-install-recommends \
54+
git \
55+
curl \
56+
ncdu \
57+
iotop \
58+
bzip2 \
59+
libglib2.0-0 \
60+
libgl1-mesa-glx \
61+
python3-venv \
62+
python3-pip \
63+
build-essential \
64+
python3-opencv \
65+
libopencv-dev &&\
66+
apt-get clean && apt-get autoclean
67+
68+
ARG WORKDIR=/invokeai
69+
WORKDIR ${WORKDIR}
70+
71+
ENV INVOKEAI_ROOT=/mnt/invokeai
72+
ENV VIRTUAL_ENV=${WORKDIR}/.venv
5473
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
5574

56-
COPY --from=builder ${APP_ROOT} ${APP_ROOT}
75+
COPY --from=builder ${WORKDIR} ${WORKDIR}
76+
COPY --from=builder /usr/lib/x86_64-linux-gnu/pkgconfig /usr/lib/x86_64-linux-gnu/pkgconfig
77+
78+
# build patchmatch
79+
RUN python -c "from patchmatch import patch_match"
80+
81+
## workaround for non-existent initfile when runtime directory is mounted; see #1613
82+
RUN touch /root/.invokeai
5783

5884
ENTRYPOINT ["bash"]
5985

docker-build/Makefile

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ INVOKEAI_ROOT=/mnt/invokeai
33
# Host directory to contain the runtime dir. Will be mounted at INVOKEAI_ROOT path in the container
44
HOST_MOUNT_PATH=${HOME}/invokeai
55

6-
DOCKER_BUILDKIT=1
76
IMAGE=local/invokeai:latest
87

98
USER=$(shell id -u)
@@ -14,41 +13,32 @@ GROUP=$(shell id -g)
1413
# Contents can be moved to a persistent storage and used to prime the cache on another host.
1514

1615
build:
17-
docker build -t local/invokeai:latest -f Dockerfile.cloud ..
16+
DOCKER_BUILDKIT=1 docker build -t local/invokeai:latest -f Dockerfile.cloud ..
1817

1918
configure:
2019
docker run --rm -it --runtime=nvidia --gpus=all \
2120
-v ${HOST_MOUNT_PATH}:${INVOKEAI_ROOT} \
22-
-v ${HOST_MOUNT_PATH}/.cache:/root/.cache \
2321
-e INVOKEAI_ROOT=${INVOKEAI_ROOT} \
24-
--entrypoint bash \
25-
${IMAGE} -c "scripts/configure_invokeai.py"
26-
sudo chown -R ${USER}:${GROUP} ${HOST_MOUNT_PATH}
22+
${IMAGE} -c "python scripts/configure_invokeai.py"
2723

2824
# Run the container with the runtime dir mounted and the web server exposed on port 9090
2925
web:
3026
docker run --rm -it --runtime=nvidia --gpus=all \
3127
-v ${HOST_MOUNT_PATH}:${INVOKEAI_ROOT} \
32-
-v ${HOST_MOUNT_PATH}/.cache:/root/.cache \
3328
-e INVOKEAI_ROOT=${INVOKEAI_ROOT} \
34-
--entrypoint bash -p9090:9090 ${IMAGE} \
35-
-c "scripts/invoke.py --web --host 0.0.0.0 --root ${INVOKEAI_ROOT}"
29+
-p 9090:9090 \
30+
${IMAGE} -c "python scripts/invoke.py --web --host 0.0.0.0"
3631

3732
# Run the cli with the runtime dir mounted
3833
cli:
3934
docker run --rm -it --runtime=nvidia --gpus=all \
4035
-v ${HOST_MOUNT_PATH}:${INVOKEAI_ROOT} \
41-
-v ${HOST_MOUNT_PATH}/.cache:/root/.cache \
4236
-e INVOKEAI_ROOT=${INVOKEAI_ROOT} \
43-
--entrypoint bash ${IMAGE} \
44-
-c "scripts/invoke.py --root ${INVOKEAI_ROOT}"
37+
${IMAGE} -c "python scripts/invoke.py"
4538

46-
# Run the container with the cache mounted and open a bash shell instead of the Invoke CLI or webserver
39+
# Run the container with the runtime dir mounted and open a bash shell
4740
shell:
4841
docker run --rm -it --runtime=nvidia --gpus=all \
49-
-v ${HOST_MOUNT_PATH}:${INVOKEAI_ROOT} \
50-
-v ${HOST_MOUNT_PATH}/.cache:/root/.cache \
51-
-e INVOKEAI_ROOT=${INVOKEAI_ROOT} \
52-
--entrypoint bash ${IMAGE} --
42+
-v ${HOST_MOUNT_PATH}:${INVOKEAI_ROOT} ${IMAGE} --
5343

5444
.PHONY: build configure web cli shell

0 commit comments

Comments
 (0)