Speakr is a personal, self-hosted web application designed for transcribing audio recordings
Python
Multi-stage Dockerfile with static ffmpeg for smaller images (4.4GB → 725MB lite)
Murtaza Nasirc7297c6413cd
diff --git a/.dockerignore b/.dockerignoreindex 52524d17..1a676efb 100644--- a/.dockerignore+++ b/.dockerignore@@ -5,9 +5,7 @@# Docker.dockerignoreDockerfile-docker-compose.yml-docker-compose.override.yml-docker-compose.override.yml.example+docker-compose*.yml# Python__pycache__/@@ -33,16 +31,33 @@ var/venv/.venv/-# Data directories (these will be mounted as volumes)+# Data directories (mounted as volumes)data/uploads/instance/+exports/+auto-process/-# IDE files+# Non-runtime directories+temp/+docs/+site/+plan/+unraid/+tests/+.claude/+.migrate/+.github/++# IDE and editor files.idea/.vscode/*.swp*.swo-# Logs+# Logs and misc*.log+*.md+!requirements*.txt+LICENSE+CLAUDE.mddiff --git a/Dockerfile b/Dockerfileindex a6c01e81..7bcf0604 100644--- a/Dockerfile+++ b/Dockerfile@@ -1,43 +1,69 @@-FROM python:3.11-slim+###############################################################################+# Stage 1: Builder — install Python deps and download vendor assets+###############################################################################+FROM python:3.11-slim AS builder-# Build argument to determine if this is a production buildARG PRODUCTION=0-# Set LIGHTWEIGHT=1 to skip PyTorch/sentence-transformers (~1.7GB smaller image)ARG LIGHTWEIGHT=0WORKDIR /app-# Install system dependencies-RUN apt-get update && apt-get install -y --no-install-recommends \- gcc \- ffmpeg \+# gcc is needed to compile C extensions during pip install+RUN apt-get update && apt-get install -y --no-install-recommends gcc \&& rm -rf /var/lib/apt/lists/*-# Copy requirements first for better caching+# Install Python dependenciesCOPY requirements.txt requirements-embeddings.txt ./-RUN pip install --no-cache-dir -r requirements.txt && \+RUN pip install --no-cache-dir --prefix=/install -r requirements.txt && \if [ "$LIGHTWEIGHT" = "0" ]; then \- pip install --no-cache-dir -r requirements-embeddings.txt; \+ pip install --no-cache-dir --prefix=/install -r requirements-embeddings.txt; \fi-# Create directory structure for vendor files+# Download vendor assets (JS/CSS/fonts)RUN mkdir -p /app/static/vendor--# Copy only the scripts needed for downloading dependenciesCOPY scripts/download_offline_deps.py scripts/--# Install requests and download vendor dependencies BEFORE copying all code-# This allows better Docker layer caching - vendor deps won't re-download on code changesRUN pip install --no-cache-dir requests && \PRODUCTION=${PRODUCTION} python scripts/download_offline_deps.py && \echo "✓ Vendor dependencies downloaded successfully"-# Now copy the rest of the application code+###############################################################################+# Stage 2: FFmpeg — download static binaries (much smaller than apt ffmpeg)+###############################################################################+FROM python:3.11-slim AS ffmpeg-stage++RUN apt-get update && apt-get install -y --no-install-recommends wget xz-utils \+ && rm -rf /var/lib/apt/lists/* \+ && ARCH=$(dpkg --print-architecture) \+ && wget -q https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-${ARCH}-static.tar.xz -O /tmp/ff.tar.xz \+ && mkdir -p /tmp/ffmpeg-dir \+ && tar xf /tmp/ff.tar.xz -C /tmp/ffmpeg-dir --strip-components=1 \+ && mv /tmp/ffmpeg-dir/ffmpeg /usr/local/bin/ffmpeg \+ && mv /tmp/ffmpeg-dir/ffprobe /usr/local/bin/ffprobe \+ && chmod +x /usr/local/bin/ffmpeg /usr/local/bin/ffprobe \+ && rm -rf /tmp/ff.tar.xz /tmp/ffmpeg-dir++###############################################################################+# Stage 3: Runtime — lean final image with only what's needed+###############################################################################+FROM python:3.11-slim++WORKDIR /app++# Copy static ffmpeg binaries (~150MB vs ~450MB from apt)+COPY --from=ffmpeg-stage /usr/local/bin/ffmpeg /usr/local/bin/ffmpeg+COPY --from=ffmpeg-stage /usr/local/bin/ffprobe /usr/local/bin/ffprobe++# Copy installed Python packages from builder+COPY --from=builder /install /usr/local++# Copy downloaded vendor assets from builder+COPY --from=builder /app/static/vendor /app/static/vendor++# Copy application codeCOPY . .# Create necessary directories-RUN mkdir -p /data/uploads /data/instance-RUN chmod 755 /data/uploads /data/instance+RUN mkdir -p /data/uploads /data/instance && chmod 755 /data/uploads /data/instance# Set environment variablesENV FLASK_APP=src/app.py@@ -50,9 +76,7 @@ ENV HF_HOME=/data/instance/huggingfaceCOPY scripts/docker-entrypoint.sh /usr/local/bin/RUN chmod +x /usr/local/bin/docker-entrypoint.sh-# Expose the portEXPOSE 8899-# Set entrypoint and default commandENTRYPOINT ["docker-entrypoint.sh"]CMD ["gunicorn", "--workers", "3", "--bind", "0.0.0.0:8899", "--timeout", "600", "src.app:app"]