diff --git a/workflows/comfy/Dockerfile b/workflows/comfy/Dockerfile new file mode 100644 index 0000000..8fe6354 --- /dev/null +++ b/workflows/comfy/Dockerfile @@ -0,0 +1,52 @@ + +# NB(bt, 2022-12-12): The version of containerized CUDA must match (or be less than?) that of the host system running this container. +# Juggling these dependencies, plus the underlying Ubuntu system (which controls Python versions), is tricky. +# Nvidia does not provide a CUDA 11.6 with Ubuntu 22.04, which mirrors my own desktop machine. Their CUDA 11.6 + Ubuntu 20.04 image has +# a stale Python (3.8), so we have to use the DeadSnakes PPA to install a more modern version. +# Gross. +FROM nvidia/cuda:11.8.0-devel-ubuntu22.04 + +# See: https://github.com/opencontainers/image-spec/blob/master/annotations.md +LABEL org.opencontainers.image.title='Storyteller ML: Voice Conversion' +LABEL org.opencontainers.image.authors='adrien@storyteller.ai' + +# tzdata install hangs without presetting the time zone +ENV TZ=UTC +RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone + +# Needed to install "future" release of Python 3.10 under Ubuntu 20.04, which only natively packages Python 3.8. +# We seem to be stuck on Ubuntu 22.04 because containerizd CUDA 11.6 is the only version we can run on my host machine, +# and Nvidia does not supply a (CUDA 11.6, Ubuntu 22.04) docker base image. +RUN apt-get update \ + && apt install software-properties-common -y \ + && add-apt-repository ppa:deadsnakes/ppa + +RUN apt-get update \ + && DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt-get install -y \ + curl \ + ffmpeg \ + libmagic-dev \ + libmagic1 \ + python3-pip \ + python3.10 \ + python3.10-venv \ + unzip \ + wget \ + git \ + --no-install-recommends + +RUN addgroup --system appgroup && adduser --system --ingroup appgroup appuser +# Copy files to container +COPY --chown=appuser:appgroup initialize_comfy_extensions.py /app/initialize_comfy_extensions.py +COPY --chown=appuser:appgroup install.py /app/install.py +COPY --chown=appuser:appgroup repos.json /app/repos.json +COPY --chown=appuser:appgroup required_requirements.txt /app/required_requirements.txt + +RUN chmod -R 777 /app + +# protobuf use python implementation (weird error without) +ENV PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python + +EXPOSE 8188 + +USER appuser \ No newline at end of file diff --git a/workflows/comfy/initialize_comfy_extensions.py b/workflows/comfy/initialize_comfy_extensions.py new file mode 100644 index 0000000..bae7c54 --- /dev/null +++ b/workflows/comfy/initialize_comfy_extensions.py @@ -0,0 +1,46 @@ +import os +import sys +import asyncio +import threading +# Init all the nodes + +current_script_dir = os.path.dirname(os.path.realpath(__file__)) +comfy_path = os.path.dirname(os.path.abspath(__file__)) +comfy_path = os.path.join(comfy_path, 'ComfyUI') + +# change to ComfyUI directory +os.chdir(comfy_path) + +# add ComfyUI to path +sys.path.append(comfy_path) + +from server import PromptServer +from execution import PromptQueue +from main import init_custom_nodes, cuda_malloc_warning, prompt_worker, execute_prestartup_script +import folder_paths + +execute_prestartup_script() + +async def run(): + loop = asyncio.new_event_loop() + asyncio.set_event_loop(loop) + server = PromptServer(loop) + q = PromptQueue(server) + + init_custom_nodes() + + cuda_malloc_warning() + + server.add_routes() + + threading.Thread(target=prompt_worker, daemon=True, args=(q, server,)).start() + + folder_paths.add_model_folder_path("checkpoints", os.path.join(folder_paths.get_output_directory(), "checkpoints")) + folder_paths.add_model_folder_path("clip", os.path.join(folder_paths.get_output_directory(), "clip")) + folder_paths.add_model_folder_path("vae", os.path.join(folder_paths.get_output_directory(), "vae")) + + await server.start('127.0.0.1', 8188) + + +if __name__ == "__main__": + asyncio.run(run()) diff --git a/workflows/comfy/install.py b/workflows/comfy/install.py new file mode 100644 index 0000000..63715f2 --- /dev/null +++ b/workflows/comfy/install.py @@ -0,0 +1,65 @@ +import subprocess +import json +import os + +json_file_path = 'repos.json' +venv_python = os.path.join('ComfyUI', 'venv', 'Scripts' if os.name == 'nt' else 'bin', 'python') + + +def run_command(command): + process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) + + # Print stdout live + for line in iter(process.stdout.readline, ''): + print(line, end='') + + # Wait for the process to terminate and get the exit code + process.wait() + + # Check if the process exited with an error + if process.returncode != 0: + # Print any errors from stderr + for line in iter(process.stderr.readline, ''): + print(line, end='') + print(f"Error executing command: {command}") + + +def setup_repo(repo_info): + url, commit, folder = repo_info['url'], repo_info['commit'], repo_info['folder'] + # save the current working directory + original_cwd = os.getcwd() + try: + run_command(f"git clone {url} {folder}") + os.chdir(folder) + run_command(f"git checkout {commit}") + finally: + os.chdir(original_cwd) + + +def setup_venv_and_install_requirements(): + run_command("python -m venv ComfyUI/venv") + print('=============# Installing ComfyUI Requirements #=============') + run_command(f"{venv_python} -m pip install -r ComfyUI/requirements.txt") + print('=============# Installing extension missing requirements #=============') + run_command(f"{venv_python} -m pip install -r required_requirements.txt") + + +def run_comfyui_setup(): + run_command(f"{venv_python} initialize_comfy_extensions.py") + + +def main(): + with open(json_file_path, 'r') as file: + repos = json.load(file) + + for repo_info in repos: + print(f"installing {repo_info['url']} at commit {repo_info['commit']} to {repo_info['folder']}") + setup_repo(repo_info) + + setup_venv_and_install_requirements() + run_comfyui_setup() + + +if __name__ == "__main__": + main() + open('ALREADY_SETUP.flag', 'w').close() diff --git a/workflows/comfy/repos.json b/workflows/comfy/repos.json new file mode 100644 index 0000000..344778a --- /dev/null +++ b/workflows/comfy/repos.json @@ -0,0 +1,127 @@ +[ + { + "url": "https://github.com/comfyanonymous/ComfyUI.git", + "commit": "00425563c07171f478e7809d3b89cc3df770ebbd", + "folder": "ComfyUI" + }, + { + "url": "https://github.com/ltdrdata/ComfyUI-Manager.git", + "commit": "a31c528906759783ef2863c2e1590fd4d61cbbbf", + "folder": "ComfyUI/custom_nodes/ComfyUI-Manager" + }, + { + "url": "https://github.com/ltdrdata/ComfyUI-Impact-Pack.git", + "commit": "8b35530cfb3658aaa2715c8619379ca20a94c5a6", + "folder": "ComfyUI/custom_nodes/ComfyUI-Impact-Pack" + }, + { + "url": "https://github.com/Fannovel16/comfyui_controlnet_aux.git", + "commit": "920a7ff9deac386ff3a3d17782fa876c51554cda", + "folder": "ComfyUI/custom_nodes/comfyui_controlnet_aux" + }, + { + "url": "https://github.com/Fannovel16/ComfyUI-Frame-Interpolation.git", + "commit": "5e11679995c68f33891c306a393915feefe234b5", + "folder": "ComfyUI/custom_nodes/ComfyUI-Frame-Interpolation" + }, + { + "url": "https://github.com/jags111/efficiency-nodes-comfyui.git", + "commit": "f6d01dc5449e2cc6e29da92b3b337e49c0dce112", + "folder": "ComfyUI/custom_nodes/efficiency-nodes-comfyui" + }, + { + "url": "https://github.com/Derfuu/Derfuu_ComfyUI_ModdedNodes.git", + "commit": "2ace4c463d5b2063de35e46ebb9bd3f10e2d34b4", + "folder": "ComfyUI/custom_nodes/Derfuu_ComfyUI_ModdedNodes" + }, + { + "url": "https://github.com/WASasquatch/was-node-suite-comfyui.git", + "commit": "596fc345ddf2edcda7cf444354afe586d630cddf", + "folder": "ComfyUI/custom_nodes/was-node-suite-comfyui" + }, + { + "url": "https://github.com/pythongosssss/ComfyUI-Custom-Scripts.git", + "commit": "b4a9cebf24b50c4b538945ae86c17a9dc24052a8", + "folder": "ComfyUI/custom_nodes/ComfyUI-Custom-Scripts" + }, + { + "url": "https://github.com/melMass/comfy_mtb.git", + "commit": "b7c85824582d2eed994ec1ff451e33d75911595d", + "folder": "ComfyUI/custom_nodes/comfy_mtb" + }, + { + "url": "https://github.com/FizzleDorf/ComfyUI_FizzNodes.git", + "commit": "2ad19c1c3ad424b732fa0bc16ffb02284676a5da", + "folder": "ComfyUI/custom_nodes/ComfyUI_FizzNodes" + }, + { + "url": "https://github.com/Kosinkadink/ComfyUI-Advanced-ControlNet.git", + "commit": "9c0fe542c62b55591253f4bcdd33c34a1b24331e", + "folder": "ComfyUI/custom_nodes/ComfyUI-Advanced-ControlNet" + }, + { + "url": "https://github.com/Kosinkadink/ComfyUI-AnimateDiff-Evolved.git", + "commit": "12c9879ebbbf2cc2a87dae8609ad365384313072", + "folder": "ComfyUI/custom_nodes/ComfyUI-AnimateDiff-Evolved" + }, + { + "url": "https://github.com/Kosinkadink/ComfyUI-VideoHelperSuite.git", + "commit": "f94597739f20dac331f9918a245149b6b00a60f2", + "folder": "ComfyUI/custom_nodes/ComfyUI-VideoHelperSuite" + }, + { + "url": "https://github.com/theUpsider/ComfyUI-Logic.git", + "commit": "fb8897351f715ea75eebf52e74515b6d07c693b8", + "folder": "ComfyUI/custom_nodes/ComfyUI-Logic" + }, + { + "url": "https://github.com/rgthree/rgthree-comfy.git", + "commit": "9021670e9ff887d40e031334fc9f3e92c599d161", + "folder": "ComfyUI/custom_nodes/rgthree-comfy" + }, + { + "url": "https://github.com/giriss/comfy-image-saver.git", + "commit": "65e6903eff274a50f8b5cd768f0f96baf37baea1", + "folder": "ComfyUI/custom_nodes/comfy-image-saver" + }, + { + "url": "https://github.com/kijai/ComfyUI-KJNodes.git", + "commit": "e9fcd376a6c06915bb596c189815edef380a98f5", + "folder": "ComfyUI/custom_nodes/ComfyUI-KJNodes" + }, + { + "url": "https://github.com/Ttl/ComfyUi_NNLatentUpscale.git", + "commit": "08105da31dbd7a54569661e135835e73bd8064b0", + "folder": "ComfyUI/custom_nodes/ComfyUi_NNLatentUpscale" + }, + { + "url": "https://github.com/cubiq/ComfyUI_IPAdapter_plus.git", + "commit": "6a411dcb2c6c3b91a3aac97adfb080a77ade7d38", + "folder": "ComfyUI/custom_nodes/ComfyUI_IPAdapter_plus" + }, + { + "url": "https://github.com/cubiq/ComfyUI_essentials.git", + "commit": "85a1937eea238c6e6e59991813656faa0da82fff", + "folder": "ComfyUI/custom_nodes/ComfyUI_essentials" + }, + { + "url": "https://github.com/storyicon/comfyui_segment_anything.git", + "commit": "681d977c2cc244de729fd9e08145ff365c609262", + "folder": "ComfyUI/custom_nodes/comfyui_segment_anything" + }, + { + "url": "https://github.com/Jcd1230/rembg-comfyui-node.git", + "commit": "fac7df6c3f42e158a2829b511b37f13e4cc834eb", + "folder": "ComfyUI/custom_nodes/rembg-comfyui-node" + }, + { + "url": "https://github.com/crystian/ComfyUI-Crystools.git", + "commit": "8c257748b98f59357ac20cebd4b4b67c0a9e53fe", + "folder": "ComfyUI/custom_nodes/ComfyUI-Crystools" + }, + { + "url": "https://github.com/Fannovel16/ComfyUI-Video-Matting.git", + "commit": "178bf956ddb817d065b1b073ec04582ad60335bb", + "folder": "ComfyUI/custom_nodes/ComfyUI-Video-Matting" + } +] diff --git a/workflows/comfy/required_requirements.txt b/workflows/comfy/required_requirements.txt new file mode 100644 index 0000000..06d6657 --- /dev/null +++ b/workflows/comfy/required_requirements.txt @@ -0,0 +1,14 @@ +numexpr +numba +opencv-python +color_matcher +mediapipe +piexif +segment_anything +scikit-image +rembg[gpu] +timm +addict +yapf +deepdiff +pynvml