# Multi-stage build para otimizar tamanho FROM python:3.11-slim AS builder WORKDIR /app # Install build dependencies RUN apt-get update && apt-get install -y \ build-essential \ curl \ && rm -rf /var/lib/apt/lists/* # Install Python dependencies COPY requirements.txt . RUN pip install --user --no-cache-dir -r requirements.txt # --- # Production stage FROM python:3.11-slim # Create non-root user RUN useradd -m -u 1000 appuser && \ mkdir -p /app && \ chown -R appuser:appuser /app WORKDIR /app # Copy Python dependencies from builder COPY --from=builder /root/.local /home/appuser/.local # Copy application COPY --chown=appuser:appuser . . # Set PATH ENV PATH=/home/appuser/.local/bin:$PATH # Environment variables ENV PYTHONUNBUFFERED=1 ENV GRADIO_SERVER_NAME=0.0.0.0 ENV GRADIO_SERVER_PORT=7860 # Switch to non-root user USER appuser # Health check HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \ CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:7860').read()" || exit 1 # Expose port EXPOSE 7860 # Run CMD ["python", "app.py"]