File size: 3,060 Bytes
e5e36db
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c7f18d9
 
e5e36db
 
 
 
 
 
 
 
 
7f5d26e
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# =============================================================================
# Dockerfile  v1.2.0
# Multi-stage build — slim production image.
#
# Build:  docker build -t info-integrity-env .
# Run:    docker run --env-file .env -p 7860:7860 info-integrity-env
#
# Evaluation path (no external services needed):
#   docker run --env-file .env info-integrity-env \
#     python inference.py --benchmark --out /tmp/results.json
#
# Required .env keys for the API server:
#   HF_TOKEN                       (for inference.py)
#   MODEL_NAME=Qwen/Qwen2.5-72B-Instruct
#   API_BASE_URL=https://router.huggingface.co/v1
#
# Optional (only needed for live data collection via /collect):
#   SERPAPI_KEY / NEWSAPI_KEY / BRAVE_SEARCH_KEY / GOOGLE_FACTCHECK_KEY
#   REDIS_URL=redis://redis:6379
# =============================================================================

# ---- Stage 1: builder ----
FROM python:3.11-slim AS builder

WORKDIR /app

RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential \
    && rm -rf /var/lib/apt/lists/*

COPY requirements.txt .
RUN pip install --no-cache-dir --upgrade pip \
 && pip install --no-cache-dir -r requirements.txt

# ---- Stage 2: runtime ----
FROM python:3.11-slim AS runtime

WORKDIR /app

# Copy installed packages from builder
COPY --from=builder /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages
COPY --from=builder /usr/local/bin /usr/local/bin

# Copy application source
COPY models.py            ./models.py
COPY environment.py       ./environment.py
COPY reward.py            ./reward.py
COPY explainability.py    ./explainability.py
COPY data_collector.py    ./data_collector.py
COPY app.py             ./app.py
COPY server.py          ./server.py
COPY inference.py         ./inference.py
COPY reward_config.yaml   ./reward_config.yaml
COPY openenv.yaml         ./openenv.yaml
COPY README.md            ./README.md

# Copy optional config files if they exist
COPY domain_reliability.yaml* ./

# Copy tasks package (graders + registry + deterministic scenario datasets)
COPY tasks/               ./tasks/

# Non-root user for security
RUN useradd -m -u 1000 appuser && chown -R appuser:appuser /app
USER appuser

# Environment defaults (override via --env-file or -e flags)
ENV PYTHONUNBUFFERED=1 \
    PYTHONDONTWRITEBYTECODE=1 \
    HOST=0.0.0.0 \
    PORT=7860 \
    LOG_LEVEL=info \
    REDIS_URL=redis://localhost:6379 \
    SESSION_TTL_SECONDS=3600 \
    CACHE_TTL_SECONDS=86400 \
    MAX_SOURCES_PER_CLAIM=8 \
    REQUEST_TIMEOUT=10 \
    BENCHMARK_SEED=42 \
    MAX_STEPS=20 \
    GRADIO_ANALYTICS_ENABLED=false \
    PYTHONPATH=/app

EXPOSE 7860

# Use Python's built-in urllib — no curl dependency needed in runtime
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
  CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:7860/health', timeout=8)"

# Default: start the API server
# Override for benchmark: docker run ... python inference.py --benchmark
CMD ["python", "app.py"]