Skip to content

Commit

Permalink
chore: add docker compose example
Browse files Browse the repository at this point in the history
  • Loading branch information
asai95 committed Dec 23, 2023
1 parent 1407b35 commit b60c2a2
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 0 deletions.
6 changes: 6 additions & 0 deletions examples/docker_compose/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
WHISPER_NAME="openai/whisper-tiny.en"
LOCAL_STORAGE_FOLDER_PATH="/data"
HUEY_BUS_REDIS_HOST="host.docker.internal"
MODEL="speech_recognition_api.extra.whisper_model.WhisperModel"
STORAGE="speech_recognition_api.extra.local_storage.LocalStorage"
MESSAGE_BUS="speech_recognition_api.extra.huey_bus.HueyMessageBus"
23 changes: 23 additions & 0 deletions examples/docker_compose/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM python:3.11-slim as base

RUN apt-get update && apt-get install -y ffmpeg
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt --extra-index-url https://download.pytorch.org/whl/cpu

FROM base as api
CMD [ \
"gunicorn", \
"speech_recognition_api:create_app()", \
"-k", \
"uvicorn.workers.UvicornWorker", \
"-w", \
"1", \
"-b", \
"0.0.0.0:8888" \
]

FROM base as worker
CMD [ \
"huey_consumer", \
"speech_recognition_api.extra.huey_bus.huey" \
]
17 changes: 17 additions & 0 deletions examples/docker_compose/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## Docker Compose example

This example demonstrates one of the ways to build containers:
API server and async worker.

In this example they communicate using Huey and Redis, saving data to
a local folder.

### Running the example

```bash
docker compose up
```

The service is going to be available at http://localhost:8888

You can visit http://localhost:8888/docs to try it right in your browser.
34 changes: 34 additions & 0 deletions examples/docker_compose/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
version: "3.8"
services:
api:
env_file:
- .env.example
build:
context: .
dockerfile: Dockerfile
target: api
volumes:
- "./data:/data"
ports:
- "8888:8888"
depends_on:
redis:
condition: service_started
worker:
env_file:
- .env.example
build:
context: .
dockerfile: Dockerfile
target: worker
volumes:
- "./data:/data"
depends_on:
api:
condition: service_started
redis:
condition: service_started
redis:
image: redis
ports:
- "6379:6379"
3 changes: 3 additions & 0 deletions examples/docker_compose/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
speech-recognition-api[whisper,huey]
redis
gunicorn

0 comments on commit b60c2a2

Please sign in to comment.