From 34eb32b72455e6e628849e50405ed172d846d2d9 Mon Sep 17 00:00:00 2001 From: NERDDISCO <492378+TimPietrusky@users.noreply.github.com> Date: Mon, 12 Feb 2024 16:43:22 +0100 Subject: [PATCH] feat: run the worker locally (#19) * feat: provide option to run the handler locally as API * ci: run the workflow on our extended instance * feat: the local API should run on 0.0.0.0 * ci: use semantic-release to create releases automatically --- .github/workflows/dev.yml | 4 +- .../{docker-release.yml => release.yml} | 41 +++++++++++++++---- docker-compose.yml | 7 ++-- src/start.sh | 8 +++- 4 files changed, 45 insertions(+), 15 deletions(-) rename .github/workflows/{docker-release.yml => release.yml} (57%) diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml index 3aefec8..1c8f904 100644 --- a/.github/workflows/dev.yml +++ b/.github/workflows/dev.yml @@ -8,7 +8,7 @@ on: jobs: dev: - runs-on: ubuntu-latest + runs-on: ubuntu-latest-m steps: - name: Checkout uses: actions/checkout@v3 @@ -49,5 +49,3 @@ jobs: push: true tags: | ${{ secrets.DOCKERHUB_REPO }}/${{ secrets.DOCKERHUB_IMG }}:dev - - diff --git a/.github/workflows/docker-release.yml b/.github/workflows/release.yml similarity index 57% rename from .github/workflows/docker-release.yml rename to .github/workflows/release.yml index 3162d56..34a9d26 100644 --- a/.github/workflows/docker-release.yml +++ b/.github/workflows/release.yml @@ -1,12 +1,20 @@ -name: CD | Release Docker Image +name: Release on: - release: - types: [published] + workflow_dispatch: + push: + branches: + - "main" jobs: - docker: + release: runs-on: ubuntu-latest + if: ${{ !contains(github.event.head_commit.message, 'chore(release)') }} + permissions: + contents: write # to be able to publish a GitHub release + issues: write # to be able to comment on released issues + pull-requests: write # to be able to comment on released pull requests + steps: - name: Checkout uses: actions/checkout@v3 @@ -41,17 +49,34 @@ jobs: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Build and push + - name: Update the ToC in the README.md + run: npx markdown-toc README.md -i + + - name: Semantic release + uses: codfish/semantic-release-action@v3 + id: semanticrelease + with: + additional-packages: | + ['@semantic-release/git', '@semantic-release/changelog'] + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Build image and push it to Docker Hub + if: steps.semanticrelease.outputs.new-release-published == 'true' uses: docker/build-push-action@v5 with: push: true tags: | - ${{ secrets.DOCKERHUB_REPO }}/${{ secrets.DOCKERHUB_IMG }}:${{ github.event.release.tag_name }} + ${{ secrets.DOCKERHUB_REPO }}/${{ secrets.DOCKERHUB_IMG }}:${{ steps.semanticrelease.outputs.release-version }} ${{ secrets.DOCKERHUB_REPO }}/${{ secrets.DOCKERHUB_IMG }}:latest - - - name: Docker Hub Description + + - name: Update description on Docker Hub + if: steps.semanticrelease.outputs.new-release-published == 'true' uses: peter-evans/dockerhub-description@v3 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} repository: ${{ secrets.DOCKERHUB_REPO }}/${{ secrets.DOCKERHUB_IMG }} + + + diff --git a/docker-compose.yml b/docker-compose.yml index 57c7e74..37352a3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,12 +2,13 @@ version: "3.8" services: comfyui: - image: timpietruskyblibla/runpod-worker-comfy:1.0.0 + image: timpietruskyblibla/runpod-worker-comfy:latest container_name: comfyui-worker environment: - NVIDIA_VISIBLE_DEVICES=all - env_file: - - .env + - SERVE_API_LOCALLY=true + ports: + - "8000:8000" runtime: nvidia volumes: - ./data/comfyui/output:/comfyui/output diff --git a/src/start.sh b/src/start.sh index 4d922c0..b55df3d 100644 --- a/src/start.sh +++ b/src/start.sh @@ -8,4 +8,10 @@ echo "runpod-worker-comfy: Starting ComfyUI" python3 /comfyui/main.py --disable-auto-launch --disable-metadata & echo "runpod-worker-comfy: Starting RunPod Handler" -python3 -u /rp_handler.py \ No newline at end of file + +# Serve the API and don't shutdown the container +if [ "$SERVE_API_LOCALLY" == "true" ]; then + python3 -u /rp_handler.py --rp_serve_api --rp_api_host=0.0.0.0 +else + python3 -u /rp_handler.py +fi \ No newline at end of file