|
| 1 | +# Dev Container Setup for ComfyStream |
| 2 | + |
| 3 | +This guide will help you set up and run a development container for ComfyStream using Visual Studio Code (VS Code). |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +- [Docker](https://www.docker.com/get-started) |
| 8 | +- [Visual Studio Code](https://code.visualstudio.com/) |
| 9 | +- [VS Code Remote - Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) |
| 10 | + |
| 11 | +## Host Setup |
| 12 | + |
| 13 | +### Clone the Repository |
| 14 | + |
| 15 | +First, clone the `comfystream` repository: |
| 16 | + |
| 17 | +```sh |
| 18 | +git clone https://github.com/yondonfu/comfystream.git |
| 19 | +cd comfystream |
| 20 | +``` |
| 21 | + |
| 22 | +### Download or Build Base Docker Image |
| 23 | + |
| 24 | +The `livepeer/comfyui-base:latest` image provides a ComfyUI workspace for ComfyStream development. You may either pull the base docker image or build it: |
| 25 | + |
| 26 | +- Pull from Dockerhub: |
| 27 | + |
| 28 | +```sh |
| 29 | +docker pull livepeer/comfyui-base:latest |
| 30 | +``` |
| 31 | + |
| 32 | +- Build the base image: |
| 33 | + |
| 34 | +```sh |
| 35 | +docker build -f docker/Dockerfile.base -t livepeer/comfyui-base:latest . |
| 36 | +``` |
| 37 | + |
| 38 | +### Host Configuration |
| 39 | + |
| 40 | +On your **host** system, create directories to store models and engines: |
| 41 | + |
| 42 | +```sh |
| 43 | +mkdir -p ~/models/ComfyUI--models && mkdir -p ~/models/ComfyUI--output |
| 44 | +``` |
| 45 | + |
| 46 | +> [!NOTE] |
| 47 | +> This step should be ran on your host machine before attempting to start the container. |
| 48 | +
|
| 49 | +If you would like to use a different path to store models, open `.devcontainer/devcontainer.json` file and update the `source` to map to the correct paths to your host system. Here is an example configuration: |
| 50 | + |
| 51 | +```json |
| 52 | +{ |
| 53 | + "mounts": [ |
| 54 | + "source=/path/to/your/model-files,target=/ComfyUI/models/ComfyUI--models,type=bind", |
| 55 | + "source=/path/to/your/output-files,target=/ComfyUI/models/ComfyUI--output,type=bind" |
| 56 | + ] |
| 57 | +} |
| 58 | +``` |
| 59 | + |
| 60 | +Replace `/path/to/your/model-files` and `path/to/your/output-files` with the path to your `models` and `output` folders on your host machine. |
| 61 | + |
| 62 | +## Dev Container Setup |
| 63 | + |
| 64 | +1. Open the `comfystream` repository in VS Code. |
| 65 | +2. From VS Code, reload the folder as a devcontainer: |
| 66 | + - Open the Command Palette (`Ctrl+Shift+P` or `Cmd+Shift+P` on macOS). |
| 67 | + - Select `Remote-Containers: Reopen in Container`. |
| 68 | + |
| 69 | +### Download models |
| 70 | + |
| 71 | +From within the **dev container**, download models to run the example workflows: |
| 72 | + |
| 73 | +```sh |
| 74 | +cd /comfystream |
| 75 | +conda activate comfystream |
| 76 | +python src/comfystream/scripts/setup_models.py --workspace /ComfyUI |
| 77 | +``` |
| 78 | + |
| 79 | +For more info about configuring model downloads, see [src/comfystream/scripts/README.md](../src/comfystream/scripts/README.md) |
| 80 | + |
| 81 | +By following these steps, you should be able to set up and run your development container for ComfyStream efficiently. |
| 82 | + |
| 83 | +### Building the DepthAnything Engine |
| 84 | + |
| 85 | +After downloading models, it is necessary to compile TensorRT engines for the example workflow. |
| 86 | + |
| 87 | +> [!NOTE] |
| 88 | +> Engine files must be compiled on the same GPU hardware/architecture that they will be used on. This step must be run manually after starting the devcontainer. You may use either conda environment for this step. |
| 89 | +
|
| 90 | +1. Run the **export_trt.py** script from the directory of the onnx file: |
| 91 | + |
| 92 | + ```sh |
| 93 | + cd /ComfyUI/models/tensorrt/depth-anything |
| 94 | + python /ComfyUI/custom_nodes/ComfyUI-Depth-Anything-Tensorrt/export_trt.py |
| 95 | + ``` |
| 96 | + |
| 97 | +## Debugging ComfyStream and ComfyUI |
| 98 | + |
| 99 | +The `launch.json` includes sample launch configurations for ComfyStream and ComfyUI. |
| 100 | + |
| 101 | +## Setting the Python Environment |
| 102 | + |
| 103 | +Conda is initialized in the bash shell with no environment activated to provide better interoperability with VS Code Shell Integration. |
| 104 | + |
| 105 | +VS Code will automatically activate the `comfystream` environment, unless you change it: |
| 106 | + |
| 107 | +1. From VSCode, press `Ctrl-Shift-P`. |
| 108 | +2. Choose `Python: Select Interpreter`. |
| 109 | +3. Select `comfystream` or `comfyui`. |
| 110 | +4. Open a new terminal, you will see the environment name to the left of the bash terminal. |
| 111 | + |
| 112 | +Alternatively, you may activate an environment manually with `conda activate comfyui` or `conda activate comfystream` |
| 113 | + |
| 114 | +> [!NOTE] For more information, see [Python environments in VS Code](https://code.visualstudio.com/docs/python/environments) |
| 115 | + |
| 116 | +### Starting ComfyUI |
| 117 | + |
| 118 | +Start ComfyUI: |
| 119 | + |
| 120 | +```sh |
| 121 | +cd /comfystream/ComfyUI |
| 122 | +conda activate comfyui |
| 123 | +python main.py --listen |
| 124 | +``` |
| 125 | + |
| 126 | +When using TensorRT engine enabled workflows, you should include the `---disable-cuda-malloc` flag as shown below: |
| 127 | + |
| 128 | +```sh |
| 129 | +cd /comfystream/ComfyUI |
| 130 | +conda activate comfyui |
| 131 | +python main.py --listen --disable-cuda-malloc |
| 132 | +``` |
| 133 | + |
| 134 | +### Starting ComfyStream |
| 135 | + |
| 136 | +Start ComfyStream: |
| 137 | + |
| 138 | +```sh |
| 139 | +cd /comfystream |
| 140 | +conda activate comfystream |
| 141 | +python server/app.py --workspace /ComfyUI --media-ports=5678 --host=0.0.0.0 --port 8888 |
| 142 | +``` |
| 143 | + |
| 144 | +Optionally, you can also start the [ComfyStream UI](../README.md#run-ui) to view the stream: |
| 145 | + |
| 146 | +```sh |
| 147 | +cd /comfystream/ui |
| 148 | +npm run dev:https |
| 149 | +``` |
| 150 | + |
| 151 | +## Additional Resources |
| 152 | + |
| 153 | +- [Developing inside a Container](https://code.visualstudio.com/docs/remote/containers) |
| 154 | +- [Docker Documentation](https://docs.docker.com/) |
0 commit comments