-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDockerfile
More file actions
85 lines (69 loc) · 2.53 KB
/
Dockerfile
File metadata and controls
85 lines (69 loc) · 2.53 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
# Adobe Hackathon 2025 - Ultra-Optimized Dockerfile for Synapse-Docs
# Target: Reduce from ~12GB to ~3-4GB with full functionality preservation
# Stage 1: Frontend Build (production-grade with lock file)
FROM node:18-alpine AS frontend
WORKDIR /frontend
# Copy package files for dependency resolution
COPY frontend/package.json frontend/package-lock.json ./
# Fast, reliable install using committed lock file
RUN npm ci --silent
# Copy source and build
COPY frontend/ ./
RUN npm run build
# Clean production install (remove dev dependencies)
RUN npm ci --silent --only=production
# Stage 2: Python Dependencies (optimized compilation)
FROM python:3.11-slim AS python-deps
WORKDIR /deps
# Critical: Install minimal build tools
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
g++ \
libc6-dev \
pkg-config \
&& rm -rf /var/lib/apt/lists/*
# Install to user directory for isolation
COPY backend/requirements.txt .
RUN pip install --no-cache-dir --user --no-warn-script-location \
--extra-index-url https://download.pytorch.org/whl/cpu \
torch==2.6.0+cpu torchvision
RUN pip install --no-cache-dir --user --no-warn-script-location \
-r requirements.txt
RUN find /root/.local -name "*.pyc" -delete || true && \
find /root/.local -name "__pycache__" -exec rm -rf {} + || true
# Stage 3: Minimal Runtime (ultra-slim)
FROM python:3.11-slim AS runtime
WORKDIR /app
# Production environment optimization
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PYTHONPATH=/app \
PATH=/root/.local/bin:$PATH \
MALLOC_TRIM_THRESHOLD_=100000
# Install absolute minimal runtime libraries + CRITICAL sample script dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
libgomp1 \
libblas3 \
liblapack3 \
ffmpeg \
espeak-ng \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get autoremove -y \
&& apt-get clean \
&& rm -rf /tmp/* /var/tmp/*
# Copy optimized Python environment
COPY --from=python-deps /root/.local /root/.local
# Copy minimal application files only
COPY backend/app /app/app
COPY backend/gunicorn_conf.py /app/
COPY backend/chat_with_llm.py /app/
COPY backend/generate_audio.py /app/
COPY backend/preload_models.py /app/
COPY --from=frontend /frontend/dist /app/static
# Pre-download ML models to avoid download delays at runtime
RUN python preload_models.py
# Create required directories with proper permissions
RUN mkdir -p /app/data/audio /app/uploads
# Use optimized startup
EXPOSE 8080
CMD ["gunicorn", "-c", "gunicorn_conf.py", "app.main:app"]