Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example of custom paths in Compose #6

Closed
wants to merge 1 commit into from

Conversation

chaudharydeepanshu
Copy link

@chaudharydeepanshu chaudharydeepanshu commented Jan 13, 2025

Updated the README with optional mappings for models, workflows, and outputs. This helps new Docker users set custom paths, allowing safe container reset(by deleting run folder) without losing important files.

Also, thanks for creating the docker image ⭐.

@mmartial
Copy link
Owner

Thanks for the idea, but unfortunately, this does not work on a fresh run.
First, any directory added must be manually created by the WANTED_UID:GID user. This is already partially documented; as such, we could work around this.

The real issue is that mounting a volume into /comfy/mnt/ComfyUI creates that directory. Therefore, the init script will not download the installer from git, which causes the rest of the script to fail.
I had tried a similar approach in the original version of the container, but after trying a few workarounds, was not comfortable with the resulting solution. Therefore, in the current container version, I decided to avoid the risk of users mounting folders that could cause the issue.

To test the described behavior, try the compose.yaml in a directory with no content. First, run mkdir run models workflows output as the WANTED_UID:GID user. You will encounter the issue that occurs when the initialization script attempts to install ComfyUI from git.

comfyui-nvidia-comp  | == Installing/Updating from ComfyUI's requirements
comfyui-nvidia-comp  | ERROR: Could not open requirements file: [Errno 2] No such file or directory: 'requirements.txt'
comfyui-nvidia-comp  | ComfyUI requirements install/upgrade failed

@chaudharydeepanshu
Copy link
Author

Yes, you are right about that. Sorry, I missed that.

What if we modify the initialization to first check if the ComfyUI directory exists, and if it exists we check if the requirements.txt file is present within it? If the file is missing, we can clone the repository into a temporary directory, and copy its contents to the ComfyUI directory.

Something like below in the init.bash:

# Obtain the latest version of ComfyUI if not already present
cd ${COMFYUSER_DIR}/mnt
if [ ! -d "ComfyUI" ]; then
  echo "== Cloning ComfyUI"
  git clone https://github.com/comfyanonymous/ComfyUI.git ComfyUI || error_exit "ComfyUI clone failed"
else
  # If ComfyUI dir is present but does not contain a requirements.txt file.
  if [ ! -f "ComfyUI/requirements.txt" ]; then
    echo "== Cloning ComfyUI"
    mkdir comfyUITemp || error_exit "Failed to create comfyUITemp folder"
    git clone https://github.com/comfyanonymous/ComfyUI.git comfyUITemp || error_exit "ComfyUI clone failed"
    shopt -s dotglob 
    cp -r comfyUITemp/* ComfyUI || error_exit "Failed to copy files from comfyUITemp to ComfyUI"
    shopt -u dotglob 
    rm -rf comfyUITemp || error_exit "Failed to remove comfyUITemp folder"
  else
    echo "== ComfyUI directory already exists and is up-to-date."
  fi
fi

I tried this approach and it works.

@mmartial
Copy link
Owner

I have finished a new release, so I will continue to investigate how to integrate this proposed solution. I am trying to make sure that none of those bind mounts will create issues with the manager trying to update Comfy, for example.

@mmartial
Copy link
Owner

I'm sorry for the delay.

There might be a solution in the CLI: use the --base-directory CLI option
https://github.com/comfyanonymous/ComfyUI/blob/master/comfy/cli_args.py#L46

I still would like to add some rsync pre-process --in case the content already exists and try to avoid erasing content.

@mmartial
Copy link
Owner

This is not a valid CLI option.

-- Running: python3 ./main.py --listen 0.0.0.0 --disable-auto-launch  --base-directory /basedir
usage: main.py [-h] [...]
[...]
main.py: error: unrecognized arguments: --base-directory /basedir

An alternate solution will have me look at:

  [--extra-model-paths-config PATH [PATH ...]]
  [--output-directory OUTPUT_DIRECTORY]
  [--temp-directory TEMP_DIRECTORY] 
  [--input-directory INPUT_DIRECTORY]
  [--user-directory USER_DIRECTORY]

@mmartial
Copy link
Owner

mmartial commented Jan 31, 2025

My test Comfy installation is older than 5 days ... when this option was added
comfyanonymous/ComfyUI#6600

@mmartial
Copy link
Owner

@mmartial
Copy link
Owner

mmartial commented Feb 3, 2025

Integrated the BASE_DIRECTORY environment variable into the container and made a new release.
Closing since this solution provides the requested feature.

@mmartial mmartial closed this Feb 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants