Skip to content

Commit

Permalink
feat: reverse proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
ltdrdata committed Feb 18, 2025
1 parent e0e3ec0 commit ad1b4a9
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 62 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,29 @@ The following settings are applied based on the section marked as `is_default`.
* This option can be used if performance issues occur in a Colab+GDrive environment.
## Environment Variables
The following features can be configured using environment variables:
* **COMFYUI_PATH**: The installation path of ComfyUI
* **GITHUB_ENDPOINT**: Reverse proxy configuration for environments with limited access to GitHub
* **HF_ENDPOINT**: Reverse proxy configuration for environments with limited access to Hugging Face
### Example 1:
Redirecting `https://github.com/ltdrdata/ComfyUI-Impact-Pack` to `https://mirror.ghproxy.com/https://github.com/ltdrdata/ComfyUI-Impact-Pack`
```
GITHUB_ENDPOINT=https://mirror.ghproxy.com/https://github.com
```
#### Example 2:
Changing `https://huggingface.co/path/to/somewhere` to `https://some-hf-mirror.com/path/to/somewhere`
```
HF_ENDPOINT=https://some-hf-mirror.com
```
## Scanner
When you run the `scan.sh` script:
Expand Down
24 changes: 16 additions & 8 deletions glob/git_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
import configparser


GITHUB_ENDPOINT = os.getenv('GITHUB_ENDPOINT')


def is_git_repo(path: str) -> bool:
""" Check if the path is a git repository. """
# NOTE: Checking it through `git.Repo` must be avoided.
Expand Down Expand Up @@ -46,16 +49,21 @@ def git_url(fullpath):

return None


def normalize_url(url) -> str:
url = url.replace("[email protected]:", "https://github.com/")
if url.endswith('.git'):
url = url[:-4]
if 'github' in url or (GITHUB_ENDPOINT is not None and GITHUB_ENDPOINT in url):
author = os.path.basename(os.path.dirname(url))
repo_name = os.path.basename(url)
url = f"https://github.com/{author}/{repo_name}"

return url

def normalize_url_http(url) -> str:
url = url.replace("https://github.com/", "[email protected]:")
if url.endswith('.git'):
url = url[:-4]

return url
def get_url_for_clone(url):
url = normalize_url(url)

if GITHUB_ENDPOINT is not None and url.startswith('https://github.com/'):
url = GITHUB_ENDPOINT + url[18:] # url[18:] -> remove `https://github.com`

return url

92 changes: 39 additions & 53 deletions glob/manager_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
from node_package import InstalledNodePackage


version_code = [3, 23]
version_code = [3, 24]
version_str = f"V{version_code[0]}.{version_code[1]}" + (f'.{version_code[2]}' if len(version_code) > 2 else '')


Expand Down Expand Up @@ -505,6 +505,8 @@ def resolve_node_spec(self, node_name, guess_mode=None):
def resolve_from_path(self, fullpath):
url = git_utils.git_url(fullpath)
if url:
url = git_utils.normalize_url(url)

cnr = self.get_cnr_by_repo(url)
commit_hash = git_utils.get_commit_hash(fullpath)
if cnr:
Expand Down Expand Up @@ -1239,15 +1241,16 @@ def repo_install(self, url, repo_path, instant_execution=False, no_deps=False, r
if url.endswith("/"):
url = url[:-1]
try:
print(f"Download: git clone '{url}'")

# Clone the repository from the remote URL
clone_url = git_utils.get_url_for_clone(url)
print(f"Download: git clone '{clone_url}'")

if not instant_execution and platform.system() == 'Windows':
res = manager_funcs.run_script([sys.executable, git_script_path, "--clone", get_default_custom_nodes_path(), url, repo_path], cwd=get_default_custom_nodes_path())
res = manager_funcs.run_script([sys.executable, git_script_path, "--clone", get_default_custom_nodes_path(), clone_url, repo_path], cwd=get_default_custom_nodes_path())
if res != 0:
return result.fail(f"Failed to clone repo: {url}")
return result.fail(f"Failed to clone repo: {clone_url}")
else:
repo = git.Repo.clone_from(url, repo_path, recursive=True, progress=GitProgress())
repo = git.Repo.clone_from(clone_url, repo_path, recursive=True, progress=GitProgress())
repo.git.clear_cache()
repo.close()

Expand Down Expand Up @@ -2043,12 +2046,14 @@ async def gitclone_install(url, instant_execution=False, msg_prefix='', no_deps=
print(f"CLONE into '{repo_path}'")

# Clone the repository from the remote URL
clone_url = git_utils.get_url_for_clone(url)

if not instant_execution and platform.system() == 'Windows':
res = manager_funcs.run_script([sys.executable, git_script_path, "--clone", get_default_custom_nodes_path(), url, repo_path], cwd=get_default_custom_nodes_path())
res = manager_funcs.run_script([sys.executable, git_script_path, "--clone", get_default_custom_nodes_path(), clone_url, repo_path], cwd=get_default_custom_nodes_path())
if res != 0:
return result.fail(f"Failed to clone '{url}' into '{repo_path}'")
return result.fail(f"Failed to clone '{clone_url}' into '{repo_path}'")
else:
repo = git.Repo.clone_from(url, repo_path, recursive=True, progress=GitProgress())
repo = git.Repo.clone_from(clone_url, repo_path, recursive=True, progress=GitProgress())
repo.git.clear_cache()
repo.close()

Expand Down Expand Up @@ -2973,7 +2978,14 @@ async def restore_snapshot(snapshot_path, git_helper_extras=None):
print("cm-cli: unexpected [0001]")

# for nightly restore
git_info = info.get('git_custom_nodes')
_git_info = info.get('git_custom_nodes')
git_info = {}

# normalize github repo
for k, v in _git_info.items():
norm_k = git_utils.normalize_url(k)
git_info[norm_k] = v

if git_info is not None:
todo_disable = []
todo_enable = []
Expand All @@ -2986,39 +2998,26 @@ async def restore_snapshot(snapshot_path, git_helper_extras=None):

if v[0] == 'nightly' and cnr_repo_map.get(k):
repo_url = cnr_repo_map.get(k)
normalized_url = git_utils.normalize_url(repo_url)

normalized_url1 = git_utils.normalize_url(repo_url)
normalized_url2 = git_utils.normalize_url_http(repo_url)

if normalized_url1 not in git_info and normalized_url2 not in git_info:
if normalized_url not in git_info:
todo_disable.append(k)
else:
if normalized_url1 in git_info:
commit_hash = git_info[normalized_url1]['hash']
todo_checkout.append((v[1], commit_hash))

if normalized_url2 in git_info:
commit_hash = git_info[normalized_url2]['hash']
todo_checkout.append((v[1], commit_hash))
commit_hash = git_info[normalized_url]['hash']
todo_checkout.append((v[1], commit_hash))

for k, v in unified_manager.nightly_inactive_nodes.items():
if 'comfyui-manager' in k:
continue

if cnr_repo_map.get(k):
repo_url = cnr_repo_map.get(k)
normalized_url1 = git_utils.normalize_url(repo_url)
normalized_url2 = git_utils.normalize_url_http(repo_url)

if normalized_url1 in git_info:
commit_hash = git_info[normalized_url1]['hash']
todo_enable.append((k, commit_hash))
processed_urls.append(normalized_url1)
normalized_url = git_utils.normalize_url(repo_url)

if normalized_url2 in git_info:
commit_hash = git_info[normalized_url2]['hash']
if normalized_url in git_info:
commit_hash = git_info[normalized_url]['hash']
todo_enable.append((k, commit_hash))
processed_urls.append(normalized_url2)
processed_urls.append(normalized_url)

for x in todo_disable:
unified_manager.unified_disable(x, False)
Expand Down Expand Up @@ -3071,40 +3070,27 @@ async def restore_snapshot(snapshot_path, git_helper_extras=None):
if repo_url is None:
continue

normalized_url1 = git_utils.normalize_url(repo_url)
normalized_url2 = git_utils.normalize_url_http(repo_url)
normalized_url = git_utils.normalize_url(repo_url)

if normalized_url1 not in git_info and normalized_url2 not in git_info:
if normalized_url not in git_info:
todo_disable.append(k2)
else:
if normalized_url1 in git_info:
commit_hash = git_info[normalized_url1]['hash']
todo_checkout.append((k2, commit_hash))
processed_urls.append(normalized_url1)

if normalized_url2 in git_info:
commit_hash = git_info[normalized_url2]['hash']
todo_checkout.append((k2, commit_hash))
processed_urls.append(normalized_url2)
commit_hash = git_info[normalized_url]['hash']
todo_checkout.append((k2, commit_hash))
processed_urls.append(normalized_url)

for k2, v2 in unified_manager.unknown_inactive_nodes.items():
repo_url = resolve_giturl_from_path(v2[1])

if repo_url is None:
continue

normalized_url1 = git_utils.normalize_url(repo_url)
normalized_url2 = git_utils.normalize_url_http(repo_url)

if normalized_url1 in git_info:
commit_hash = git_info[normalized_url1]['hash']
todo_enable.append((k2, commit_hash))
processed_urls.append(normalized_url1)
normalized_url = git_utils.normalize_url(repo_url)

if normalized_url2 in git_info:
commit_hash = git_info[normalized_url2]['hash']
if normalized_url in git_info:
commit_hash = git_info[normalized_url]['hash']
todo_enable.append((k2, commit_hash))
processed_urls.append(normalized_url2)
processed_urls.append(normalized_url)

for x in todo_disable:
unified_manager.unified_disable(x, True)
Expand Down
1 change: 1 addition & 0 deletions glob/manager_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
aria2 = os.getenv('COMFYUI_MANAGER_ARIA2_SERVER')
HF_ENDPOINT = os.getenv('HF_ENDPOINT')


if aria2 is not None:
secret = os.getenv('COMFYUI_MANAGER_ARIA2_SECRET')
url = urlparse(aria2)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[project]
name = "comfyui-manager"
description = "ComfyUI-Manager provides features to install and manage custom nodes for ComfyUI, as well as various functionalities to assist with ComfyUI."
version = "3.23"
version = "3.24"
license = { file = "LICENSE.txt" }
dependencies = ["GitPython", "PyGithub", "matrix-client==0.4.0", "transformers", "huggingface-hub>0.20", "typer", "rich", "typing-extensions"]

Expand Down

0 comments on commit ad1b4a9

Please sign in to comment.