# DeepFake Detector API - Docker Image # Unified Dockerfile for local, Railway, and HF Spaces FROM python:3.11-slim # Set working directory WORKDIR /app # Set environment variables ENV PYTHONDONTWRITEBYTECODE=1 \ PYTHONUNBUFFERED=1 \ PIP_NO_CACHE_DIR=1 \ PIP_DISABLE_PIP_VERSION_CHECK=1 \ PORT=7860 \ HF_CACHE_DIR=/app/.hf_cache \ HF_HUB_CACHE=/app/.hf_cache \ HF_HOME=/app/.hf_cache/hf_home \ HF_XET_CACHE=/app/.hf_cache/xet # Create non-root user (HF Spaces requirement) RUN useradd -m -u 1000 user USER user # Set PATH for user-installed packages ENV PATH="/home/user/.local/bin:$PATH" # Install runtime dependencies by default (inference + explainability + LLM). # Optional dependencies are local test tools. ARG INSTALL_OPTIONAL_DEPS=false COPY --chown=user:user requirements-runtime.txt requirements-optional.txt requirements.txt ./ RUN pip install --no-cache-dir --upgrade -r requirements-runtime.txt \ && if [ "$INSTALL_OPTIONAL_DEPS" = "true" ]; then \ pip install --no-cache-dir --upgrade -r requirements-optional.txt; \ fi # Copy only files required for model prefetch first. COPY --chown=user:user app /app/app COPY --chown=user:user start.sh /app/start.sh # Switch to root to create cache directory and set permissions USER root RUN mkdir -p /app/.hf_cache /app/.hf_cache/hf_home /app/.hf_cache/xet \ && chown -R user:user /app/.hf_cache \ && chmod +x /app/start.sh # Switch back to user USER user # Expose default app port EXPOSE 7860 # Run the application (start.sh uses PORT env var) CMD ["./start.sh"]