mirror of
https://github.com/invoke-ai/InvokeAI.git
synced 2026-10-12 11:10:03 +00:00
119 lines
4.3 KiB
Docker
119 lines
4.3 KiB
Docker
# syntax=docker/dockerfile:1.4
|
|
|
|
#### Web UI ------------------------------------
|
|
|
|
FROM docker.io/node:22-slim AS web-builder
|
|
ENV PNPM_HOME="/pnpm"
|
|
ENV PATH="$PNPM_HOME:$PATH"
|
|
RUN corepack use [email protected] && corepack enable
|
|
|
|
# Mirror the repository layout: the webv2 build reads the release version from invokeai/version.
|
|
WORKDIR /build/invokeai/frontend/webv2
|
|
COPY invokeai/frontend/webv2/ ./
|
|
RUN --mount=type=cache,target=/pnpm/store \
|
|
pnpm install --frozen-lockfile
|
|
COPY invokeai/version/invokeai_version.py /build/invokeai/version/
|
|
RUN pnpm exec vite build
|
|
|
|
FROM web-builder AS legacy-web-builder
|
|
WORKDIR /legacy-build
|
|
COPY invokeai/frontend/webv1/ ./
|
|
RUN --mount=type=cache,target=/pnpm/store \
|
|
pnpm install --frozen-lockfile
|
|
RUN pnpm exec vite build
|
|
|
|
## Backend ---------------------------------------
|
|
|
|
FROM library/ubuntu:24.04
|
|
|
|
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 \
|
|
--mount=type=cache,target=/var/lib/apt \
|
|
apt update && apt install -y --no-install-recommends \
|
|
ca-certificates \
|
|
git \
|
|
gosu \
|
|
libglib2.0-0 \
|
|
libgl1 \
|
|
libglx-mesa0 \
|
|
build-essential \
|
|
libopencv-dev \
|
|
libstdc++-10-dev
|
|
|
|
ENV \
|
|
PYTHONUNBUFFERED=1 \
|
|
PYTHONDONTWRITEBYTECODE=1 \
|
|
VIRTUAL_ENV=/opt/venv \
|
|
INVOKEAI_SRC=/opt/invokeai \
|
|
PYTHON_VERSION=3.12 \
|
|
UV_PYTHON=3.12 \
|
|
UV_COMPILE_BYTECODE=1 \
|
|
UV_MANAGED_PYTHON=1 \
|
|
UV_LINK_MODE=copy \
|
|
UV_PROJECT_ENVIRONMENT=/opt/venv \
|
|
INVOKEAI_ROOT=/invokeai \
|
|
INVOKEAI_HOST=0.0.0.0 \
|
|
INVOKEAI_PORT=9090 \
|
|
PATH="/opt/venv/bin:$PATH" \
|
|
CONTAINER_UID=${CONTAINER_UID:-1000} \
|
|
CONTAINER_GID=${CONTAINER_GID:-1000}
|
|
|
|
ARG GPU_DRIVER=cuda
|
|
|
|
# Install `uv` for package management
|
|
COPY --from=ghcr.io/astral-sh/uv:0.11.28 /uv /uvx /bin/
|
|
|
|
# Install python & allow non-root user to use it by traversing the /root dir without read permissions
|
|
RUN --mount=type=cache,target=/root/.cache/uv \
|
|
uv python install ${PYTHON_VERSION} && \
|
|
# chmod --recursive a+rX /root/.local/share/uv/python
|
|
chmod 711 /root
|
|
|
|
WORKDIR ${INVOKEAI_SRC}
|
|
|
|
# Install project's dependencies as a separate layer so they aren't rebuilt every commit.
|
|
# bind-mount instead of copy to defer adding sources to the image until next layer.
|
|
#
|
|
# NOTE: on arm64 (aarch64), torch/torchvision resolve to the PyPI CPU wheels (2.7.1) regardless of
|
|
# GPU_DRIVER -- the pinned WHL-index pairs only apply on x86_64 (see pyproject.toml). Use GPU_DRIVER=cpu on arm64.
|
|
# x86_64/CUDA is the default
|
|
RUN --mount=type=cache,target=/root/.cache/uv \
|
|
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
|
|
--mount=type=bind,source=uv.lock,target=uv.lock \
|
|
# this is just to get the package manager to recognize that the project exists, without making changes to the docker layer
|
|
--mount=type=bind,source=invokeai/version,target=invokeai/version \
|
|
ulimit -n 30000 && \
|
|
uv sync --extra $GPU_DRIVER --extra mysql --frozen
|
|
|
|
# Link amdgpu.ids for ROCm builds
|
|
# contributed by https://github.com/Rubonnek
|
|
RUN mkdir -p "/opt/amdgpu/share/libdrm" &&\
|
|
ln -s "/usr/share/libdrm/amdgpu.ids" "/opt/amdgpu/share/libdrm/amdgpu.ids" && groupadd render
|
|
|
|
# build patchmatch
|
|
RUN cd /usr/lib/$(uname -p)-linux-gnu/pkgconfig/ && ln -sf opencv4.pc opencv.pc
|
|
RUN python -c "from patchmatch import patch_match"
|
|
|
|
RUN mkdir -p ${INVOKEAI_ROOT} && chown -R ${CONTAINER_UID}:${CONTAINER_GID} ${INVOKEAI_ROOT}
|
|
|
|
COPY docker/docker-entrypoint.sh ./
|
|
ENTRYPOINT ["/opt/invokeai/docker-entrypoint.sh"]
|
|
CMD ["invokeai-web"]
|
|
|
|
# --link requires buldkit w/ dockerfile syntax 1.4, does not work with podman
|
|
COPY --link --from=web-builder /build/invokeai/frontend/webv2/dist ${INVOKEAI_SRC}/invokeai/frontend/webv2/dist
|
|
COPY --link --from=legacy-web-builder /legacy-build/dist ${INVOKEAI_SRC}/invokeai/frontend/webv1/dist
|
|
|
|
# add sources last to minimize image changes on code changes
|
|
COPY invokeai ${INVOKEAI_SRC}/invokeai
|
|
|
|
# this should not increase image size because we've already installed dependencies
|
|
# in a previous layer
|
|
RUN --mount=type=cache,target=/root/.cache/uv \
|
|
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
|
|
--mount=type=bind,source=uv.lock,target=uv.lock \
|
|
ulimit -n 30000 && \
|
|
uv pip install -e .[$GPU_DRIVER,mysql]
|
|
|