-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
98 lines (80 loc) · 3.5 KB
/
Copy pathDockerfile
File metadata and controls
98 lines (80 loc) · 3.5 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# 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)
#
# Version: 0.0.4
# Image tags: 0.0.1, latest
FROM python:3.14-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.14-slim
# Install Node.js 25.6.1 (for git repository ingestion via npx codefetch)
ENV NODE_VERSION=25.6.1
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
curl \
xz-utils \
libsndfile1 \
ffmpeg \
gosu \
&& ARCH=$(dpkg --print-architecture) \
&& NODE_ARCH=$(case "$ARCH" in amd64) echo "x64" ;; arm64) echo "arm64" ;; *) echo "$ARCH" ;; esac) \
&& curl -fsSLO --compressed "https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-${NODE_ARCH}.tar.xz" \
&& curl -fsSLO --compressed "https://nodejs.org/dist/v${NODE_VERSION}/SHASUMS256.txt" \
&& grep " node-v${NODE_VERSION}-linux-${NODE_ARCH}.tar.xz$" SHASUMS256.txt | sha256sum -c - \
&& tar -xJf "node-v${NODE_VERSION}-linux-${NODE_ARCH}.tar.xz" -C /usr/local --strip-components=1 --no-same-owner \
&& rm "node-v${NODE_VERSION}-linux-${NODE_ARCH}.tar.xz" SHASUMS256.txt \
&& apt-get purge -y curl xz-utils \
&& apt-get autoremove -y \
&& 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 with explicit UID 1000 for K8s/dynamic UID compatibility
RUN useradd --create-home --shell /bin/bash --uid 1000 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 ./
COPY docker-entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
# Create logs and data directories, ensure ownership
RUN chown pockettts:pockettts /app && \
mkdir -p /app/logs && chown pockettts:pockettts /app/logs && \
mkdir -p /app/data/sources /app/data/audio && chown -R pockettts:pockettts /app/data && \
mkdir -p /tmp && chown pockettts:pockettts /tmp
# Create HuggingFace cache directory (for volume mount)
RUN mkdir -p /home/pockettts/.cache/huggingface && \
chown -R pockettts:pockettts /home/pockettts/.cache
# Environment variables with defaults
ENV POCKET_TTS_HOST=0.0.0.0 \
POCKET_TTS_PORT=49112 \
POCKET_TTS_VOICES_DIR=/app/voices \
POCKET_TTS_DATA_DIR=/app/data \
POCKET_TTS_LOG_DIR=/app/logs \
POCKET_TTS_LOG_LEVEL=INFO \
PYTHONUNBUFFERED=1 \
TMPDIR=/tmp
# 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
# Entrypoint fixes volume permissions then drops to non-root user
ENTRYPOINT ["docker-entrypoint.sh"]
# Run server
CMD ["python", "server.py"]