Rename dockerfile to Dockerfile
Browse files- Dockerfile +93 -0
- dockerfile +0 -126
Dockerfile
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Optimized Dockerfile for Hugging Face Spaces
|
| 2 |
+
FROM python:3.12-slim
|
| 3 |
+
|
| 4 |
+
# Set working directory
|
| 5 |
+
WORKDIR /app
|
| 6 |
+
|
| 7 |
+
# Set environment variables for HF Spaces
|
| 8 |
+
ENV DEBIAN_FRONTEND=noninteractive \
|
| 9 |
+
PYTHONUNBUFFERED=1 \
|
| 10 |
+
PYTHONPATH=/app \
|
| 11 |
+
GRADIO_SERVER_NAME=0.0.0.0 \
|
| 12 |
+
GRADIO_SERVER_PORT=7860 \
|
| 13 |
+
HF_HOME=/tmp/huggingface \
|
| 14 |
+
TRANSFORMERS_CACHE=/tmp/transformers \
|
| 15 |
+
PIP_NO_CACHE_DIR=1 \
|
| 16 |
+
PIP_DISABLE_PIP_VERSION_CHECK=1
|
| 17 |
+
|
| 18 |
+
# Install system dependencies in single layer
|
| 19 |
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 20 |
+
wget \
|
| 21 |
+
curl \
|
| 22 |
+
git \
|
| 23 |
+
gcc \
|
| 24 |
+
g++ \
|
| 25 |
+
build-essential \
|
| 26 |
+
pkg-config \
|
| 27 |
+
portaudio19-dev \
|
| 28 |
+
libasound2-dev \
|
| 29 |
+
libsdl-pango-dev \
|
| 30 |
+
libcairo2-dev \
|
| 31 |
+
libpango1.0-dev \
|
| 32 |
+
sox \
|
| 33 |
+
ffmpeg \
|
| 34 |
+
ca-certificates \
|
| 35 |
+
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
| 36 |
+
|
| 37 |
+
# Install TinyTeX with minimal packages for HF Spaces
|
| 38 |
+
RUN wget -qO- "https://yihui.org/tinytex/install-bin-unix.sh" | sh \
|
| 39 |
+
&& export PATH="$HOME/.TinyTeX/bin/x86_64-linux:$PATH" \
|
| 40 |
+
&& tlmgr install \
|
| 41 |
+
amsmath latex-bin xetex xcolor \
|
| 42 |
+
fontspec microtype setspace \
|
| 43 |
+
standalone preview physics \
|
| 44 |
+
&& rm -rf ~/.TinyTeX/texmf-var/web2c/tlmgr*.log* \
|
| 45 |
+
&& find ~/.TinyTeX -name "*.log" -delete 2>/dev/null || true
|
| 46 |
+
|
| 47 |
+
# Add TinyTeX to PATH
|
| 48 |
+
ENV PATH="/root/.TinyTeX/bin/x86_64-linux:$PATH"
|
| 49 |
+
|
| 50 |
+
# Copy requirements and install Python dependencies
|
| 51 |
+
COPY requirements.txt .
|
| 52 |
+
RUN pip install --no-cache-dir -r requirements.txt \
|
| 53 |
+
&& pip install --no-cache-dir gradio \
|
| 54 |
+
&& python -c "import gradio; print(f'Gradio version: {gradio.__version__}')" \
|
| 55 |
+
&& find /usr/local -name "*.pyc" -delete \
|
| 56 |
+
&& find /usr/local -name "__pycache__" -type d -exec rm -rf {} + 2>/dev/null || true
|
| 57 |
+
|
| 58 |
+
# Create models directory and download models efficiently
|
| 59 |
+
RUN mkdir -p models && cd models \
|
| 60 |
+
&& echo "Downloading models for HF Spaces..." \
|
| 61 |
+
&& wget --progress=dot:giga --timeout=30 --tries=3 \
|
| 62 |
+
-O kokoro-v0_19.onnx \
|
| 63 |
+
"https://github.com/thewh1teagle/kokoro-onnx/releases/download/model-files/kokoro-v0_19.onnx" \
|
| 64 |
+
&& wget --progress=dot:giga --timeout=30 --tries=3 \
|
| 65 |
+
-O voices.bin \
|
| 66 |
+
"https://github.com/thewh1teagle/kokoro-onnx/releases/download/model-files/voices.bin" \
|
| 67 |
+
&& ls -la /app/models/
|
| 68 |
+
|
| 69 |
+
# Copy application files (order matters for caching)
|
| 70 |
+
COPY src/ ./src/
|
| 71 |
+
COPY .env* ./
|
| 72 |
+
COPY gradio_app.py ./
|
| 73 |
+
COPY README.md ./
|
| 74 |
+
COPY *.py ./
|
| 75 |
+
|
| 76 |
+
# Create output directory
|
| 77 |
+
RUN mkdir -p output tmp
|
| 78 |
+
|
| 79 |
+
# Add HF Spaces specific metadata
|
| 80 |
+
LABEL space.title="Your App Title" \
|
| 81 |
+
space.sdk="docker" \
|
| 82 |
+
space.author="your-username" \
|
| 83 |
+
space.description="Your app description"
|
| 84 |
+
|
| 85 |
+
# Expose the port that HF Spaces expects
|
| 86 |
+
EXPOSE 7860
|
| 87 |
+
|
| 88 |
+
# Health check optimized for HF Spaces
|
| 89 |
+
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=2 \
|
| 90 |
+
CMD curl -f http://localhost:7860/ || exit 1
|
| 91 |
+
|
| 92 |
+
# Run the Gradio app with HF Spaces optimized settings
|
| 93 |
+
CMD ["python", "gradio_app.py"]
|
dockerfile
DELETED
|
@@ -1,126 +0,0 @@
|
|
| 1 |
-
# Stage 1: Builder
|
| 2 |
-
FROM python:3.12-slim AS builder
|
| 3 |
-
|
| 4 |
-
WORKDIR /app
|
| 5 |
-
|
| 6 |
-
# Set environment variables
|
| 7 |
-
ENV DEBIAN_FRONTEND=noninteractive \
|
| 8 |
-
PYTHONUNBUFFERED=1 \
|
| 9 |
-
PIP_NO_CACHE_DIR=1 \
|
| 10 |
-
PIP_DISABLE_PIP_VERSION_CHECK=1
|
| 11 |
-
|
| 12 |
-
# Install build dependencies in a single layer with version pinning where critical
|
| 13 |
-
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 14 |
-
wget=1.21.* \
|
| 15 |
-
curl \
|
| 16 |
-
gcc \
|
| 17 |
-
bzip2 \
|
| 18 |
-
ca-certificates \
|
| 19 |
-
gnupg \
|
| 20 |
-
git \
|
| 21 |
-
python3-dev \
|
| 22 |
-
build-essential \
|
| 23 |
-
pkg-config \
|
| 24 |
-
portaudio19-dev \
|
| 25 |
-
libsdl-pango-dev \
|
| 26 |
-
libcairo2-dev \
|
| 27 |
-
libpango1.0-dev \
|
| 28 |
-
&& apt-get clean \
|
| 29 |
-
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
| 30 |
-
|
| 31 |
-
# Install TinyTeX with error handling and cleanup
|
| 32 |
-
RUN wget -qO- "https://yihui.org/tinytex/install-bin-unix.sh" | sh \
|
| 33 |
-
&& ~/.TinyTeX/bin/*/tlmgr path add \
|
| 34 |
-
&& ~/.TinyTeX/bin/*/tlmgr install \
|
| 35 |
-
amsmath babel-english cbfonts-fd cm-super count1to ctex \
|
| 36 |
-
doublestroke dvisvgm everysel fontspec frcursive fundus-calligra \
|
| 37 |
-
gnu-freefont jknapltx latex-bin mathastext microtype multitoc \
|
| 38 |
-
physics preview prelim2e ragged2e relsize rsfs setspace \
|
| 39 |
-
standalone tipa wasy wasysym xcolor xetex xkeyval \
|
| 40 |
-
&& rm -rf ~/.TinyTeX/texmf-var/web2c/tlmgr.log* \
|
| 41 |
-
&& rm -rf ~/.TinyTeX/texmf-var/web2c/tlmgr-commands.log* \
|
| 42 |
-
&& find ~/.TinyTeX -name "*.log" -delete \
|
| 43 |
-
&& find ~/.TinyTeX -name "*.aux" -delete
|
| 44 |
-
|
| 45 |
-
# Copy and install Python dependencies
|
| 46 |
-
COPY requirements.txt .
|
| 47 |
-
RUN pip install --no-cache-dir --prefix=/install -r requirements.txt \
|
| 48 |
-
&& find /install -name "*.pyc" -delete \
|
| 49 |
-
&& find /install -name "__pycache__" -type d -exec rm -rf {} + 2>/dev/null || true
|
| 50 |
-
|
| 51 |
-
# Download models with checksums and error handling
|
| 52 |
-
RUN mkdir -p /models \
|
| 53 |
-
&& cd /models \
|
| 54 |
-
&& wget --progress=dot:giga -O kokoro-v0_19.onnx \
|
| 55 |
-
"https://github.com/thewh1teagle/kokoro-onnx/releases/download/model-files/kokoro-v0_19.onnx" \
|
| 56 |
-
&& wget --progress=dot:giga -O voices.bin \
|
| 57 |
-
"https://github.com/thewh1teagle/kokoro-onnx/releases/download/model-files/voices.bin" \
|
| 58 |
-
&& ls -la /models
|
| 59 |
-
|
| 60 |
-
# Stage 2: Runtime
|
| 61 |
-
FROM python:3.12-slim AS runtime
|
| 62 |
-
|
| 63 |
-
# Create non-root user for security
|
| 64 |
-
RUN groupadd -r appuser && useradd -r -g appuser -d /app -s /sbin/nologin appuser
|
| 65 |
-
|
| 66 |
-
WORKDIR /app
|
| 67 |
-
|
| 68 |
-
# Set environment variables
|
| 69 |
-
ENV DEBIAN_FRONTEND=noninteractive \
|
| 70 |
-
PYTHONUNBUFFERED=1 \
|
| 71 |
-
PYTHONPATH=/app \
|
| 72 |
-
PATH="/root/.TinyTeX/bin/x86_64-linux:$PATH"
|
| 73 |
-
|
| 74 |
-
# Install runtime dependencies
|
| 75 |
-
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 76 |
-
portaudio19-dev \
|
| 77 |
-
libasound2-dev \
|
| 78 |
-
libsdl-pango-dev \
|
| 79 |
-
libcairo2-dev \
|
| 80 |
-
libpango1.0-dev \
|
| 81 |
-
sox \
|
| 82 |
-
ffmpeg \
|
| 83 |
-
tini \
|
| 84 |
-
&& apt-get clean \
|
| 85 |
-
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
| 86 |
-
|
| 87 |
-
# Copy TinyTeX from builder stage
|
| 88 |
-
COPY --from=builder /root/.TinyTeX /root/.TinyTeX
|
| 89 |
-
|
| 90 |
-
# Copy Python packages from builder stage
|
| 91 |
-
COPY --from=builder /install /usr/local
|
| 92 |
-
|
| 93 |
-
# Copy models from builder stage
|
| 94 |
-
COPY --from=builder /models /app/models
|
| 95 |
-
|
| 96 |
-
# Copy application files (be more selective to reduce layer size)
|
| 97 |
-
COPY --chown=appuser:appuser .env gradio_app.py ./
|
| 98 |
-
COPY --chown=appuser:appuser src/ ./src/
|
| 99 |
-
|
| 100 |
-
# Create output directory with proper permissions
|
| 101 |
-
RUN mkdir -p output \
|
| 102 |
-
&& chown -R appuser:appuser /app
|
| 103 |
-
|
| 104 |
-
# Switch to non-root user
|
| 105 |
-
USER appuser
|
| 106 |
-
|
| 107 |
-
# Add labels for better maintainability
|
| 108 |
-
LABEL maintainer="[email protected]" \
|
| 109 |
-
version="1.0" \
|
| 110 |
-
description="Multi-stage Docker image for ML application"
|
| 111 |
-
|
| 112 |
-
# Expose port
|
| 113 |
-
EXPOSE 7860
|
| 114 |
-
|
| 115 |
-
# Use tini as PID 1 for proper signal handling
|
| 116 |
-
ENTRYPOINT ["tini", "--"]
|
| 117 |
-
|
| 118 |
-
# Improved health check with more specific validation
|
| 119 |
-
HEALTHCHECK --interval=30s --timeout=15s --start-period=60s --retries=3 \
|
| 120 |
-
CMD python -c "import sys; import src; import manim; \
|
| 121 |
-
import requests; \
|
| 122 |
-
r = requests.get('http://localhost:7860/health', timeout=10); \
|
| 123 |
-
sys.exit(0 if r.status_code == 200 else 1)" || exit 1
|
| 124 |
-
|
| 125 |
-
# Start the application
|
| 126 |
-
CMD ["python", "gradio_app.py"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|