Skip to content

Commit

Permalink
Merge pull request #1 from livepeer/feature/docker-builds
Browse files Browse the repository at this point in the history
workflows: Automating docker image build pipeline
  • Loading branch information
hjpotter92 authored Mar 4, 2025
2 parents 342e302 + 4dbbd13 commit 258afb8
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 73 deletions.
11 changes: 6 additions & 5 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
**/__pycache__
**/*.pyc
**/*.pyo
**/*.pyd
.git
**/*.py[cod]
.env
.venv
.git/
.venv/
.github/
ui/node_modules/
.dockerignore
71 changes: 71 additions & 0 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Docker build and push images

on:
pull_request:
branches:
- main
push:
branches:
- main
tags:
- "v*"

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

jobs:
build:
name: docker builds
permissions:
packages: write
contents: read
runs-on: [self-hosted, linux, amd64]
steps:
- name: Check out code
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}

- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.CI_DOCKERHUB_USERNAME }}
password: ${{ secrets.CI_DOCKERHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ github.repository }}
tags: |
type=sha
type=ref,event=pr
type=ref,event=tag
type=sha,format=long
type=ref,event=branch
type=semver,pattern={{version}},prefix=v
type=semver,pattern={{major}}.{{minor}},prefix=v
type=raw,value=latest,enable={{is_default_branch}}
type=raw,value=${{ github.event.pull_request.head.ref }}
type=raw,value=stable,enable=${{ startsWith(github.event.ref, 'refs/tags/v') }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build and push livepeer docker image
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
file: docker/Dockerfile
labels: ${{ steps.meta.outputs.labels }}
annotations: ${{ steps.meta.outputs.annotations }}
cache-from: type=registry,ref=${{ github.repository }}:build-cache
cache-to: type=registry,mode=max,ref=${{ github.repository }}:build-cache

- name: Notify new build upload
run: curl -X POST https://holy-bread-207a.livepeer.workers.dev
3 changes: 1 addition & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,14 @@ jobs:
env:
"NEXT_PUBLIC_DEV": "false"
run: |
dist_file_suffix="${{ github.ref_type == 'tag' && github.ref_name || github.event.pull_request.head.sha || github.sha }}"
mkdir -p releases/
cur_dir="$(pwd)"
cd ui/
npm ci
npm run build
dist_dir="../nodes/web/static/"
cd "$dist_dir"
dist_file_full="${cur_dir}/releases/comfystream-uikit-${dist_file_suffix}.zip"
dist_file_full="${cur_dir}/releases/comfystream-uikit.zip"
zip -DTr9q "${dist_file_full}" ./
echo "dist_file=${dist_file_full}" >> $GITHUB_OUTPUT
cd -
Expand Down
59 changes: 30 additions & 29 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,40 +1,41 @@
ARG BASE_IMAGE=livepeer/comfyui-base:latest
FROM ${BASE_IMAGE}
ARG BASE_IMAGE=livepeer/comfyui-base:latest

RUN echo "Using base image: ${BASE_IMAGE}"
FROM ${BASE_IMAGE}

ENV PATH="/workspace/miniconda3/bin:${PATH}"
EXPOSE 8188
EXPOSE 8889
EXPOSE 3000
EXPOSE 1024-65535/udp
RUN apt-get update && apt-get install -y supervisor
ENV PATH="/workspace/miniconda3/bin:${PATH}" \
NVM_DIR=/root/.nvm \
NODE_VERSION=18.18.0

WORKDIR /
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

# Install NVM
ENV NVM_DIR=/root/.nvm
ENV NODE_VERSION=18.18.0
RUN wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
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
ENV PATH=$NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH
RUN conda init bash
ENV NODE_PATH="$NVM_DIR/v$NODE_VERSION/lib/node_modules" \
PATH="$NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH"

# Create the supervisor configuration file for ComfyUI and ComfyStream
RUN mkdir -p /etc/supervisor/conf.d
COPY docker/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
RUN conda init bash

WORKDIR /workspace/comfystream
COPY docker/entrypoint.sh /workspace/comfystream/docker/entrypoint.sh
RUN chmod +x /workspace/comfystream/docker/entrypoint.sh
# Create the supervisor configuration file for ComfyUI and ComfyStream
COPY docker/supervisord.conf /etc/supervisor/conf.d/supervisord.conf

ENTRYPOINT ["/workspace/comfystream/docker/entrypoint.sh"]
CMD ["/bin/bash"]
WORKDIR /workspace/comfystream
COPY --chmod=0755 docker/entrypoint.sh /workspace/comfystream/docker/entrypoint.sh

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

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

CMD [ "/bin/bash" ]
76 changes: 39 additions & 37 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,74 +1,76 @@
#!/bin/bash

set -e
eval "$(conda shell.bash hook)"

# Handle workspace mounting
if [ -d "/app" ] && [ ! -d "/app/miniconda3" ]; then
echo "Initializing workspace in /app..."
cp -r /workspace/* /app
echo "Initializing workspace in /app..."
cp -r /workspace/* /app
fi

if [ -d "/app" ] && [ ! -L "/workspace" ]; then
echo "Starting from volume mount /app..."
cd / && rm -rf /workspace
ln -sf /app /workspace
cd /workspace/comfystream
echo "Starting from volume mount /app..."
cd / && rm -rf /workspace
ln -sf /app /workspace
cd /workspace/comfystream
fi

# Add help command to show usage
show_help() {
echo "Usage: entrypoint.sh [OPTIONS]"
echo ""
echo "Options:"
echo " --download-models Download default models"
echo " --build-engines Build TensorRT engines for default models"
echo " --server Start the Comfystream server, UI and ComfyUI"
echo " --help Show this help message"
echo ""
echo "Usage: entrypoint.sh [OPTIONS]"
echo ""
echo "Options:"
echo " --download-models Download default models"
echo " --build-engines Build TensorRT engines for default models"
echo " --server Start the Comfystream server, UI and ComfyUI"
echo " --help Show this help message"
echo ""
}

if [ "$1" = "--help" ]; then
show_help
exit 0
show_help
exit 0
fi

if [ "$1" = "--download-models" ]; then
cd /workspace/comfystream
conda activate comfystream
python src/comfystream/scripts/setup_models.py --workspace /workspace/ComfyUI
shift
cd /workspace/comfystream
conda activate comfystream
python src/comfystream/scripts/setup_models.py --workspace /workspace/ComfyUI
shift
fi

DEPTH_ANYTHING_DIR="/workspace/ComfyUI/models/tensorrt/depth-anything"

if [ "$1" = "--build-engines" ]; then
cd /workspace/comfystream
conda activate comfystream
cd /workspace/comfystream
conda activate comfystream

# Build Static Engine for Dreamshaper
python src/comfystream/scripts/build_trt.py --model /workspace/ComfyUI/models/unet/dreamshaper-8-dmd-1kstep.safetensors --out-engine /workspace/ComfyUI/output/tensorrt/static-dreamshaper8_SD15_\$stat-b-1-h-512-w-512_00001_.engine
# Build Static Engine for Dreamshaper
python src/comfystream/scripts/build_trt.py --model /workspace/ComfyUI/models/unet/dreamshaper-8-dmd-1kstep.safetensors --out-engine /workspace/ComfyUI/output/tensorrt/static-dreamshaper8_SD15_\$stat-b-1-h-512-w-512_00001_.engine

# Build Engine for DepthAnything2
if [ ! -f "$DEPTH_ANYTHING_DIR/depth_anything_vitl14-fp16.engine" ]; then
if [ ! -d "$DEPTH_ANYTHING_DIR" ]; then
mkdir -p "$DEPTH_ANYTHING_DIR"
fi
cd "$DEPTH_ANYTHING_DIR"
python /workspace/ComfyUI/custom_nodes/ComfyUI-Depth-Anything-Tensorrt/export_trt.py
else
echo "Engine for DepthAnything2 already exists, skipping..."
# Build Engine for DepthAnything2
if [ ! -f "$DEPTH_ANYTHING_DIR/depth_anything_vitl14-fp16.engine" ]; then
if [ ! -d "$DEPTH_ANYTHING_DIR" ]; then
mkdir -p "$DEPTH_ANYTHING_DIR"
fi
shift
cd "$DEPTH_ANYTHING_DIR"
python /workspace/ComfyUI/custom_nodes/ComfyUI-Depth-Anything-Tensorrt/export_trt.py
else
echo "Engine for DepthAnything2 already exists, skipping..."
fi
shift
fi

# Install npm packages if needed
cd /workspace/comfystream/ui
if [ ! -d "node_modules" ]; then
npm install --legacy-peer-deps
npm install --legacy-peer-deps
fi

if [ "$1" = "--server" ]; then
/usr/bin/supervisord -c /etc/supervisor/supervisord.conf
shift
/usr/bin/supervisord -c /etc/supervisor/supervisord.conf
shift
fi

cd /workspace/comfystream
Expand Down

0 comments on commit 258afb8

Please sign in to comment.