File size: 2,886 Bytes
a39d8ef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1c64977
 
 
a39d8ef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# nl2sql-bench/server/Dockerfile
# ─────────────────────────────────────────────────────────────────────────────
# NL2SQL-Bench OpenEnv Server
# Hugging Face Spaces compatible (port 7860, non-root user).
# Build:  docker build -t nl2sql-bench:latest .
# Run:    docker run -p 7860:7860 nl2sql-bench:latest
# ─────────────────────────────────────────────────────────────────────────────

FROM python:3.11-slim

# HF Spaces runs as non-root by default
ARG UID=1000
RUN useradd -m -u $UID appuser

WORKDIR /app

# ── System deps ───────────────────────────────────────────────────────────
RUN apt-get update -qq && \
    apt-get install -y --no-install-recommends curl && \
    rm -rf /var/lib/apt/lists/*

# ── Python deps ───────────────────────────────────────────────────────────
COPY server/requirements.txt /app/requirements.txt
RUN pip install --no-cache-dir -r requirements.txt

# ── Application code ──────────────────────────────────────────────────────
# Copy server code
COPY server/ /app/server/
# Copy shared models (client imports from parent β€” we flatten for Docker)
COPY models.py /app/models.py

# Flatten server submodules into /app so Python can find them
# (avoids complex PYTHONPATH games inside the container)
RUN cp -r /app/server/tasks /app/tasks && \
    cp -r /app/server/db    /app/db    && \
    cp    /app/server/grader.py      /app/grader.py && \
    cp    /app/server/environment.py /app/environment.py && \
    cp    /app/server/app.py         /app/app.py

# 🚨 CRITICAL FIX: Give appuser ownership of /app so SQLite can create the database
RUN chown -R appuser:appuser /app

# ── Runtime config ────────────────────────────────────────────────────────
ENV PYTHONPATH=/app
ENV PYTHONUNBUFFERED=1
# HF Spaces requires port 7860
ENV PORT=7860
ENV NL2SQL_DEFAULT_TASK=simple-filter
ENV NL2SQL_MAX_STEPS=5

USER appuser
WORKDIR /app

EXPOSE 7860

HEALTHCHECK --interval=30s --timeout=10s --start-period=15s --retries=3 \
    CMD curl -sf http://localhost:${PORT}/health || exit 1

CMD ["sh", "-c", "uvicorn app:app --host 0.0.0.0 --port ${PORT} --workers 2 --log-level info"]