# ── Base image ──────────────────────────────────────────────────────────────── FROM python:3.12-slim # Cache bust: v3 ENV PYTHONUNBUFFERED=1 \ PYTHONDONTWRITEBYTECODE=1 \ DEBIAN_FRONTEND=noninteractive \ KMP_DUPLICATE_LIB_OK=TRUE \ API_URL=http://localhost:8000 # ── System deps ─────────────────────────────────────────────────────────────── RUN apt-get update && apt-get install -y --no-install-recommends \ libglib2.0-0 \ libsm6 \ libxrender1 \ libxext6 \ libgl1 \ curl \ supervisor \ && rm -rf /var/lib/apt/lists/* # ── Non-root user (HF Spaces requirement) ──────────────────────────────────── RUN useradd -m -u 1000 appuser # ── Working directory ───────────────────────────────────────────────────────── WORKDIR /app # ── Python dependencies ─────────────────────────────────────────────────────── COPY requirements.txt . RUN pip install --no-cache-dir --upgrade pip && \ pip install --no-cache-dir -r requirements.txt # ── Copy application code ───────────────────────────────────────────────────── COPY app/ ./app/ COPY skin_disease_classifier.pkl . # ── Streamlit config override (force port 7860) ─────────────────────────────── RUN mkdir -p /app/app/frontend/.streamlit && \ printf '[server]\nport = 7860\nheadless = true\naddress = "0.0.0.0"\nenableCORS = false\nenableXsrfProtection = false\n' \ > /app/app/frontend/.streamlit/config.toml # ── Supervisor config with stdout logging ───────────────────────────────────── RUN mkdir -p /etc/supervisor/conf.d && \ printf '[supervisord]\nnodaemon=true\nlogfile=/tmp/supervisord.log\npidfile=/tmp/supervisord.pid\nuser=root\n\n[program:fastapi]\ncommand=uvicorn backend.main:app --host 0.0.0.0 --port 8000 --workers 1\ndirectory=/app/app\nautostart=true\nautorestart=true\nstartretries=5\nstdout_logfile=/dev/stdout\nstdout_logfile_maxbytes=0\nstderr_logfile=/dev/stderr\nstderr_logfile_maxbytes=0\nenvironment=KMP_DUPLICATE_LIB_OK="TRUE",PYTHONPATH="/app/app"\n\n[program:streamlit]\ncommand=streamlit run Home.py\ndirectory=/app/app/frontend\nautostart=true\nautorestart=true\nstartretries=5\nstdout_logfile=/dev/stdout\nstdout_logfile_maxbytes=0\nstderr_logfile=/dev/stderr\nstderr_logfile_maxbytes=0\nenvironment=API_URL="http://localhost:8000",KMP_DUPLICATE_LIB_OK="TRUE",PYTHONPATH="/app/app/frontend"\n' \ > /etc/supervisor/conf.d/dermAI.conf # ── Permissions ─────────────────────────────────────────────────────────────── RUN chown -R appuser:appuser /app && \ chmod -R 755 /app && \ mkdir -p /tmp && chmod 777 /tmp # ── HuggingFace Spaces requires port 7860 ──────────────────────────────────── EXPOSE 7860 # ── Healthcheck ─────────────────────────────────────────────────────────────── HEALTHCHECK --interval=30s --timeout=10s --start-period=120s --retries=5 \ CMD curl -f http://localhost:7860/_stcore/health || exit 1 # ── Start supervisor ────────────────────────────────────────────────────────── CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/supervisord.conf"]