Add Docker deployment support

This commit is contained in:
Dymas
2026-06-06 11:44:30 +02:00
parent 0af80fde24
commit d8b92d5025
5 changed files with 134 additions and 0 deletions
+17
View File
@@ -0,0 +1,17 @@
.git
.gitignore
__pycache__/
*.pyc
*.pyo
*.pyd
.Python
.pytest_cache/
.mypy_cache/
.venv/
venv/
env/
logs/
history/
models/
tmp/
client.png
+27
View File
@@ -0,0 +1,27 @@
FROM python:3.12-slim
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
DEBIAN_FRONTEND=noninteractive \
PIP_NO_CACHE_DIR=1
WORKDIR /app
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
ffmpeg \
sox \
libmagic1 \
&& rm -rf /var/lib/apt/lists/*
COPY requirements.txt ./
RUN pip install --upgrade pip \
&& pip install -r requirements.txt
COPY . .
RUN mkdir -p /app/logs /app/history
EXPOSE 5042
CMD ["python", "server.py", "--config", "config.docker.json"]
+50
View File
@@ -63,6 +63,56 @@ pip install -r requirements.txt
python server.py
```
## Docker
The repository now includes a container setup for running the API in Docker.
### What gets mounted
- `./config.docker.json` -> `/app/config.docker.json`
- `./logs` -> `/app/logs`
- `./history` -> `/app/history`
- `./models` -> `/models`
Place your Whisper model inside `./models/whisper` or update `model_path` in `config.docker.json`.
### Build and run with Docker Compose
```bash
docker compose up --build
```
The API will be available at:
```text
http://localhost:5042
```
### Build and run with plain Docker
```bash
docker build -t whisper-api-server .
docker run --rm -p 5042:5042 \
-v "$(pwd)/config.docker.json:/app/config.docker.json:ro" \
-v "$(pwd)/logs:/app/logs" \
-v "$(pwd)/history:/app/history" \
-v "$(pwd)/models:/models" \
whisper-api-server
```
### GPU note
The container image installs the same Python dependencies as the local setup, including CUDA-oriented PyTorch wheels on Linux x86_64. To actually use NVIDIA GPU acceleration at runtime, start the container with GPU access enabled in your Docker environment, for example:
```bash
docker run --rm --gpus all -p 5042:5042 \
-v "$(pwd)/config.docker.json:/app/config.docker.json:ro" \
-v "$(pwd)/logs:/app/logs" \
-v "$(pwd)/history:/app/history" \
-v "$(pwd)/models:/models" \
whisper-api-server
```
## Configuration
The service is configured through the `config.json` file:
+26
View File
@@ -0,0 +1,26 @@
{
"service_port": 5042,
"model_path": "/models/whisper",
"language": "russian",
"enable_history": true,
"max_history_days": 30,
"chunk_length_s": 28,
"batch_size": 6,
"max_new_tokens": 384,
"temperature": 0.01,
"return_timestamps": false,
"audio_rate": 16000,
"norm_level": "-0.55",
"compand_params": "0.3,1 -90,-90,-70,-50,-40,-15,0,0 -7 0 0.15",
"device_id": 0,
"file_validation": {
"max_file_size_mb": 500,
"allowed_extensions": [".wav", ".mp3", ".ogg", ".flac", ".m4a", ".oga", ".aac", ".webm"],
"allowed_mime_types": ["audio/wav", "audio/mpeg", "audio/ogg", "audio/flac", "audio/mp4", "audio/x-m4a", "audio/aac", "audio/webm"]
},
"log_level": "INFO",
"log_file": "logs/whisper_api.log",
"request_logging": {
"exclude_endpoints": ["/health", "/static"]
}
}
+14
View File
@@ -0,0 +1,14 @@
services:
whisper-api:
build:
context: .
dockerfile: Dockerfile
container_name: whisper-api-server
ports:
- "5042:5042"
volumes:
- ./config.docker.json:/app/config.docker.json:ro
- ./logs:/app/logs
- ./history:/app/history
- ./models:/models
restart: unless-stopped