FROM python:3.10-slim # Set working directory WORKDIR /app # Install system dependencies RUN apt-get update && apt-get install -y \ gcc \ g++ \ && rm -rf /var/lib/apt/lists/* # Copy requirements file COPY requirements.txt . # Install Python dependencies RUN pip install --no-cache-dir -r requirements.txt # Copy the application code COPY . . # Create all necessary directories with proper permissions RUN mkdir -p /app/tmp \ /app/.config/matplotlib \ /app/.cache \ /app/.local && \ chmod -R 777 /app/tmp /app/.config /app/.cache /app/.local # Set comprehensive environment variables ENV TMPDIR=/app/tmp \ TEMP=/app/tmp \ TMP=/app/tmp \ MPLCONFIGDIR=/app/.config/matplotlib \ XDG_CACHE_HOME=/app/.cache \ XDG_CONFIG_HOME=/app/.config \ HOME=/app \ MPLBACKEND=Agg \ PYTHONUNBUFFERED=1 # Expose the port FastAPI will run on EXPOSE 7860 # Command to run the FastAPI application CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1", "--timeout-keep-alive", "120"] # # Builder stage # FROM python:3.10-slim AS builder # WORKDIR /app # COPY requirements.txt . # RUN apt-get update && apt-get install -y gcc g++ \ # && pip install --no-cache-dir -r requirements.txt \ # && apt-get purge -y gcc g++ \ # && apt-get autoremove -y \ # && rm -rf /var/lib/apt/lists/* # # Runtime stage # FROM python:3.10-slim # WORKDIR /app # COPY --from=builder /usr/local/lib/python3.10/site-packages /usr/local/lib/python3.10/site-packages # COPY . . # # Create TMP directories # RUN mkdir -p /app/tmp /app/.config/matplotlib /app/.cache /app/.local && \ # chmod -R 777 /app/tmp /app/.config /app/.cache /app/.local # ENV TMPDIR=/app/tmp \ # TEMP=/app/tmp \ # TMP=/app/tmp \ # MPLCONFIGDIR=/app/.config/matplotlib \ # XDG_CACHE_HOME=/app/.cache \ # XDG_CONFIG_HOME=/app/.config \ # HOME=/app \ # MPLBACKEND=Agg \ # PYTHONUNBUFFERED=1 # EXPOSE 7860 # CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1", "--timeout-keep-alive", "120"]