Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(comfy-ui): create developing image #79

Merged
merged 6 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions ComfyUI/DEV.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
## Building developing image

```sh
docker buildx build -f Dockerfile.local-cpu -t comfyui .
```

## Running the container

```sh
docker run \
--name comfyui \
--publish 8188:8188 \
# optionally to run in background
--detach \
--restart unless-stopped \
comfyui
```

86 changes: 86 additions & 0 deletions ComfyUI/Dockerfile.local-cpu
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# syntax = docker/dockerfile:1.4.0
# Use a Python image with uv pre-installed
FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim

# The installer requires curl (and certificates) to download the release archive
RUN --mount=type=cache,target=/var/cache/apt,rw --mount=type=cache,target=/var/lib/apt,rw \
apt-get update && apt-get install -y --no-install-recommends \
git \
git-lfs \
build-essential \
libgl1-mesa-glx \
wget \
curl \
unzip \
ffmpeg

# Enable bytecode compilation
ENV UV_COMPILE_BYTECODE=1 UV_LINK_MODE=copy

# Set environment variables
ARG COMFYUI_VERSION=v0.3.10
ARG COMFYUI_MANAGER_VERSION=3.6.5
ENV PYTHONUNBUFFERED=1 \
COMFYUI_REPO=https://github.com/comfyanonymous/ComfyUI.git \
COMFYUI_MANAGER_REPO=https://github.com/ltdrdata/ComfyUI-Manager.git \
COMFYUI_DIR=/opt/ComfyUI

# Clones the ComfyUI repository and checks out the latest release
# Clone the ComfyUI repository
RUN git clone --branch $COMFYUI_VERSION --single-branch $COMFYUI_REPO $COMFYUI_DIR

# Change into ComfyUI directory
WORKDIR $COMFYUI_DIR

RUN git config --local user.email "[email protected]" \
&& git config --global user.name "Container Builder"

# Create Python virtual environment
RUN --mount=type=cache,target=/root/.cache/uv \
uv venv --seed --relocatable .venv
ENV VIRTUAL_ENV=$COMFYUI_DIR/.venv
ENV PATH="$VIRTUAL_ENV/bin:$PATH"

# Install PyTorch and its dependencies
# see https://docs.astral.sh/uv/guides/integration/pytorch/#the-uv-pip-interface
RUN --mount=type=cache,target=/root/.cache/uv \
uv pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to install these libraries separately? Isn't the requirements.txt file in the ComfyUI root directory sufficient?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

requirements.txt is not enough in case of GPU optimized versions pytorch as it ships different builds using different indexes.

See https://docs.astral.sh/uv/guides/integration/pytorch/


# Install the required Python packages for ComfyUI
RUN --mount=type=cache,target=/root/.cache/uv \
uv pip install -r requirements.txt
Comment on lines +49 to +50
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Verify package integrity during installation.

Add hash verification for better security:

 RUN --mount=type=cache,target=/root/.cache/uv \
-    uv pip install -r requirements.txt
+    uv pip install -r requirements.txt --require-hashes

Generate requirements with hashes using:

uv pip freeze --all --require-hashes > requirements.txt


# Clones the ComfyUI Manager repository and checks out the latest release
# remove gitignore to allow adding submodule into custom_nodes
RUN rm .gitignore
tinovyatkin marked this conversation as resolved.
Show resolved Hide resolved
RUN git submodule add $COMFYUI_MANAGER_REPO custom_nodes/ComfyUI-Manager \
&& cd custom_nodes/ComfyUI-Manager \
&& git checkout tags/$COMFYUI_MANAGER_VERSION
RUN --mount=type=cache,target=/root/.cache/uv \
uv pip install -r custom_nodes/ComfyUI-Manager/requirements.txt

# Creating ComfyUI Manager config file
RUN mkdir -p user/default/ComfyUI-Manager
RUN <<EOF cat >> user/default/ComfyUI-Manager/config.ini
[default]
preview_method = auto
file_logging = False
security_level = weak
skip_migration_check = True
model_download_by_agent = False
EOF
marchuk-vlad marked this conversation as resolved.
Show resolved Hide resolved
tinovyatkin marked this conversation as resolved.
Show resolved Hide resolved

# commit current state so we can trace changes
RUN git add . && git commit -m "chore: initial setup"

# Expose the port the ComfyUI runs on
EXPOSE 8188

# Add a healthcheck to ensure the service is running
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8188/ || exit 1

# On startup, ComfyUI is started at its default port; the IP address is changed from localhost to 0.0.0.0, because Docker is only forwarding traffic
# to the IP address it assigns to the container, which is unknown at build time; listening to 0.0.0.0 means that ComfyUI listens to all incoming
# traffic; the auto-launch feature is disabled, because we do not want (nor is it possible) to open a browser window in a Docker container
CMD [".venv/bin/python", "main.py", "--listen", "0.0.0.0", "--port", "8188", "--disable-auto-launch", "--cpu", "--cpu-vae"]
Loading