From c375863421ddfe33c98afd429728c9ef88af3cc1 Mon Sep 17 00:00:00 2001 From: YAN Wenkun Date: Fri, 26 Jul 2024 02:48:10 +0800 Subject: [PATCH] Add 'comfy3d-pt22' --- .github/workflows/build-comfy3d-pt22.yml | 46 +++++++++++ comfy3d-pt22/Dockerfile | 76 +++++++++++++++++++ comfy3d-pt22/runner-scripts/download.sh | 45 +++++++++++ comfy3d-pt22/runner-scripts/entrypoint.sh | 52 +++++++++++++ .../runner-scripts/pre-start.sh.example | 4 + .../runner-scripts/set-proxy.sh.example | 22 ++++++ 6 files changed, 245 insertions(+) create mode 100644 .github/workflows/build-comfy3d-pt22.yml create mode 100644 comfy3d-pt22/Dockerfile create mode 100644 comfy3d-pt22/runner-scripts/download.sh create mode 100644 comfy3d-pt22/runner-scripts/entrypoint.sh create mode 100644 comfy3d-pt22/runner-scripts/pre-start.sh.example create mode 100644 comfy3d-pt22/runner-scripts/set-proxy.sh.example diff --git a/.github/workflows/build-comfy3d-pt22.yml b/.github/workflows/build-comfy3d-pt22.yml new file mode 100644 index 0000000..5610a13 --- /dev/null +++ b/.github/workflows/build-comfy3d-pt22.yml @@ -0,0 +1,46 @@ +name: Publish 'comfy3d-pt22' to Docker Hub + +on: + workflow_dispatch: # Can be manually triggered + +jobs: + + build-publish-comfy3d-pt22: + environment: Publish to Docker Hub + runs-on: ubuntu-latest + steps: + - + name: Get current date + id: date + run: echo "date=$(date +'%Y%m%d')" >> $GITHUB_OUTPUT + - + name: Maximize build disk space + uses: easimon/maximize-build-space@master + with: + overprovision-lvm: 'true' + remove-android: 'true' + - + name: Git checkout + uses: actions/checkout@v4 + - + name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - + name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_ACCESSTOKEN }} + - + name: Build and push 'comfy3d-pt22' + uses: docker/build-push-action@v6 + with: + context: ./comfy3d-pt22 + file: ./comfy3d-pt22/Dockerfile + tags: | + yanwk/comfyui-boot:comfy3d-pt22 + yanwk/comfyui-boot:comfy3d-pt22-${{ steps.date.outputs.date }} + push: true diff --git a/comfy3d-pt22/Dockerfile b/comfy3d-pt22/Dockerfile new file mode 100644 index 0000000..14c94a5 --- /dev/null +++ b/comfy3d-pt22/Dockerfile @@ -0,0 +1,76 @@ +################################################################################ +# Dockerfile that builds 'yanwk/comfyui-boot:comfy3d-pt22' +# An environment for running ComfyUI with ComfyUI-3D-Pack. +# Using PyTorch 2.2 +# Comfy3D Version: https://github.com/MrForExample/ComfyUI-3D-Pack/tree/3b4e715939376634c68aa4c1c7d4ea4a8665c098 +################################################################################ + +# https://gitlab.com/nvidia/container-images/cuda +# https://catalog.ngc.nvidia.com/orgs/nvidia/containers/cuda/tags +FROM nvcr.io/nvidia/cuda:12.1.1-cudnn8-devel-ubi9 + +LABEL maintainer="YAN Wenkun " + +################################################################################ +# Python and tools +# GCC 11 & Make is already included in the base image. + +RUN --mount=type=cache,target=/var/cache/dnf \ + set -eu \ + && dnf upgrade -y --disablerepo cuda \ + && dnf install -y \ +python3.11-devel \ +python3.11-pip \ +python3.11-Cython \ +python3.11-numpy \ +python3.11-requests \ +python3.11-scipy \ +python3.11-urllib3 \ +git \ +git-lfs \ +less \ +mesa-libGL \ +mesa-libEGL \ + && update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 100 \ + && update-alternatives --install /usr/bin/pip pip /usr/bin/pip3.11 100 + +################################################################################ +# Python Packages +# Comfy3D doesn't use ONNX Runtime, so this image skipped it. + +RUN --mount=type=cache,target=/root/.cache/pip \ + pip list \ + && pip install \ + --upgrade pip wheel setuptools \ + && pip install \ + xformers==0.0.25.post1 torchvision torchaudio \ + --index-url https://download.pytorch.org/whl/cu121 \ + --extra-index-url https://pypi.org/simple \ + && pip install \ + -r https://raw.githubusercontent.com/comfyanonymous/ComfyUI/master/requirements.txt \ + -r https://raw.githubusercontent.com/ltdrdata/ComfyUI-Manager/main/requirements.txt \ + -r https://raw.githubusercontent.com/MrForExample/ComfyUI-3D-Pack/3b4e715939376634c68aa4c1c7d4ea4a8665c098/requirements.txt \ + && pip install \ + https://github.com/YanWenKun/ComfyUI-3D-Pack-LinuxWheels/releases/download/v2/diff_gaussian_rasterization-0.0.0-cp311-cp311-linux_x86_64.whl \ + https://github.com/YanWenKun/ComfyUI-3D-Pack-LinuxWheels/releases/download/v2/kiui-0.2.7-py3-none-any.whl \ + https://github.com/YanWenKun/ComfyUI-3D-Pack-LinuxWheels/releases/download/v2/nvdiffrast-0.3.1-py3-none-any.whl \ + https://github.com/YanWenKun/ComfyUI-3D-Pack-LinuxWheels/releases/download/v2/pointnet2_ops-3.0.0-cp311-cp311-linux_x86_64.whl \ + https://github.com/YanWenKun/ComfyUI-3D-Pack-LinuxWheels/releases/download/v2/pytorch3d-0.7.6-cp311-cp311-linux_x86_64.whl \ + https://github.com/YanWenKun/ComfyUI-3D-Pack-LinuxWheels/releases/download/v2/simple_knn-0.0.0-cp311-cp311-linux_x86_64.whl \ + https://github.com/YanWenKun/ComfyUI-3D-Pack-LinuxWheels/releases/download/v2/torch_scatter-2.1.2-cp311-cp311-linux_x86_64.whl \ + https://github.com/YanWenKun/ComfyUI-3D-Pack-LinuxWheels/releases/download/v2/torchmcubes-0.1.0-cp311-cp311-linux_x86_64.whl \ + && pip list + +################################################################################ + +RUN du -ah /root \ + && rm -rf /root/* /root/.* + +COPY runner-scripts/. /runner-scripts/ + +USER root +VOLUME /root +WORKDIR /root +EXPOSE 8188 +ENV CLI_ARGS="" +CMD ["bash","/runner-scripts/entrypoint.sh"] diff --git a/comfy3d-pt22/runner-scripts/download.sh b/comfy3d-pt22/runner-scripts/download.sh new file mode 100644 index 0000000..5a87194 --- /dev/null +++ b/comfy3d-pt22/runner-scripts/download.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +set -euo pipefail + +# Regex that matches REPO_NAME +# First from pattern [https://example.com/xyz/REPO_NAME.git] or [git@example.com:xyz/REPO_NAME.git] +# Second from pattern [http(s)://example.com/xyz/REPO_NAME] +# They all extract REPO_NAME to BASH_REMATCH[2] +function clone_or_pull () { + if [[ $1 =~ ^(.*[/:])(.*)(\.git)$ ]] || [[ $1 =~ ^(http.*\/)(.*)$ ]]; then + echo "${BASH_REMATCH[2]}" ; + set +e ; + git clone --depth=1 --no-tags --recurse-submodules --shallow-submodules "$1" \ + || git -C "${BASH_REMATCH[2]}" pull --ff-only ; + set -e ; + else + echo "[ERROR] Invalid URL: $1" ; + return 1 ; + fi ; +} + + +echo "########################################" +echo "[INFO] Downloading ComfyUI & Manager..." +echo "########################################" + +cd /root +clone_or_pull https://github.com/comfyanonymous/ComfyUI.git + +cd /root/ComfyUI/custom_nodes +clone_or_pull https://github.com/ltdrdata/ComfyUI-Manager.git + + +echo "########################################" +echo "[INFO] Downloading Custom Nodes..." +echo "########################################" + +cd /root/ComfyUI/custom_nodes + +clone_or_pull https://github.com/MrForExample/ComfyUI-3D-Pack.git +git -C ComfyUI-3D-Pack reset --hard 3b4e715939376634c68aa4c1c7d4ea4a8665c098 + + +# Finish +touch /root/.download-complete diff --git a/comfy3d-pt22/runner-scripts/entrypoint.sh b/comfy3d-pt22/runner-scripts/entrypoint.sh new file mode 100644 index 0000000..6df2172 --- /dev/null +++ b/comfy3d-pt22/runner-scripts/entrypoint.sh @@ -0,0 +1,52 @@ +#!/bin/bash + +set -e + +# Run user's set-proxy script +cd /root +if [ ! -f "/root/user-scripts/set-proxy.sh" ] ; then + mkdir -p /root/user-scripts + cp /runner-scripts/set-proxy.sh.example /root/user-scripts/set-proxy.sh +else + echo "[INFO] Running set-proxy script..." + + chmod +x /root/user-scripts/set-proxy.sh + source /root/user-scripts/set-proxy.sh +fi ; + +# Install ComfyUI +cd /root +if [ ! -f "/root/.download-complete" ] ; then + chmod +x /runner-scripts/download.sh + bash /runner-scripts/download.sh +fi ; + +# Run user's pre-start script +cd /root +if [ ! -f "/root/user-scripts/pre-start.sh" ] ; then + mkdir -p /root/user-scripts + cp /runner-scripts/pre-start.sh.example /root/user-scripts/pre-start.sh +else + echo "[INFO] Running pre-start script..." + + chmod +x /root/user-scripts/pre-start.sh + source /root/user-scripts/pre-start.sh +fi ; + + +echo "########################################" +echo "[INFO] Starting ComfyUI..." +echo "########################################" + +# Let .pyc files be stored in one place +export PYTHONPYCACHEPREFIX="/root/.cache/pycache" +# Let PIP install packages to /root/.local +export PIP_USER=true +# Add above to PATH +export PATH="${PATH}:/root/.local/bin" +# Suppress [WARNING: Running pip as the 'root' user] +export PIP_ROOT_USER_ACTION=ignore + +cd /root + +python3 ./ComfyUI/main.py --listen --port 8188 ${CLI_ARGS} diff --git a/comfy3d-pt22/runner-scripts/pre-start.sh.example b/comfy3d-pt22/runner-scripts/pre-start.sh.example new file mode 100644 index 0000000..dba55bb --- /dev/null +++ b/comfy3d-pt22/runner-scripts/pre-start.sh.example @@ -0,0 +1,4 @@ +#!/bin/bash +set -eu + +echo "[INFO] Continue without pre-start script." diff --git a/comfy3d-pt22/runner-scripts/set-proxy.sh.example b/comfy3d-pt22/runner-scripts/set-proxy.sh.example new file mode 100644 index 0000000..8801050 --- /dev/null +++ b/comfy3d-pt22/runner-scripts/set-proxy.sh.example @@ -0,0 +1,22 @@ +#!/bin/bash +set -eu + +# Tip: Within containers, you cannot access your host machine via 127.0.0.1. +# You will need "host.docker.internal"(for Docker) or "host.containers.internal"(for Podman) + +# Example of setting proxy +#export HTTP_PROXY=http://host.docker.internal:1081 +#export HTTPS_PROXY=$HTTP_PROXY +#export http_proxy=$HTTP_PROXY +#export https_proxy=$HTTP_PROXY +#export NO_PROXY="localhost,*.local,*.internal,[::1],fd00::/7, +#10.0.0.0/8,127.0.0.0/8,169.254.0.0/16,172.16.0.0/12,192.168.0.0/16, +#10.*,127.*,169.254.*,172.16.*,172.17.*,172.18.*,172.19.*,172.20.*, +#172.21.*,172.22.*,172.23.*,172.24.*,172.25.*,172.26.*,172.27.*, +#172.28.*,172.29.*,172.30.*,172.31.*,172.32.*,192.168.*, +#*.cn,ghproxy.com,*.ghproxy.com,ghproxy.org,*.ghproxy.org, +#gh-proxy.com,*.gh-proxy.com,ghproxy.net,*.ghproxy.net" +#export no_proxy=$NO_PROXY +#echo "[INFO] Proxy set to $HTTP_PROXY" + +echo "[INFO] Continue without proxy."