# Build stage FROM python:3.11-slim as builder WORKDIR /app # Install build dependencies RUN apt-get update && apt-get install -y --no-install-recommends \ gcc \ python3-dev \ && rm -rf /var/lib/apt/lists/* # Create and activate virtual environment RUN python -m venv /opt/venv ENV PATH="/opt/venv/bin:$PATH" # Install Python dependencies COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt # Runtime stage FROM python:3.11-slim # Install runtime dependencies RUN apt-get update && apt-get install -y --no-install-recommends \ curl \ libcairo2 \ libpango-1.0-0 \ libpangocairo-1.0-0 \ libgdk-pixbuf-2.0-0 \ libffi-dev \ shared-mime-info \ && rm -rf /var/lib/apt/lists/* # Copy static ffmpeg COPY --from=mwader/static-ffmpeg:6.1 /ffmpeg /usr/local/bin/ COPY --from=mwader/static-ffmpeg:6.1 /ffprobe /usr/local/bin/ # Copy virtual environment from builder COPY --from=builder /opt/venv /opt/venv ENV PATH="/opt/venv/bin:$PATH" WORKDIR /app # Copy application code COPY app.py . COPY templates/ templates/ COPY static/ static/ # Create directories for data persistence RUN mkdir -p /app/videos /app/data # Create directories for data persistence RUN mkdir -p /app/videos /app/data # Environment variables ENV PYTHONUNBUFFERED=1 ENV FLASK_APP=app.py ENV FLASK_ENV=production # Health check HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ CMD curl -f http://localhost:5001/ || exit 1 # Expose port EXPOSE 5001 # Run with Gunicorn for production CMD ["gunicorn", "--bind", "0.0.0.0:5001", "--workers", "2", "--threads", "4", "--timeout", "120", "app:app"]