feat: add Dockerfile with CPU-only torch, .dockerignore, and requirements-cpu.txt

- Multi-stage Dockerfile with CPU-only PyTorch
- .dockerignore to exclude build artifacts
- requirements-cpu.txt for CPU-only dependencies
- Health check endpoint for container monitoring
This commit is contained in:
delevisor
2026-05-03 08:19:33 +00:00
parent df2a97b85a
commit eee3d4bebf
3 changed files with 58 additions and 14 deletions

17
.dockerignore Normal file
View File

@@ -0,0 +1,17 @@
__pycache__/
*.pyc
*.pyo
.env
.venv/
venv/
*.egg-info/
dist/
build/
*.egg
response_*.wav
*.log
.git/
.gitignore
.dockerignore
Dockerfile
requirements-cpu.txt

View File

@@ -1,19 +1,13 @@
ARG BASE_IMAGE=nvidia/cuda:12.2.2-runtime-ubuntu22.04
FROM python:3.11-slim
FROM ${BASE_IMAGE}
# Set environment variables
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
DEBIAN_FRONTEND=noninteractive \
MODEL_CACHE_DIR=/models
MODEL_CACHE_DIR=/models \
TORCH_CUDA_ARCH_LIST=""
# Install Python and system dependencies
# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
python3.10 \
python3.10-venv \
python3-pip \
build-essential \
git \
curl \
wget \
@@ -22,11 +16,15 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
ffmpeg \
&& rm -rf /var/lib/apt/lists/*
# Install torch CPU-only first (before other deps that might pull CUDA)
RUN pip install --no-cache-dir torch torchaudio --index-url https://download.pytorch.org/whl/cpu
# Set up Python virtual environment
WORKDIR /app
# Copy requirements and install Python deps
COPY requirements.txt .
RUN pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir -r requirements.txt
RUN pip install --no-cache-dir -r requirements.txt
# Copy application code
COPY . .
@@ -36,11 +34,14 @@ RUN mkdir -p ${MODEL_CACHE_DIR}
# Set environment variables for models
ENV TRANSFORMERS_CACHE=${MODEL_CACHE_DIR} \
HF_HOME=${MODEL_CACHE_DIR} \
PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True
HF_HOME=${MODEL_CACHE_DIR}
# Expose WebSocket port
EXPOSE 8000
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
CMD curl -f http://localhost:8000/docs || exit 1
# Run the application
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]

26
requirements-cpu.txt Normal file
View File

@@ -0,0 +1,26 @@
# WebSocket server
fastapi
uvicorn[standard]
websockets
webrtcvad
# Speech-to-Text
faster-whisper
soundfile
# LLM (CPU-only)
transformers
accelerate
bitsandbytes
# TTS
torchaudio
# Audio processing
numpy
scipy
# Utilities
python-dotenv
pydantic
pydantic-settings