Spaces:
Sleeping
Sleeping
| # ================================ | |
| # PrecisionVoice Dockerfile | |
| # Optimized for performance and size | |
| # ================================ | |
| # Stage 1: Builder | |
| FROM python:3.10-slim-bullseye AS builder | |
| WORKDIR /app | |
| # Install build dependencies | |
| RUN apt-get update && apt-get install -y --no-install-recommends \ | |
| build-essential \ | |
| git \ | |
| ffmpeg \ | |
| libsndfile1-dev \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Copy requirements and install dependencies | |
| # Using --user to keep packages in /root/.local | |
| COPY requirements.txt . | |
| RUN pip install --no-cache-dir --user -r requirements.txt | |
| # ================================ | |
| # Stage 2: Runtime | |
| # ================================ | |
| FROM python:3.10-slim-bullseye | |
| WORKDIR /app | |
| # Install runtime dependencies | |
| RUN apt-get update && apt-get install -y --no-install-recommends \ | |
| ffmpeg \ | |
| libsndfile1 \ | |
| && rm -rf /var/lib/apt/lists/* \ | |
| && apt-get clean | |
| # Copy Python packages from builder | |
| COPY --from=builder /root/.local /root/.local | |
| # Ensure scripts in .local are available | |
| ENV PATH=/root/.local/bin:$PATH | |
| ENV PYTHONUNBUFFERED=1 | |
| ENV PYTHONDONTWRITEBYTECODE=1 | |
| # Model cache directories | |
| ENV HF_HOME=/root/.cache/huggingface | |
| ENV TORCH_HOME=/root/.cache/torch | |
| ENV TRANSFORMERS_CACHE=/root/.cache/huggingface | |
| # Copy application code | |
| COPY app/ ./app/ | |
| COPY data/ ./data/ | |
| # Create necessary directories | |
| RUN mkdir -p /app/data/uploads /app/data/processed | |
| # Port configuration | |
| ARG PORT=7860 | |
| ENV PORT=${PORT} | |
| EXPOSE ${PORT} | |
| # Health check | |
| HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \ | |
| CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:${PORT}/api/health')" || exit 1 | |
| # Run the application | |
| CMD ["sh", "-c", "uvicorn app.main:app --host 0.0.0.0 --port ${PORT}"] | |