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

workflow: Add workflow for testing/linting #158

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ trim_trailing_whitespace = true
insert_final_newline = true

[Dockerfile*]
indent_style = tab
indent_size = 8
indent_size = 4
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverted this from tab style to space (default)

2 changes: 2 additions & 0 deletions .github/codeql-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
paths-ignore:
- "docker/"
52 changes: 52 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Test project

on:
pull_request:
branches:
- "main"
push:
branches:
- "main"

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
codeql:
name: Perform CodeQL analysis
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: typescript,javascript,python
config-file: ./.github/codeql-config.yaml
build-mode: autobuild

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2

editorconfig:
name: Run editorconfig checker
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4
with:
# Check https://github.com/livepeer/go-livepeer/pull/1891
# for ref value discussion
ref: ${{ github.event.pull_request.head.sha }}

- name: Install editorconfig-checker
uses: editorconfig-checker/action-editorconfig-checker@main

- name: Run editorconfig checker against the repo
run: editorconfig-checker --format github-actions
14 changes: 8 additions & 6 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
import os
import pathlib


def ensure_init_files():
"""Create __init__.py files in comfy/ and comfy_extras/ directories if they don't exist"""
# Go up two levels from custom_nodes/comfystream_inside to reach ComfyUI root
comfy_root = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
base_dirs = ['comfy', 'comfy_extras']
base_dirs = ["comfy", "comfy_extras"]
for base_dir in base_dirs:
base_path = os.path.join(comfy_root, base_dir)
if not os.path.exists(base_path):
continue

# Create __init__.py in the root of base_dir first
root_init = os.path.join(base_path, "__init__.py")
if not os.path.exists(root_init):
with open(root_init, 'w') as f:
with open(root_init, "w") as f:
f.write("")

# Then walk subdirectories
for root, dirs, files in os.walk(base_path):
init_path = os.path.join(root, "__init__.py")
if not os.path.exists(init_path):
with open(init_path, 'w') as f:
with open(init_path, "w") as f:
f.write("")


# Create __init__.py files in ComfyUI directories
ensure_init_files()

Expand All @@ -33,4 +35,4 @@ def ensure_init_files():
# Import and expose node classes
from .nodes import NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS

__all__ = ['NODE_CLASS_MAPPINGS', 'NODE_DISPLAY_NAME_MAPPINGS']
__all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS"]
52 changes: 26 additions & 26 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
ARG BASE_IMAGE=livepeer/comfyui-base:latest
ARG BASE_IMAGE=livepeer/comfyui-base:latest

FROM ${BASE_IMAGE}
FROM ${BASE_IMAGE}

ENV PATH="/workspace/miniconda3/bin:${PATH}" \
NVM_DIR=/root/.nvm \
NODE_VERSION=18.18.0
ENV PATH="/workspace/miniconda3/bin:${PATH}" \
NVM_DIR=/root/.nvm \
NODE_VERSION=18.18.0

RUN echo "Using base image: ${BASE_IMAGE}" && \
apt update && \
apt install -yqq supervisor && \
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
RUN echo "Using base image: ${BASE_IMAGE}" && \
apt update && \
apt install -yqq supervisor && \
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash

WORKDIR /
WORKDIR /

# Install node and npm
RUN bash -c "source $NVM_DIR/nvm.sh && \
nvm install $NODE_VERSION && \
nvm alias default $NODE_VERSION && \
nvm use default"
RUN bash -c "source $NVM_DIR/nvm.sh && \
nvm install $NODE_VERSION && \
nvm alias default $NODE_VERSION && \
nvm use default"

# Add node and npm to path so the commands are available
ENV NODE_PATH="$NVM_DIR/v$NODE_VERSION/lib/node_modules" \
PATH="$NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH"
ENV NODE_PATH="$NVM_DIR/v$NODE_VERSION/lib/node_modules" \
PATH="$NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH"

RUN conda init bash
RUN conda init bash

# Create the supervisor configuration file for ComfyUI and ComfyStream
COPY docker/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY docker/supervisord.conf /etc/supervisor/conf.d/supervisord.conf

WORKDIR /workspace/comfystream
COPY --chmod=0755 docker/entrypoint.sh /workspace/comfystream/docker/entrypoint.sh
WORKDIR /workspace/comfystream
COPY --chmod=0755 docker/entrypoint.sh /workspace/comfystream/docker/entrypoint.sh

EXPOSE 8188
EXPOSE 8889
EXPOSE 3000
EXPOSE 1024-65535/udp
EXPOSE 8188
EXPOSE 8889
EXPOSE 3000
EXPOSE 1024-65535/udp

ENTRYPOINT [ "/workspace/comfystream/docker/entrypoint.sh" ]
ENTRYPOINT [ "/workspace/comfystream/docker/entrypoint.sh" ]

CMD [ "/bin/bash" ]
CMD [ "/bin/bash" ]
51 changes: 33 additions & 18 deletions install.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
import urllib.request
import toml

logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
logging.basicConfig(
level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s"
)
logger = logging.getLogger(__name__)


def get_project_version(workspace: str) -> str:
"""Read project version from pyproject.toml"""
pyproject_path = os.path.join(workspace, "pyproject.toml")
Expand All @@ -22,28 +25,29 @@ def get_project_version(workspace: str) -> str:
except Exception as e:
logger.error(f"Failed to read version from pyproject.toml: {e}")
return "unknown"



def ensure_init_files(workspace: str):
"""Create __init__.py files in comfy/ and comfy_extras/ directories if they don't exist"""
base_dirs = ['comfy', 'comfy_extras']
base_dirs = ["comfy", "comfy_extras"]
for base_dir in base_dirs:
base_path = os.path.join(workspace, base_dir)
if not os.path.exists(base_path):
continue

# Create __init__.py in the root of base_dir first
root_init = os.path.join(base_path, "__init__.py")
if not os.path.exists(root_init):
logger.info(f"Creating {root_init}")
with open(root_init, 'w') as f:
with open(root_init, "w") as f:
f.write("")

# Then walk subdirectories
for root, dirs, files in os.walk(base_path):
init_path = os.path.join(root, "__init__.py")
if not os.path.exists(init_path):
logger.info(f"Creating {init_path}")
with open(init_path, 'w') as f:
with open(init_path, "w") as f:
f.write("")


Expand All @@ -52,14 +56,19 @@ def download_and_extract_ui_files(version: str):

output_dir = os.path.join(os.getcwd(), "nodes", "web")
pathlib.Path(output_dir).mkdir(parents=True, exist_ok=True)
base_url = urllib.parse.urljoin("https://github.com/yondonfu/comfystream/releases/download/", f"v{version}/static.tar.gz")
fallback_url = "https://github.com/yondonfu/comfystream/releases/latest/download/static.tar.gz"

base_url = urllib.parse.urljoin(
"https://github.com/yondonfu/comfystream/releases/download/",
f"v{version}/static.tar.gz",
)
fallback_url = (
"https://github.com/yondonfu/comfystream/releases/latest/download/static.tar.gz"
)

# Create a temporary directory instead of a temporary file
with tempfile.TemporaryDirectory() as temp_dir:
# Define the path for the downloaded file
download_path = os.path.join(temp_dir, "static.tar.gz")

# Download tar.gz file
logger.info(f"Downloading {base_url}")
try:
Expand All @@ -75,23 +84,27 @@ def download_and_extract_ui_files(version: str):
else:
logger.error(f"Error downloading package: {e}")
raise

# Extract contents
try:
logger.info(f"Extracting files to {output_dir}")
with tarfile.open(download_path, 'r:gz') as tar:
with tarfile.open(download_path, "r:gz") as tar:
tar.extractall(path=output_dir)
except Exception as e:
logger.error(f"Error extracting files: {e}")
raise


if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Install custom node requirements")
parser.add_argument(
"--workspace", default=os.environ.get('COMFY_UI_WORKSPACE', None), required=False, help="Set Comfy workspace"
"--workspace",
default=os.environ.get("COMFY_UI_WORKSPACE", None),
required=False,
help="Set Comfy workspace",
)
args = parser.parse_args()

workspace = args.workspace
if workspace is None:
# Look up to 3 directories up for ComfyUI
Expand All @@ -112,14 +125,16 @@ def download_and_extract_ui_files(version: str):
current = os.path.dirname(current)

if workspace is None:
logger.warning("No ComfyUI workspace found. Please specify a valid workspace path to fully install")

logger.warning(
"No ComfyUI workspace found. Please specify a valid workspace path to fully install"
)

if workspace is not None:
logger.info("Ensuring __init__.py files exist in ComfyUI directories...")
ensure_init_files(workspace)
logger.info("Installing custom node requirements...")
subprocess.check_call([sys.executable, "-m", "pip", "install", "-e", "."])

logger.info("Downloading and extracting UI files...")
version = get_project_version(os.getcwd())
download_and_extract_ui_files(version)
Expand Down
Loading
Loading