Improve docker configuration (#4)

Improve docker configuration
This commit is contained in:
Brian Gebel 2025-05-31 11:06:24 -07:00 committed by GitHub
parent 541965b37c
commit 0eee719776
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 127 additions and 161 deletions

View file

@ -1,6 +0,0 @@
#!/bin/bash
set -Eeuo pipefail
find services -name "*.sh" -exec git update-index --chmod=+x {} \;
find .devscripts -name "*.sh" -exec git update-index --chmod=+x {} \;

View file

@ -1,30 +0,0 @@
mkdir -p data/.cache data/StableDiffusion data/Codeformer data/GFPGAN data/ESRGAN data/BSRGAN data/RealESRGAN data/SwinIR data/LDSR data/embeddings
cp -vf cache/models/model.ckpt data/StableDiffusion/model.ckpt
cp -vf cache/models/LDSR.ckpt data/LDSR/model.ckpt
cp -vf cache/models/LDSR.yaml data/LDSR/project.yaml
cp -vf cache/models/RealESRGAN_x4plus.pth data/RealESRGAN/
cp -vf cache/models/RealESRGAN_x4plus_anime_6B.pth data/RealESRGAN/
cp -vrf cache/torch data/.cache/
mkdir -p data/.cache/huggingface/transformers/
cp -vrf cache/transformers/* data/.cache/huggingface/transformers/
cp -v cache/custom-models/* data/StableDiffusion/
mkdir -p data/.cache/clip/
cp -vf cache/weights/ViT-L-14.pt data/.cache/clip/
cp -vf cache/weights/codeformer.pth data/Codeformer/codeformer-v0.1.0.pth
cp -vf cache/weights/detection_Resnet50_Final.pth data/.cache/
cp -vf cache/weights/parsing_parsenet.pth data/.cache/
cp -v embeddings/* data/embeddings/
echo this script was created 10/2022
echo Dont forget to run: docker compose --profile download up --build
echo the cache and embeddings folders can be deleted, but its not necessary.

View file

@ -1,9 +0,0 @@
#!/bin/bash
set -Eeuo pipefail
echo "Moving everything in output to output/old..."
mv output old
mkdir output
mv old/.gitignore output
mv old output

View file

@ -1,28 +0,0 @@
#!/bin/bash
set -Eeuo pipefail
echo "Renaming..."
# compatible with default auto-names
mv -v ./data/StableDiffusion ./data/Stable-diffusion
mv -v ./data/Deepdanbooru ./data/torch_deepdanbooru
# casing problem on windows
mv -v ./data/Hypernetworks ./data/hypernetworks1
mv -v ./data/hypernetworks1 ./data/hypernetworks
mv -v ./data/MiDaS ./data/midas1
mv -v ./data/midas1 ./data/midas
echo "Moving folders..."
mkdir -pv ./final
mv -v ./data/config ./final/config
mv -v ./data/.cache ./final/.cache
mv -v ./data/embeddings ./final/embeddings
mv -v ./data ./final/models
mv -v ./final ./data

View file

@ -1,9 +0,0 @@
root = true
[*]
end_of_line = lf
indent_style = space
indent_size = 2
charset = utf-8
insert_final_newline = true
trim_trailing_whitespace = true

View file

@ -1,4 +1,23 @@
#=====================================================================#
# Server Configuration #
#=====================================================================#
PUID=1000
PGID=1000
DEVICE_DRIVER=nvidia
DEVICE_DRIVER=nvidia
#=====================================================================#
# Automatic1111 Configuration #
#=====================================================================#
AUTO_WEBUI_PORT=7860
AUTO_CLI_ARGS="--allow-code --medvram --xformers --enable-insecure-extension-access --api"
# AUTO_CLI_ARGS="--no-half --precision full --allow-code --enable-insecure-extension-access --api"
#=====================================================================#
# ComfyUI Configuration #
#=====================================================================#
COMFY_WEBUI_PORT=8188
COMFY_CLI_ARGS=

3
.gitignore vendored
View file

@ -1,5 +1,6 @@
# Docker
/.devcontainer
/docker-compose.override.yml
.env
# VSCode specific
*.code-workspace

View file

@ -1,24 +1,4 @@
x-base_service: &base_service
user: ${PUID:-1000}:${PGID:-1000}
environment:
- PUID=${PUID:-1000}
- PGID=${PGID:-1000}
ports:
- "${WEBUI_PORT:-7860}:7860"
volumes:
- &v1 ./data:/data
- &v2 ./output:/output
stop_signal: SIGKILL
tty: true
deploy:
resources:
reservations:
devices:
- driver: nvidia
device_ids: ['0']
capabilities: [compute, utility]
name: webui-docker
name: stable-diffusion-webui-docker
services:
download:
@ -29,34 +9,66 @@ services:
- PUID=${PUID:-1000}
- PGID=${PGID:-1000}
volumes:
- *v1
- ./data:/data
auto: &automatic
<<: *base_service
auto:
profiles: ["auto"]
build: ./services/AUTOMATIC1111
image: sd-auto:78
image: auto:v1.10.1
user: ${PUID:-1000}:${PGID:-1000}
environment:
- CLI_ARGS=--allow-code --medvram --xformers --enable-insecure-extension-access --api
- PUID=${PUID:-1000}
- PGID=${PGID:-1000}
- CLI_ARGS=${AUTO_CLI_ARGS}
ports:
- "7860:7860" # hardcoded in Dockerfile for now
volumes:
- ./data:/data
- ./output:/output
stop_signal: SIGKILL
tty: true
deploy:
resources:
reservations:
devices:
- driver: nvidia
device_ids: ['0']
capabilities: [compute, utility]
auto-cpu:
<<: *automatic
profiles: ["auto-cpu"]
deploy: {}
environment:
- CLI_ARGS=--no-half --precision full --allow-code --enable-insecure-extension-access --api
comfy: &comfy
<<: *base_service
comfy:
profiles: ["comfy"]
build: ./services/comfy/
image: sd-comfy:7
image: comfy:v0.3.39
user: ${PUID:-1000}:${PGID:-1000}
environment:
- CLI_ARGS=
- PUID=${PUID:-1000}
- PGID=${PGID:-1000}
- CLI_ARGS=${COMFY_CLI_ARGS}
ports:
- "8188:8188" # hardcoded in Dockerfile for now
volumes:
# - ./comfy/extra_model_paths.yaml:/extra_model_paths.yaml:ro,cached
- ./data:/data:delegated
- ./output:/output
stop_signal: SIGKILL
tty: true
deploy:
resources:
reservations:
devices:
- driver: nvidia
device_ids: ['0']
capabilities: [compute, utility]
comfy-cpu:
<<: *comfy
profiles: ["comfy-cpu"]
deploy: {}
environment:
- CLI_ARGS=--cpu
# Version auto1111, use same or similar base images
# Fix Mappings for models `/data/models` and `data/config/comfy/models` the later is created by ComfyManager
# Run everything in an venv
# IPAdapterPlus
# ONNX
# comfyui-manager by default
# Model/Embeddings
# /data/config/comfy
# /data/config/auto
# /data/config/shared
# Also move /output to /data/output

View file

@ -5,12 +5,10 @@ ENV PIP_PREFER_BINARY=1
RUN --mount=type=cache,target=/var/cache/apt \
apt-get update && \
apt-get install -y git wget curl jq ffmpeg libgl1-mesa-glx libglib2.0-0 && \
apt-get clean
apt-get install -y --no-install-recommends git wget curl jq ffmpeg libgl1-mesa-glx libglib2.0-0 && \
apt-get clean && \
pip install --no-input --upgrade pip
# Explore how we can use the CLI to do this instead
# https://docs.comfy.org/installation/system_requirements
# https://docs.comfy.org/comfy-cli/getting-started
FROM base AS application
RUN useradd -m -s /bin/bash comfy
@ -19,31 +17,43 @@ USER comfy
WORKDIR /home/comfy/app
# Using CLI (with conda venv -can do venv without all this too)
# python -m pip install -U pip && \
# pip install comfy-cli && \
# conda init bash && \
# conda create -n comfy-env python=3.11 && \
# conda activate comfy-env && \
# comfy install
RUN --mount=type=cache,target=/comfy/.cache/pip \
git clone --branch v0.3.30 --depth 1 https://github.com/comfyanonymous/ComfyUI.git . && \
mkdir -p .local/bin && \
pip install -r requirements.txt && \
pip install onnxruntime-gpu
# Should make ONNX optional by moving this into a configuration file that can be alterated at run time
SHELL ["/bin/bash", "--login", "-c"]
# Setup ComfyUI project
RUN git clone --branch v0.3.39 --depth 1 https://github.com/comfyanonymous/ComfyUI.git .
COPY --chown=comfy:comfy . .
RUN chmod u+x ./entrypoint.sh
# Setup venv
# # https://pythonspeed.com/articles/activate-virtualenv-dockerfile/
ENV VIRTUAL_ENV=/home/comfy/app/.venv
RUN --mount=type=cache,target=~/.cache/pip \
mkdir -p ~/.local/bin && \
python -m venv $VIRTUAL_ENV
ENV PATH="/home/comfy/.local/bin:${PATH}"
ENV PYTHONPATH="${PYTHONPATH}:${PWD}"
ENV PATH="/home/comfy/.local/bin:$PATH"
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
# ENV PYTHONPATH="${PYTHONPATH}:${PWD}"
# Activate environment and install dependencies
# Should make ONNX optional by moving this into a configuration file that can be alterated at run time
RUN --mount=type=cache,target=~/.cache/pip \
pip install -r requirements.txt && \
pip install onnxruntime-gpu && \
chmod u+x ./entrypoint.sh
ENV NVIDIA_VISIBLE_DEVICES=all
ENV CLI_ARGS=""
EXPOSE 7860
EXPOSE 8188
ENTRYPOINT ["./entrypoint.sh"]
CMD python -u main.py --listen --port 7860 ${CLI_ARGS}
CMD python -u main.py --listen --port 8188 ${CLI_ARGS}
# Explore how we can use the CLI to do this instead
# https://docs.comfy.org/installation/system_requirements
# https://docs.comfy.org/comfy-cli/getting-started
# https://pythonspeed.com/articles/activate-conda-dockerfile/
# https://pythonspeed.com/articles/multi-stage-docker-python/
# pip install comfy-cli && \
# comfy install

View file

@ -3,27 +3,25 @@
set -Eeuo pipefail
BASE_DIRECTORY="/data/config/comfy"
OUTPUT_DIRECTORY="/data/output"
OUTPUT_DIRECTORY="/output"
mkdir -vp ${BASE_DIRECTORY}
mkdir -vp ${BASE_DIRECTORY}
mkdir -vp ${BASE_DIRECTORY}/temp
mkdir -vp ${BASE_DIRECTORY}/user
mkdir -vp ${BASE_DIRECTORY}/custom_nodes
mkdir -vp ${OUTPUT_DIRECTORY}
# @brian - Why is this here?
# XDG_CACHE_HOME - Set cache outside container
mkdir -vp /data/.cache
XDG_CACHE_HOME=/data/.cache
export XDG_CACHE_HOME
# mkdir -vp /data/.cache
# XDG_CACHE_HOME=/data/.cache
# export XDG_CACHE_HOME
# --base-directory BASE_DIRECTORY
# Set the ComfyUI base directory for models,
# custom_nodes, input, output, temp, and user directories.
CLI_ARGS+="${CLI_ARGS} --base-directory ${BASE_DIRECTORY} --output-directory ${OUTPUT_DIRECTORY}"
echo ${CLI_ARGS}
if [ -f "/data/config/comfy/startup.sh" ]; then
pushd ${APPLICATION_ROOT}
. /data/config/comfy/startup.sh

View file

@ -1,11 +1,14 @@
# https://github.com/comfyanonymous/ComfyUI/blob/master/extra_model_paths.yaml.example
# https://comfyui-wiki.com/en/tutorial/basic/link-models-between-comfyui-and-a1111
a111:
base_path: /data
checkpoints: models/Stable-diffusion
configs: models/Stable-diffusion
vae: models/VAE
loras: models/Lora
loras: |
models/Lora
models/LyCORIS
upscale_models: |
models/RealESRGAN
models/ESRGAN
@ -20,16 +23,20 @@ a111:
comfyui:
base_path: /data
# custom_nodes: config/comfy/custom_nodes
custom_nodes: config/comfy/custom_nodes
download_model_base: data/models
# TODO: I am unsure about these, need more testing
# style_models: data/config/comfy/style_models
# t2i_adapter: data/config/comfy/t2i_adapter
# clip_vision: data/config/comfy/clip_vision
# diffusers: data/config/comfy/diffusers
# download_model_base: data/models
# Need this file to be loaded dynamically maybe as a vol?
# Need to install ipadapter and set mappings
# https://github.com/cubiq/ComfyUI_IPAdapter_plus
# Create an auto installer? Is there a newer plugin/extension?
# Need this file to be loaded dynamically maybe as a vol? Currently these are being downloaded to /data/config/comfy/models
# - `ultralytics_bbox` - Specifies the paths for bbox YOLO models.
# - `ultralytics_segm` - Specifies the paths for segm YOLO models.
# - `ultralytics` - Allows the presence of `bbox/` and `segm/` subdirectories.

View file

@ -0,0 +1 @@
https://github.com/microsoft/TRELLIS/issues/14