From 56018e39f807213461abf80aea430d9c1f9324a1 Mon Sep 17 00:00:00 2001 From: Joseph Hanson Date: Fri, 2 Aug 2024 21:45:15 -0500 Subject: [PATCH] v2 --- .envrc | 1 + .gitignore | 1 + .taskfiles/docker/Taskfile.yaml | 12 ++++++++++ Dockerfile-chainguard | 39 +++++++++++++++++++++++++++++++++ README.md | 14 ++++++++++++ Taskfile.yaml | 9 ++++++++ entrypoint.sh | 2 +- shell.nix | 12 ++++++++++ 8 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 .envrc create mode 100644 .gitignore create mode 100644 .taskfiles/docker/Taskfile.yaml create mode 100644 Dockerfile-chainguard create mode 100644 README.md create mode 100644 Taskfile.yaml create mode 100644 shell.nix diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..65326bb --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use nix \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ff51edf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.direnv \ No newline at end of file diff --git a/.taskfiles/docker/Taskfile.yaml b/.taskfiles/docker/Taskfile.yaml new file mode 100644 index 0000000..f57b4e2 --- /dev/null +++ b/.taskfiles/docker/Taskfile.yaml @@ -0,0 +1,12 @@ +--- +version: "3" + +tasks: + build: + desc: Build docker container + cmds: + - docker build -f Dockerfile-chainguard -t comfyui . + run: + desc: Run docker container + cmds: + - docker run -it --entrypoint /bin/bash comfyui diff --git a/Dockerfile-chainguard b/Dockerfile-chainguard new file mode 100644 index 0000000..e495acb --- /dev/null +++ b/Dockerfile-chainguard @@ -0,0 +1,39 @@ +# Stage 1: Build +FROM chainguard/python:latest-dev AS builder +# 2.3.0-cuda12.1-cudnn8-runtime AS builder +# FROM cgr.dev/chainguard/pytorch-cuda12:latest AS builder +ARG TAG_VERSION=v0.0.2 +USER root +ENV ROOT=/app +WORKDIR ${ROOT} +RUN mkdir -p /nonroot/.cache/pip +RUN --mount=type=cache,target=/nonroot/.cache/pip \ + git clone https://github.com/comfyanonymous/ComfyUI.git ${ROOT} && \ + cd ${ROOT} && \ + git checkout ${TAG_VERSION} && \ + pip install -r requirements.txt + +COPY . ${ROOT} +RUN chown -R nonroot.nonroot /app/ +RUN chown -R nonroot.nonroot /nonroot/ +RUN chmod u+x entrypoint.sh + +# # Stage 2: Minimal Image +FROM cgr.dev/chainguard/pytorch-cuda12:latest +USER nonroot + +ENV ROOT=/app +WORKDIR ${ROOT} + +# RUN apk add python-${version} +ENV ROOT=/app +ENV NVIDIA_VISIBLE_DEVICES=all PYTHONPATH="${PYTHONPATH}:${ROOT}" CLI_ARGS="" PATH="${PATH}:${ROOT}" + +# Copy the application from the builder stage +COPY --from=builder /app ${ROOT} +# And the pip cache +COPY --from=builder /nonroot /nonroot + +EXPOSE 7860 +ENTRYPOINT ["entrypoint.sh"] +CMD python -u main.py --listen --port 7860 ${CLI_ARGS} \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..c922105 --- /dev/null +++ b/README.md @@ -0,0 +1,14 @@ +# README + +## local dev + +```sh +docker build -f Dockerfile-chainguard -t comfyui . +docker run -it --entrypoint /bin/bash comfyui +``` + +## remote dev + +```sh +docker run -it --entrypoint /bin/bash jahanson/comfyui:latest +``` \ No newline at end of file diff --git a/Taskfile.yaml b/Taskfile.yaml new file mode 100644 index 0000000..222d14e --- /dev/null +++ b/Taskfile.yaml @@ -0,0 +1,9 @@ +--- +version: "3" + +includes: + docker: .taskfiles/docker + +tasks: + default: + cmds: ["task -l"] diff --git a/entrypoint.sh b/entrypoint.sh index 5c59134..d41d1dc 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -6,7 +6,7 @@ mkdir -vp /data/config/comfy/custom_nodes declare -A MOUNTS -MOUNTS["/root/.cache"]="/data/.cache" +MOUNTS["/nonroot/.cache"]="/data/.cache" MOUNTS["${ROOT}/input"]="/data/config/comfy/input" MOUNTS["${ROOT}/output"]="/output/comfy" diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..0215442 --- /dev/null +++ b/shell.nix @@ -0,0 +1,12 @@ +# Shell for bootstrapping flake-enabled nix and home-manager +{pkgs ? import {}}: +pkgs.mkShell { + # Enable experimental features without having to specify the argument + NIX_CONFIG = "experimental-features = nix-command flakes"; + + nativeBuildInputs = with pkgs; [ + lazydocker + pre-commit + go-task + ]; +}