File size: 2,438 Bytes
f021ebf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# Dockerfile for PocketTTS OpenAI-Compatible Server
# Optimized for CPU inference (pocket-tts runs efficiently on CPU)
# Uses CPU-only PyTorch for smaller image size (~700MB vs ~2GB)

FROM python:3.10-slim AS builder

# Install build dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential \
    && rm -rf /var/lib/apt/lists/*

# Create virtual environment
RUN python -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"

# Install Python dependencies (requirements.txt specifies CPU-only PyTorch)
COPY requirements.txt /tmp/requirements.txt
RUN pip install --no-cache-dir --upgrade pip && \
    pip install --no-cache-dir -r /tmp/requirements.txt


# Production image
FROM python:3.10-slim

# Install runtime dependencies for audio processing
RUN apt-get update && apt-get install -y --no-install-recommends \
    libsndfile1 \
    ffmpeg \
    && rm -rf /var/lib/apt/lists/* \
    && apt-get clean

# Copy virtual environment from builder
COPY --from=builder /opt/venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"

# Create non-root user
RUN useradd --create-home --shell /bin/bash pockettts
WORKDIR /app

# Copy application code
COPY --chown=pockettts:pockettts app/ ./app/
COPY --chown=pockettts:pockettts static/ ./static/
COPY --chown=pockettts:pockettts templates/ ./templates/
COPY --chown=pockettts:pockettts voices/ ./voices/
COPY --chown=pockettts:pockettts server.py ./

# Create logs directory, and ensure app directory is owned by user
RUN chown pockettts:pockettts /app && mkdir -p /app/logs && chown pockettts:pockettts /app/logs

# Create HuggingFace cache directory (for volume mount)
RUN mkdir -p /home/pockettts/.cache/huggingface && \
    chown -R pockettts:pockettts /home/pockettts/.cache

# Create voice cache directory with correct ownership for the named volume
RUN mkdir -p /app/voice_cache && chown pockettts:pockettts /app/voice_cache

# Switch to non-root user
USER pockettts

# Environment variables with defaults
ENV POCKET_TTS_HOST=0.0.0.0 \
    POCKET_TTS_PORT=49112 \
    POCKET_TTS_VOICES_DIR=/app/voices \
    POCKET_TTS_LOG_DIR=/app/logs \
    POCKET_TTS_LOG_LEVEL=INFO \
    PYTHONUNBUFFERED=1

# Expose port
EXPOSE 49112

# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
    CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:49112/health')" || exit 1

# Run server
CMD ["python", "server.py"]