File size: 1,608 Bytes
7ee6359
 
 
 
 
 
 
 
 
 
 
 
 
db10084
7bd3f6d
 
 
 
7ee6359
 
 
 
 
 
 
 
a46b08f
 
 
 
 
 
 
 
7ee6359
db10084
 
 
7ee6359
 
 
7bd3f6d
 
 
7ee6359
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# 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"]