-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
111 lines (93 loc) · 4.24 KB
/
Dockerfile
File metadata and controls
111 lines (93 loc) · 4.24 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
99
100
101
102
103
104
105
106
107
108
109
110
111
# =============================================================================
# Multi-Stage Dockerfile for transcript-create (ROCm variant)
# =============================================================================
# This Dockerfile implements multi-stage builds for optimal image size and
# build time through layer caching.
#
# Build stages:
# 1. base - System dependencies and ROCm base
# 2. python-deps - Python packages installation
# 3. app - Final application stage
#
# Target image size: <2.5GB (down from ~3GB)
# Build time: <10 min with cache
# =============================================================================
# =============================================================================
# Stage 1: Base image with system dependencies
# =============================================================================
FROM rocm/dev-ubuntu-22.04:6.0.2 AS base
# Build argument for PyTorch ROCm wheel index
ARG ROCM_WHEEL_INDEX=https://download.pytorch.org/whl/rocm6.0
# Set environment variables for non-interactive installs
ENV DEBIAN_FRONTEND=noninteractive \
PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1
# Install system dependencies and development toolchain in a single layer
# We include python3-dev and build-essential so runtime packages that compile
# helper extensions (e.g. numba/triton helpers) can build their temporary
# C artefacts without "Python.h: No such file or directory" failures.
RUN apt-get update && \
apt-get install -y --no-install-recommends \
ffmpeg \
python3 \
python3-pip \
python3-dev \
libpython3-dev \
build-essential \
cmake \
pkg-config \
git \
curl \
unzip \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean
# Install Deno for yt-dlp JavaScript runtime requirement
# yt-dlp requires a JS runtime (Deno/Node/Bun/QuickJS) to solve YouTube challenges
RUN curl -fsSL https://deno.land/install.sh | sh && \
mv /root/.deno/bin/deno /usr/local/bin/deno && \
chmod +x /usr/local/bin/deno && \
deno --version
# =============================================================================
# Stage 2: Python dependencies
# =============================================================================
FROM base AS python-deps
# Copy only requirements files to leverage layer caching
COPY requirements.txt constraints.txt* ./
# Install Python dependencies with pip cache mount for faster rebuilds
# Use BuildKit cache mount to persist pip cache across builds
RUN --mount=type=cache,target=/root/.cache/pip \
pip3 install --no-cache-dir -r requirements.txt && \
# Remove any torch variants pulled in by other dependencies
(pip3 uninstall -y torch torchvision torchaudio || true) && \
# Install ROCm PyTorch wheels explicitly
pip3 install --no-cache-dir --index-url ${ROCM_WHEEL_INDEX} \
torch==2.4.1+rocm6.0 torchaudio==2.4.1+rocm6.0
# Verify PyTorch installation
RUN python3 -c "import torch; print('Torch version:', torch.__version__); print('HIP version:', getattr(torch.version, 'hip', None)); print('cuda.is_available:', torch.cuda.is_available())"
# =============================================================================
# Stage 3: Final application stage
# =============================================================================
FROM base AS app
# Copy Python packages from deps stage
COPY --from=python-deps /usr/local/lib/python3.10/dist-packages /usr/local/lib/python3.10/dist-packages
COPY --from=python-deps /usr/local/bin /usr/local/bin
# Set working directory
WORKDIR /app
# Copy application code (excluding files in .dockerignore)
COPY . /app
# Pre-compile Python files for faster startup
RUN python3 -m compileall -q /app
# Set optimal environment variables for production
ENV PDF_FONT_PATH=/app/fonts/DejaVuSerif.ttf \
HF_HOME=/root/.cache/hf \
HF_HUB_CACHE=/root/.cache/hf/hub \
TRANSFORMERS_CACHE=/root/.cache/hf/transformers
# Add health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=40s --retries=3 \
CMD curl -f http://localhost:8000/health || exit 1
# Expose API port
EXPOSE 8000
# Default command
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]