Skip to content

Commit

Permalink
ci: Docker workflow to build and slim images, update README for usage…
Browse files Browse the repository at this point in the history
… instructions
  • Loading branch information
remsky committed Jan 14, 2025
1 parent 2649a0b commit da324b0
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 32 deletions.
65 changes: 43 additions & 22 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Docker Build and Publish
name: Docker Build, Slim, and Publish

on:
push:
Expand Down Expand Up @@ -35,51 +35,72 @@ jobs:
echo "GPU_IMAGE_NAME=${{ env.REGISTRY }}/$(echo ${{ env.IMAGE_NAME }} | tr '[:upper:]' '[:lower:]')-gpu" >> $GITHUB_ENV
echo "CPU_IMAGE_NAME=${{ env.REGISTRY }}/$(echo ${{ env.IMAGE_NAME }} | tr '[:upper:]' '[:lower:]')-cpu" >> $GITHUB_ENV
echo "UI_IMAGE_NAME=${{ env.REGISTRY }}/$(echo ${{ env.IMAGE_NAME }} | tr '[:upper:]' '[:lower:]')-ui" >> $GITHUB_ENV
echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
# Extract version tag if it exists
- name: Set version tag
if: startsWith(github.ref, 'refs/tags/')
run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV

# Build and push GPU version
- name: Build and push GPU Docker image
# Build GPU version
- name: Build GPU Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./docker/gpu/Dockerfile
push: true
tags: |
${{ env.GPU_IMAGE_NAME }}:latest
${{ env.GPU_IMAGE_NAME }}:${{ env.VERSION }}
push: false
load: true
tags: ${{ env.GPU_IMAGE_NAME }}:v0.1.0
build-args: |
DOCKER_BUILDKIT=1
platforms: linux/amd64

# Build and push CPU version
- name: Build and push CPU Docker image
# Slim GPU version
- name: Slim GPU Docker image
uses: kitabisa/docker-slim-action@v1
env:
DSLIM_HTTP_PROBE: false
with:
target: ${{ env.GPU_IMAGE_NAME }}:v0.1.0
tag: v0.1.0-slim

# Push GPU versions
- name: Push GPU Docker images
run: |
docker push ${{ env.GPU_IMAGE_NAME }}:v0.1.0
docker push ${{ env.GPU_IMAGE_NAME }}:v0.1.0-slim
# Build CPU version
- name: Build CPU Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./docker/cpu/Dockerfile
push: true
tags: |
${{ env.CPU_IMAGE_NAME }}:latest
${{ env.CPU_IMAGE_NAME }}:${{ env.VERSION }}
push: false
load: true
tags: ${{ env.CPU_IMAGE_NAME }}:v0.1.0
build-args: |
DOCKER_BUILDKIT=1
platforms: linux/amd64

# Build and push UI version
# Slim CPU version
- name: Slim CPU Docker image
uses: kitabisa/docker-slim-action@v1
env:
DSLIM_HTTP_PROBE: false
with:
target: ${{ env.CPU_IMAGE_NAME }}:v0.1.0
tag: v0.1.0-slim

# Push CPU versions
- name: Push CPU Docker images
run: |
docker push ${{ env.CPU_IMAGE_NAME }}:v0.1.0
docker push ${{ env.CPU_IMAGE_NAME }}:v0.1.0-slim
# Build and push UI version (unchanged)
- name: Build and push UI Docker image
uses: docker/build-push-action@v5
with:
context: ./ui
file: ./ui/Dockerfile
push: true
tags: |
${{ env.UI_IMAGE_NAME }}:latest
${{ env.UI_IMAGE_NAME }}:${{ env.VERSION }}
${{ env.UI_IMAGE_NAME }}:v0.1.0
build-args: |
DOCKER_BUILDKIT=1
platforms: linux/amd64
Expand Down
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Dockerized FastAPI wrapper for [Kokoro-82M](https://huggingface.co/hexgrad/Kokor
The service can be accessed through either the API endpoints or the Gradio web interface.

1. Install prerequisites:
- Install [Docker Desktop](https://www.docker.com/products/docker-desktop/) + [Git](https://git-scm.com/downloads)
- Install [Docker Desktop](https://www.docker.com/products/docker-desktop/)
- Clone the repository:
```bash
git clone https://github.com/remsky/Kokoro-FastAPI.git
Expand All @@ -33,20 +33,20 @@ The service can be accessed through either the API endpoints or the Gradio web i

2. Start the service:

a. Using Docker Compose (recommended for full setup including UI):
- Using Docker Compose (Full setup including UI):
```bash
docker compose up --build # for GPU
#docker compose -f docker-compose.cpu.yml up --build # for CPU
docker compose -f docker-compose.cpu.yml up --build # for CPU
```

b. Running the API alone using Docker:
- OR running the API alone using Docker (model + voice packs baked in):
```bash
# For CPU version
docker run -p 8880:8880 kokoro-fastapi-cpu
# For GPU version (requires NVIDIA Container Toolkit)
docker run --gpus all -p 8880:8880 kokoro-fastapi-gpu
docker run -p 8880:8880 ghcr.io/remsky/kokoro-fastapi-cpu:latest # CPU
docker run --gpus all -p 8880:8880 ghcr.io/remsky/kokoro-fastapi-gpu:latest # Nvidia GPU
# Minified versions are available with `:latest-slim` tag.
```


2. Run locally as an OpenAI-Compatible Speech Endpoint
```python
from openai import OpenAI
Expand Down

0 comments on commit da324b0

Please sign in to comment.