Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
22 changes: 0 additions & 22 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,28 +83,6 @@ jobs:
cache-from: type=registry,ref=livepeer/comfyui-base:build-cache
cache-to: type=registry,mode=max,ref=livepeer/comfyui-base:build-cache

trigger:
name: Trigger ai-runner workflow
needs: base
if: ${{ github.repository == 'livepeer/comfystream' }}
runs-on: ubuntu-latest
steps:
- name: Send workflow dispatch event to ai-runner
uses: actions/github-script@v7
with:
github-token: ${{ secrets.CI_GITHUB_TOKEN }}
script: |
await github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: "ai-runner",
workflow_id: "comfyui-trigger.yaml",
ref: "main",
inputs: {
"comfyui-base-digest": "${{ needs.base.outputs.image-digest }}",
"triggering-branch": "${{ github.head_ref || github.ref_name }}",
},
});

comfystream:
name: comfystream image
needs: base
Expand Down
36 changes: 33 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,40 @@
"--media-ports=5678",
"--host=0.0.0.0",
"--port=8889",
"--log-level=DEBUG",
"--log-level=INFO",
"--comfyui-inference-log-level=DEBUG",
],
"python": "/workspace/miniconda3/envs/comfystream/bin/python",
"justMyCode": true
"justMyCode": true,
"python": "${command:python.interpreterPath}"
},
{
"name": "Run ComfyStream BYOC",
"type": "debugpy",
"request": "launch",
"cwd": "/workspace/ComfyUI",
"program": "/workspace/comfystream/server/byoc.py",
"console": "integratedTerminal",
"args": [
"--workspace=/workspace/ComfyUI",
"--host=0.0.0.0",
"--port=8000",
"--log-level=INFO",
"--comfyui-inference-log-level=DEBUG",
"--width=512",
"--height=512"
],
"env": {
"ORCH_URL": "https://172.17.0.1:9995",
"ORCH_SECRET": "orch-secret",
"CAPABILITY_NAME": "comfystream-byoc-processor",
"CAPABILITY_DESCRIPTION": "ComfyUI streaming processor for BYOC mode",
"CAPABILITY_URL": "http://172.17.0.1:8000",
"CAPABILITY_PRICE_PER_UNIT": "0",
"CAPABILITY_PRICE_SCALING": "1",
"CAPABILITY_CAPACITY": "1"
},
"justMyCode": true,
"python": "${command:python.interpreterPath}"
},
{
"name": "Run ComfyStream UI (Node.js)",
Expand Down
10 changes: 8 additions & 2 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@ ARG BASE_IMAGE=livepeer/comfyui-base:latest

FROM ${BASE_IMAGE}

ENV PATH="/workspace/miniconda3/bin:${PATH}" \
# Ensure Bash is the default shell (inherited from base)
SHELL ["/bin/bash", "-c"]

ENV PATH="/workspace/.venv/bin:/root/.local/bin:${PATH}" \
NVM_DIR=/root/.nvm \
NODE_VERSION=18.18.0
NODE_VERSION=18.18.0 \
VIRTUAL_ENV="/workspace/.venv" \
PYTHONPATH="/workspace/.venv/lib/python3.12/site-packages" \
SHELL="/bin/bash"

RUN echo "Using base image: ${BASE_IMAGE}" && \
apt update && \
Expand Down
79 changes: 46 additions & 33 deletions docker/Dockerfile.base
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
ARG BASE_IMAGE=nvidia/cuda:12.8.1-cudnn-devel-ubuntu22.04 \
CONDA_VERSION=latest \
PYTHON_VERSION=3.12

FROM "${BASE_IMAGE}"

ARG CONDA_VERSION \
PYTHON_VERSION
ARG PYTHON_VERSION

# Set Bash as the default shell
SHELL ["/bin/bash", "-c"]

ENV DEBIAN_FRONTEND=noninteractive \
CONDA_VERSION="${CONDA_VERSION}" \
PATH="/workspace/miniconda3/bin:${PATH}" \
PYTHON_VERSION="${PYTHON_VERSION}"
PATH="/workspace/.venv/bin:/root/.local/bin:/usr/local/bin:${PATH}" \
PYTHON_VERSION="${PYTHON_VERSION}" \
VIRTUAL_ENV="/workspace/.venv" \
PYTHONPATH="/workspace/.venv/lib/python3.12/site-packages" \
SHELL="/bin/bash"

# System dependencies
RUN apt update && apt install -yqq --no-install-recommends \
git \
wget \
curl \
nano \
socat \
libsndfile1 \
Expand All @@ -27,6 +31,11 @@ RUN apt update && apt install -yqq --no-install-recommends \
swig \
libprotobuf-dev \
protobuf-compiler \
ffmpeg \
python3 \
python3-pip \
python3-venv \
curl \
&& rm -rf /var/lib/apt/lists/*

#enable opengl support with nvidia gpu
Expand All @@ -38,59 +47,63 @@ RUN printf '%s\n' \
' }' \
'}' > /usr/share/glvnd/egl_vendor.d/10_nvidia.json

# Conda setup
# Python setup and uv installation
RUN mkdir -p /workspace/comfystream && \
wget "https://repo.anaconda.com/miniconda/Miniconda3-${CONDA_VERSION}-Linux-x86_64.sh" -O /tmp/miniconda.sh && \
bash /tmp/miniconda.sh -b -p /workspace/miniconda3 && \
eval "$(/workspace/miniconda3/bin/conda shell.bash hook)" && \
/workspace/miniconda3/bin/conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/main && \
/workspace/miniconda3/bin/conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/r && \
conda create -n comfystream python="${PYTHON_VERSION}" ffmpeg=6 -c conda-forge -y && \
rm /tmp/miniconda.sh && echo 'export LD_LIBRARY_PATH=/workspace/miniconda3/envs/comfystream/lib:$LD_LIBRARY_PATH' >> ~/.bashrc
python3 -m pip install --upgrade pip uv && \
cd /workspace && \
uv venv .venv && \
echo 'activate_venv() { if [ -f ".venv/bin/activate" ] && [ "$VIRTUAL_ENV" != "$(pwd)/.venv" ]; then . ".venv/bin/activate"; fi; };' >> ~/.bashrc && \
echo 'PROMPT_COMMAND="activate_venv; $PROMPT_COMMAND"' >> ~/.bashrc

# Ensure pip exists inside the venv for tools that shell out to `python -m pip`
RUN /workspace/.venv/bin/python -m ensurepip --upgrade && \
/workspace/.venv/bin/python -m pip install -U pip setuptools wheel && \
/workspace/.venv/bin/python -m pip --version

RUN conda run -n comfystream --no-capture-output pip install --upgrade pip && \
conda run -n comfystream --no-capture-output pip install wheel
# Install comfy-cli using uv
RUN uv pip install comfy-cli

# Copy only files needed for setup
COPY ./src/comfystream/scripts /workspace/comfystream/src/comfystream/scripts
COPY ./configs /workspace/comfystream/configs

# Clone ComfyUI
RUN git clone --branch v0.3.56 --depth 1 https://github.com/comfyanonymous/ComfyUI.git /workspace/ComfyUI
RUN mkdir -p /workspace

# Install ComfyUI using comfy-cli
RUN comfy --skip-prompt --workspace /workspace/ComfyUI install --skip-torch-or-directml --nvidia

# Copy ComfyStream files into ComfyUI
COPY . /workspace/comfystream

RUN conda run -n comfystream --cwd /workspace/comfystream --no-capture-output pip install -r ./src/comfystream/scripts/constraints.txt
RUN cd /workspace/comfystream && uv pip install -r ./src/comfystream/scripts/overrides.txt

# Copy comfystream and example workflows to ComfyUI
COPY ./workflows/comfyui/* /workspace/ComfyUI/user/default/workflows/
COPY ./test/example-512x512.png /workspace/ComfyUI/input

# Install ComfyUI requirements
RUN conda run -n comfystream --no-capture-output --cwd /workspace/ComfyUI pip install -r requirements.txt --root-user-action=ignore
# Install ComfyUI requirements (probably not needed)
# RUN cd /workspace/ComfyUI && uv pip install -r requirements.txt

# Install ComfyStream requirements
RUN ln -s /workspace/comfystream /workspace/ComfyUI/custom_nodes/comfystream
RUN conda run -n comfystream --no-capture-output --cwd /workspace/comfystream pip install -e . --root-user-action=ignore
RUN conda run -n comfystream --no-capture-output --cwd /workspace/comfystream python install.py --workspace /workspace/ComfyUI
RUN cd /workspace/comfystream && uv pip install -e .
RUN cd /workspace/comfystream && python install.py --workspace /workspace/ComfyUI

# Accept a build-arg that lets CI force-invalidate setup_nodes.py
ARG CACHEBUST=static
ENV CACHEBUST=${CACHEBUST}

# Run setup_nodes
RUN conda run -n comfystream --no-capture-output --cwd /workspace/comfystream python src/comfystream/scripts/setup_nodes.py --workspace /workspace/ComfyUI

RUN conda run -n comfystream --no-capture-output pip install "numpy<2.0.0"
# Run setup_nodes (removing to promote user node installation)
#RUN cd /workspace/comfystream && python src/comfystream/scripts/setup_nodes.py --workspace /workspace/ComfyUI

RUN conda run -n comfystream --no-capture-output pip install --no-cache-dir xformers==0.0.30 --no-deps
#RUN uv pip install "numpy<2.0.0"
#RUN uv pip install --no-cache-dir xformers==0.0.30 --no-deps

# Configure no environment activation by default
RUN conda config --set auto_activate_base false && \
conda init bash
# Set default Python environment with auto-uv-env and ensure .bashrc is sourced
RUN echo 'source ~/.bashrc' >> ~/.bash_profile && \
echo 'if [ -f ~/.bashrc ]; then source ~/.bashrc; fi' >> ~/.profile

# Set comfystream environment as default
RUN echo "conda activate comfystream" >> ~/.bashrc
# Ensure bash is used by default for interactive shells
ENV BASH_ENV=/root/.bashrc

WORKDIR /workspace/comfystream
32 changes: 14 additions & 18 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/bin/bash

set -e
eval "$(conda shell.bash hook)"

# Add help command to show usage
show_help() {
Expand Down Expand Up @@ -76,8 +75,7 @@ fi

if [ "$1" = "--download-models" ]; then
cd /workspace/comfystream
conda activate comfystream
python src/comfystream/scripts/setup_models.py --workspace /workspace/ComfyUI
uv run setup-models --workspace /workspace/ComfyUI
shift
fi

Expand All @@ -89,19 +87,18 @@ FASTERLIVEPORTRAIT_DIR="/workspace/ComfyUI/models/liveportrait_onnx"

if [ "$1" = "--build-engines" ]; then
cd /workspace/comfystream
conda activate comfystream

# Build Static Engine for Dreamshaper - Square (512x512)
python src/comfystream/scripts/build_trt.py --model /workspace/ComfyUI/models/unet/dreamshaper-8-dmd-1kstep.safetensors --out-engine /workspace/ComfyUI/output/tensorrt/static-dreamshaper8_SD15_\$stat-b-1-h-512-w-512_00001_.engine --width 512 --height 512
uv run python src/comfystream/scripts/build_trt.py --model /workspace/ComfyUI/models/unet/dreamshaper-8-dmd-1kstep.safetensors --out-engine /workspace/ComfyUI/output/tensorrt/static-dreamshaper8_SD15_\$stat-b-1-h-512-w-512_00001_.engine --width 512 --height 512

# Build Static Engine for Dreamshaper - Portrait (384x704)
python src/comfystream/scripts/build_trt.py --model /workspace/ComfyUI/models/unet/dreamshaper-8-dmd-1kstep.safetensors --out-engine /workspace/ComfyUI/output/tensorrt/static-dreamshaper8_SD15_\$stat-b-1-h-704-w-384_00001_.engine --width 384 --height 704
uv run python src/comfystream/scripts/build_trt.py --model /workspace/ComfyUI/models/unet/dreamshaper-8-dmd-1kstep.safetensors --out-engine /workspace/ComfyUI/output/tensorrt/static-dreamshaper8_SD15_\$stat-b-1-h-704-w-384_00001_.engine --width 384 --height 704

# Build Static Engine for Dreamshaper - Landscape (704x384)
python src/comfystream/scripts/build_trt.py --model /workspace/ComfyUI/models/unet/dreamshaper-8-dmd-1kstep.safetensors --out-engine /workspace/ComfyUI/output/tensorrt/static-dreamshaper8_SD15_\$stat-b-1-h-384-w-704_00001_.engine --width 704 --height 384
uv run python src/comfystream/scripts/build_trt.py --model /workspace/ComfyUI/models/unet/dreamshaper-8-dmd-1kstep.safetensors --out-engine /workspace/ComfyUI/output/tensorrt/static-dreamshaper8_SD15_\$stat-b-1-h-384-w-704_00001_.engine --width 704 --height 384

# Build Dynamic Engine for Dreamshaper
python src/comfystream/scripts/build_trt.py \
uv run python src/comfystream/scripts/build_trt.py \
--model /workspace/ComfyUI/models/unet/dreamshaper-8-dmd-1kstep.safetensors \
--out-engine /workspace/ComfyUI/output/tensorrt/dynamic-dreamshaper8_SD15_\$dyn-b-1-4-2-h-512-704-w-320-384-448_00001_.engine \
--width 384 \
Expand All @@ -117,15 +114,15 @@ if [ "$1" = "--build-engines" ]; then
mkdir -p "$DEPTH_ANYTHING_DIR"
fi
cd "$DEPTH_ANYTHING_DIR"
python /workspace/ComfyUI/custom_nodes/ComfyUI-Depth-Anything-Tensorrt/export_trt.py
uv run python /workspace/ComfyUI/custom_nodes/ComfyUI-Depth-Anything-Tensorrt/export_trt.py
else
echo "Engine for DepthAnything2 already exists at ${DEPTH_ANYTHING_DIR}/${DEPTH_ANYTHING_ENGINE}, skipping..."
fi

# Build Engine for Depth Anything2 (large)
if [ ! -f "$DEPTH_ANYTHING_DIR/$DEPTH_ANYTHING_ENGINE_LARGE" ]; then
cd "$DEPTH_ANYTHING_DIR"
python /workspace/ComfyUI/custom_nodes/ComfyUI-Depth-Anything-Tensorrt/export_trt.py --trt-path "${DEPTH_ANYTHING_DIR}/${DEPTH_ANYTHING_ENGINE_LARGE}" --onnx-path "${DEPTH_ANYTHING_DIR}/depth_anything_v2_vitl.onnx"
uv run python /workspace/ComfyUI/custom_nodes/ComfyUI-Depth-Anything-Tensorrt/export_trt.py --trt-path "${DEPTH_ANYTHING_DIR}/${DEPTH_ANYTHING_ENGINE_LARGE}" --onnx-path "${DEPTH_ANYTHING_DIR}/depth_anything_v2_vitl.onnx"
else
echo "Engine for DepthAnything2 (large) already exists at ${DEPTH_ANYTHING_DIR}/${DEPTH_ANYTHING_ENGINE_LARGE}, skipping..."
fi
Expand All @@ -138,7 +135,7 @@ if [ "$1" = "--build-engines" ]; then
for model in $MODELS; do
for timestep in $TIMESTEPS; do
echo "Building model=$model with timestep=$timestep"
python build_tensorrt.py \
uv run python build_tensorrt.py \
--model-id "$model" \
--timesteps "$timestep" \
--engine-dir $TENSORRT_DIR/StreamDiffusion-engines
Expand All @@ -152,8 +149,7 @@ fi

if [ "$1" = "--opencv-cuda" ]; then
cd /workspace/comfystream
conda activate comfystream


# Check if OpenCV CUDA build already exists
if [ ! -f "/workspace/comfystream/opencv-cuda-release.tar.gz" ]; then
# Download and extract OpenCV CUDA build
Expand All @@ -176,18 +172,18 @@ if [ "$1" = "--opencv-cuda" ]; then
libswscale-dev

# Remove existing cv2 package
SITE_PACKAGES_DIR="/workspace/miniconda3/envs/comfystream/lib/python3.12/site-packages"
SITE_PACKAGES_DIR="$(uv python dir --bin)/lib/python3.12/site-packages"
rm -rf "${SITE_PACKAGES_DIR}/cv2"*

# Copy new cv2 package
cp -r /workspace/comfystream/cv2 "${SITE_PACKAGES_DIR}/"

# Handle library dependencies
CONDA_ENV_LIB="/workspace/miniconda3/envs/comfystream/lib"
UV_ENV_LIB="$(uv python dir --bin)/lib"

# Remove existing libstdc++ and copy system one
rm -f "${CONDA_ENV_LIB}/libstdc++.so"*
cp /usr/lib/x86_64-linux-gnu/libstdc++.so* "${CONDA_ENV_LIB}/"
rm -f "${UV_ENV_LIB}/libstdc++.so"*
cp /usr/lib/x86_64-linux-gnu/libstdc++.so* "${UV_ENV_LIB}/"

# Copy OpenCV libraries
cp /workspace/comfystream/opencv/build/lib/libopencv_* /usr/lib/x86_64-linux-gnu/
Expand Down
Loading