mirror of
https://github.com/invoke-ai/InvokeAI.git
synced 2025-01-08 11:57:36 +08:00
(docker) use 'uv' to manage python installation and the invoke dependencies, since Ubuntu 24.04 comes with Python 3.12 which we do not yet support
This commit is contained in:
parent
bd478360d9
commit
a636ac2899
@ -9,22 +9,35 @@ RUN rm -f /etc/apt/apt.conf.d/docker-clean; echo 'Binary::apt::APT::Keep-Downloa
|
|||||||
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
|
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
|
||||||
--mount=type=cache,target=/var/lib/apt,sharing=locked \
|
--mount=type=cache,target=/var/lib/apt,sharing=locked \
|
||||||
apt update && apt-get install -y \
|
apt update && apt-get install -y \
|
||||||
git \
|
build-essential \
|
||||||
python3-venv \
|
git
|
||||||
python3-pip \
|
|
||||||
build-essential
|
|
||||||
|
|
||||||
ENV INVOKEAI_SRC=/opt/invokeai
|
# Install `uv` for package management
|
||||||
ENV VIRTUAL_ENV=/opt/venv/invokeai
|
COPY --from=ghcr.io/astral-sh/uv:0.5.5 /uv /uvx /bin/
|
||||||
|
|
||||||
|
ENV VIRTUAL_ENV=/opt/venv
|
||||||
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
|
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
|
||||||
|
ENV INVOKEAI_SRC=/opt/invokeai
|
||||||
|
ENV PYTHON_VERSION=3.11
|
||||||
|
ENV UV_COMPILE_BYTECODE=1
|
||||||
|
ENV UV_LINK_MODE=copy
|
||||||
|
|
||||||
ARG GPU_DRIVER=cuda
|
ARG GPU_DRIVER=cuda
|
||||||
ARG TARGETPLATFORM="linux/amd64"
|
ARG TARGETPLATFORM="linux/amd64"
|
||||||
# unused but available
|
# unused but available
|
||||||
ARG BUILDPLATFORM
|
ARG BUILDPLATFORM
|
||||||
|
|
||||||
WORKDIR ${INVOKEAI_SRC}
|
# Switch to the `ubuntu` user to work around dependency issues with uv-installed python
|
||||||
|
RUN mkdir -p ${VIRTUAL_ENV} && \
|
||||||
|
mkdir -p ${INVOKEAI_SRC} && \
|
||||||
|
chmod -R a+w /opt
|
||||||
|
USER ubuntu
|
||||||
|
|
||||||
|
# Install python and create the venv
|
||||||
|
RUN uv python install ${PYTHON_VERSION} && \
|
||||||
|
uv venv --relocatable --prompt "invoke" --python ${PYTHON_VERSION} ${VIRTUAL_ENV}
|
||||||
|
|
||||||
|
WORKDIR ${INVOKEAI_SRC}
|
||||||
COPY invokeai ./invokeai
|
COPY invokeai ./invokeai
|
||||||
COPY pyproject.toml ./
|
COPY pyproject.toml ./
|
||||||
|
|
||||||
@ -32,9 +45,8 @@ COPY pyproject.toml ./
|
|||||||
# the local working copy can be bind-mounted into the image
|
# the local working copy can be bind-mounted into the image
|
||||||
# at path defined by ${INVOKEAI_SRC}
|
# at path defined by ${INVOKEAI_SRC}
|
||||||
# NOTE: there are no pytorch builds for arm64 + cuda, only cpu
|
# NOTE: there are no pytorch builds for arm64 + cuda, only cpu
|
||||||
# x86_64/CUDA is default
|
# x86_64/CUDA is the default
|
||||||
RUN --mount=type=cache,target=/root/.cache/pip \
|
RUN --mount=type=cache,target=/home/ubuntu/.cache/uv,uid=1000,gid=1000 \
|
||||||
python3 -m venv ${VIRTUAL_ENV} &&\
|
|
||||||
if [ "$TARGETPLATFORM" = "linux/arm64" ] || [ "$GPU_DRIVER" = "cpu" ]; then \
|
if [ "$TARGETPLATFORM" = "linux/arm64" ] || [ "$GPU_DRIVER" = "cpu" ]; then \
|
||||||
extra_index_url_arg="--extra-index-url https://download.pytorch.org/whl/cpu"; \
|
extra_index_url_arg="--extra-index-url https://download.pytorch.org/whl/cpu"; \
|
||||||
elif [ "$GPU_DRIVER" = "rocm" ]; then \
|
elif [ "$GPU_DRIVER" = "rocm" ]; then \
|
||||||
@ -42,15 +54,9 @@ RUN --mount=type=cache,target=/root/.cache/pip \
|
|||||||
else \
|
else \
|
||||||
extra_index_url_arg="--extra-index-url https://download.pytorch.org/whl/cu124"; \
|
extra_index_url_arg="--extra-index-url https://download.pytorch.org/whl/cu124"; \
|
||||||
fi && \
|
fi && \
|
||||||
\
|
uv pip install --python ${PYTHON_VERSION} $extra_index_url_arg -e "."
|
||||||
# xformers + triton fails to install on arm64 \
|
|
||||||
if [ "$GPU_DRIVER" = "cuda" ] && [ "$TARGETPLATFORM" = "linux/amd64" ]; then \
|
|
||||||
pip install $extra_index_url_arg -e ".[xformers]"; \
|
|
||||||
else \
|
|
||||||
pip install $extra_index_url_arg -e "."; \
|
|
||||||
fi
|
|
||||||
|
|
||||||
# #### Build the Web UI ------------------------------------
|
#### Build the Web UI ------------------------------------
|
||||||
|
|
||||||
FROM node:20-slim AS web-builder
|
FROM node:20-slim AS web-builder
|
||||||
ENV PNPM_HOME="/pnpm"
|
ENV PNPM_HOME="/pnpm"
|
||||||
@ -85,16 +91,14 @@ RUN apt update && apt install -y --no-install-recommends \
|
|||||||
libglib2.0-0 \
|
libglib2.0-0 \
|
||||||
libgl1 \
|
libgl1 \
|
||||||
libglx-mesa0 \
|
libglx-mesa0 \
|
||||||
python3-venv \
|
|
||||||
python3-pip \
|
|
||||||
build-essential \
|
build-essential \
|
||||||
libopencv-dev \
|
libopencv-dev \
|
||||||
libstdc++-10-dev &&\
|
libstdc++-10-dev &&\
|
||||||
apt-get clean && apt-get autoclean
|
apt-get clean && apt-get autoclean
|
||||||
|
|
||||||
|
|
||||||
ENV INVOKEAI_SRC=/opt/invokeai
|
ENV INVOKEAI_SRC=/opt/invokeai
|
||||||
ENV VIRTUAL_ENV=/opt/venv/invokeai
|
ENV VIRTUAL_ENV=/opt/venv
|
||||||
|
ENV PYTHON_VERSION=3.11
|
||||||
ENV INVOKEAI_ROOT=/invokeai
|
ENV INVOKEAI_ROOT=/invokeai
|
||||||
ENV INVOKEAI_HOST=0.0.0.0
|
ENV INVOKEAI_HOST=0.0.0.0
|
||||||
ENV INVOKEAI_PORT=9090
|
ENV INVOKEAI_PORT=9090
|
||||||
@ -102,6 +106,14 @@ ENV PATH="$VIRTUAL_ENV/bin:$INVOKEAI_SRC:$PATH"
|
|||||||
ENV CONTAINER_UID=${CONTAINER_UID:-1000}
|
ENV CONTAINER_UID=${CONTAINER_UID:-1000}
|
||||||
ENV CONTAINER_GID=${CONTAINER_GID:-1000}
|
ENV CONTAINER_GID=${CONTAINER_GID:-1000}
|
||||||
|
|
||||||
|
# Install `uv` for package management
|
||||||
|
# and install python for the ubuntu user (expected to exist on ubuntu >=24.x)
|
||||||
|
# this is too tiny to optimize with multi-stage builds, but maybe we'll come back to it
|
||||||
|
COPY --from=ghcr.io/astral-sh/uv:0.5.5 /uv /uvx /bin/
|
||||||
|
USER ubuntu
|
||||||
|
RUN uv python install ${PYTHON_VERSION}
|
||||||
|
USER root
|
||||||
|
|
||||||
# --link requires buldkit w/ dockerfile syntax 1.4
|
# --link requires buldkit w/ dockerfile syntax 1.4
|
||||||
COPY --link --from=builder ${INVOKEAI_SRC} ${INVOKEAI_SRC}
|
COPY --link --from=builder ${INVOKEAI_SRC} ${INVOKEAI_SRC}
|
||||||
COPY --link --from=builder ${VIRTUAL_ENV} ${VIRTUAL_ENV}
|
COPY --link --from=builder ${VIRTUAL_ENV} ${VIRTUAL_ENV}
|
||||||
@ -116,7 +128,7 @@ WORKDIR ${INVOKEAI_SRC}
|
|||||||
|
|
||||||
# build patchmatch
|
# build patchmatch
|
||||||
RUN cd /usr/lib/$(uname -p)-linux-gnu/pkgconfig/ && ln -sf opencv4.pc opencv.pc
|
RUN cd /usr/lib/$(uname -p)-linux-gnu/pkgconfig/ && ln -sf opencv4.pc opencv.pc
|
||||||
RUN python3 -c "from patchmatch import patch_match"
|
RUN python -c "from patchmatch import patch_match"
|
||||||
|
|
||||||
RUN mkdir -p ${INVOKEAI_ROOT} && chown -R ${CONTAINER_UID}:${CONTAINER_GID} ${INVOKEAI_ROOT}
|
RUN mkdir -p ${INVOKEAI_ROOT} && chown -R ${CONTAINER_UID}:${CONTAINER_GID} ${INVOKEAI_ROOT}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user