2024-07-01 15:57:52 +02:00
|
|
|
# Stage 1: Base Image
|
2024-07-27 11:02:51 +02:00
|
|
|
FROM madiator2011/better-base:cuda12.1 as base
|
2024-07-01 15:57:52 +02:00
|
|
|
|
2024-07-30 12:27:59 +02:00
|
|
|
ARG PYTHON_VERSION1=3.11
|
2024-07-27 11:02:51 +02:00
|
|
|
ARG TORCH=torch==2.3.0+cu121
|
2024-07-01 15:57:52 +02:00
|
|
|
|
2024-09-12 14:07:03 +02:00
|
|
|
# Install fpart (which includes fpsync)
|
|
|
|
ENV DEBIAN_FRONTEND=noninteractive
|
|
|
|
RUN apt-get update && \
|
|
|
|
apt-get install -y fpart && \
|
|
|
|
apt-get clean && \
|
|
|
|
rm -rf /var/lib/apt/lists/*
|
|
|
|
|
2024-07-01 15:57:52 +02:00
|
|
|
# Stage 2: ComfyUI Installation
|
|
|
|
FROM base as comfyui-install
|
|
|
|
|
2024-09-12 14:07:03 +02:00
|
|
|
# Create virtual environment
|
|
|
|
RUN mkdir -p /workspace/runpod-venvs && python -m venv /workspace/runpod-venvs/better-comfyui
|
2024-07-30 12:27:59 +02:00
|
|
|
|
|
|
|
# Set environment variables for the virtual environment
|
2024-09-12 14:07:03 +02:00
|
|
|
ENV VIRTUAL_ENV="/workspace/runpod-venvs/better-comfyui"
|
2024-07-30 12:27:59 +02:00
|
|
|
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
|
|
|
|
|
|
|
|
# Activate the virtual environment and install packages
|
|
|
|
RUN $VIRTUAL_ENV/bin/pip install --upgrade pip setuptools wheel && \
|
|
|
|
if [ -n "${TORCH}" ]; then \
|
|
|
|
$VIRTUAL_ENV/bin/pip install --no-cache-dir ${TORCH}; \
|
|
|
|
fi && \
|
|
|
|
git clone https://github.com/comfyanonymous/ComfyUI.git /ComfyUI && \
|
|
|
|
$VIRTUAL_ENV/bin/pip install -r /ComfyUI/requirements.txt && \
|
|
|
|
git clone https://github.com/ltdrdata/ComfyUI-Manager.git /ComfyUI/custom_nodes/ComfyUI-Manager && \
|
|
|
|
$VIRTUAL_ENV/bin/pip install -r /ComfyUI/custom_nodes/ComfyUI-Manager/requirements.txt && \
|
|
|
|
$VIRTUAL_ENV/bin/pip install xformers accelerate wheel comfy-cli insightface && \
|
|
|
|
$VIRTUAL_ENV/bin/pip install ipykernel ipywidgets && \
|
|
|
|
$VIRTUAL_ENV/bin/python -m ipykernel install --name "python3" --display-name "Python 3 (Workspace Venv)"
|
2024-07-01 15:57:52 +02:00
|
|
|
|
2024-07-27 11:02:51 +02:00
|
|
|
# Stage 3: Model Setup
|
|
|
|
FROM comfyui-install as model-setup
|
2024-07-01 15:57:52 +02:00
|
|
|
|
|
|
|
# Create model and cache directories
|
2024-07-30 12:27:59 +02:00
|
|
|
RUN mkdir -p /root/.cache/huggingface /comfy-models
|
2024-07-01 15:57:52 +02:00
|
|
|
|
2024-07-27 11:02:51 +02:00
|
|
|
ARG INCLUDE_MODELS=false
|
|
|
|
|
|
|
|
# Download each model in a separate layer
|
|
|
|
RUN if [ "${INCLUDE_MODELS}" = "true" ]; then \
|
2024-09-12 14:07:03 +02:00
|
|
|
wget -q --show-progress https://huggingface.co/Comfy-Org/stable-diffusion-v1-5-archive/resolve/main/v1-5-pruned-emaonly.safetensors -O /comfy-models/v1-5-pruned-emaonly.safetensors; \
|
2024-07-27 11:02:51 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
RUN if [ "${INCLUDE_MODELS}" = "true" ]; then \
|
|
|
|
wget -q --show-progress https://huggingface.co/stabilityai/stable-diffusion-2-1/resolve/main/v2-1_768-ema-pruned.safetensors -O /comfy-models/v2-1_768-ema-pruned.safetensors; \
|
|
|
|
fi
|
|
|
|
|
|
|
|
RUN if [ "${INCLUDE_MODELS}" = "true" ]; then \
|
|
|
|
wget -q --show-progress https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_base_1.0.safetensors -O /comfy-models/sd_xl_base_1.0.safetensors; \
|
|
|
|
fi
|
|
|
|
|
|
|
|
RUN if [ "${INCLUDE_MODELS}" = "true" ]; then \
|
|
|
|
wget -q --show-progress https://huggingface.co/stabilityai/stable-diffusion-xl-refiner-1.0/resolve/main/sd_xl_refiner_1.0.safetensors -O /comfy-models/sd_xl_refiner_1.0.safetensors; \
|
|
|
|
fi
|
2024-07-01 15:57:52 +02:00
|
|
|
|
|
|
|
# Verify models were downloaded
|
2024-07-27 11:02:51 +02:00
|
|
|
RUN if [ "${INCLUDE_MODELS}" = "true" ]; then \
|
|
|
|
ls -lh /comfy-models; \
|
|
|
|
fi
|
2024-07-01 15:57:52 +02:00
|
|
|
|
2024-07-27 11:02:51 +02:00
|
|
|
# Stage 4: Final Image
|
|
|
|
FROM comfyui-install as final
|
2024-07-01 15:57:52 +02:00
|
|
|
|
2024-07-30 12:27:59 +02:00
|
|
|
# Move virtual environment from /workspace/venv to /venv
|
2024-09-12 14:07:03 +02:00
|
|
|
RUN mv /workspace/runpod-venvs/better-comfyui /venv
|
2024-07-30 12:27:59 +02:00
|
|
|
|
2024-07-27 11:02:51 +02:00
|
|
|
# Copy models if they were included
|
|
|
|
COPY --from=model-setup /comfy-models /comfy-models
|
2024-07-01 15:57:52 +02:00
|
|
|
|
|
|
|
# Set environment variables for runtime
|
2024-09-12 14:07:03 +02:00
|
|
|
ENV VIRTUAL_ENV="/workspace/runpod-venvs/better-comfyui"
|
2024-07-30 12:27:59 +02:00
|
|
|
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
|
2024-07-01 15:57:52 +02:00
|
|
|
|
2024-07-27 11:02:51 +02:00
|
|
|
# Copy the README.md
|
|
|
|
COPY README.md /usr/share/nginx/html/README.md
|
|
|
|
|
|
|
|
# NGINX Proxy
|
|
|
|
COPY --from=proxy nginx.conf /etc/nginx/nginx.conf
|
|
|
|
COPY --from=proxy readme.html /usr/share/nginx/html/readme.html
|
2024-07-01 15:57:52 +02:00
|
|
|
|
2024-07-27 11:02:51 +02:00
|
|
|
# Copy all necessary scripts
|
|
|
|
COPY pre_start.sh /pre_start.sh
|
2024-07-01 15:57:52 +02:00
|
|
|
COPY --from=scripts start.sh /
|
|
|
|
RUN chmod +x /start.sh
|
2024-07-27 11:02:51 +02:00
|
|
|
RUN chmod +x /pre_start.sh
|
2024-07-30 12:27:59 +02:00
|
|
|
COPY comfyui_extras.ipynb /comfyui_extras.ipynb
|
2024-07-01 15:57:52 +02:00
|
|
|
|
2024-07-27 11:02:51 +02:00
|
|
|
# CMD
|
2024-09-12 14:07:03 +02:00
|
|
|
CMD [ "/start.sh" ]
|