File size: 2,813 Bytes
0d3f7cc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# ──────────────────────────────────────────────────────────────────────
# VGTC Compliance API β€” Hugging Face Spaces Dockerfile
# ──────────────────────────────────────────────────────────────────────

FROM python:3.11-slim AS builder

SHELL ["/bin/bash", "-o", "pipefail", "-e", "-u", "-x", "-c"]

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

RUN pip install --no-cache-dir uv==0.4.10

WORKDIR /app
COPY pyproject.toml README.md ./
COPY src/ src/

RUN uv venv /opt/vgtc \
    && . /opt/vgtc/bin/activate \
    && uv pip install --no-cache-dir --compile-bytecode "hatchling>=1.21,<2" \
    && uv pip install --no-cache-dir --compile-bytecode .


# ══════════════════════════════════════════════════════════════════════
# Stage 2: Production
# ══════════════════════════════════════════════════════════════════════
FROM python:3.11-slim AS production

SHELL ["/bin/bash", "-o", "pipefail", "-e", "-u", "-c"]

RUN apt-get update && apt-get install -y --no-install-recommends \
    curl ca-certificates tini && rm -rf /var/lib/apt/lists/*

# Hugging Face requires user with UID 1000
RUN useradd -m -u 1000 user \
    && mkdir -p /app/data /app/logs /app/cache /home/user/.cache/hermes/sanctions \
    && chown -R user:user /app /home/user

COPY --from=builder --chown=user:user /opt/vgtc /opt/vgtc
COPY --chown=user:user src/ src/
COPY --chown=user:user pyproject.toml ./

ENV PATH="/opt/vgtc/bin:${PATH}" \
    PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1 \
    PYTHONHASHSEED=random \
    HOME=/home/user \
    HERMES_ENVIRONMENT=production \
    SECURITY_ENABLE_AUTH=false

USER user
WORKDIR /app

# Pre-bake Sanctions Data to avoid cold start downloads!
RUN python -c "from hermes.tools.sanctions import get_engine; print('Pre-baking Sanctions Data...'); get_engine(); print('Done!')"

EXPOSE 7860

HEALTHCHECK --interval=30s --timeout=10s --retries=5 --start-period=60s \
    CMD curl -sf http://localhost:7860/docs || exit 1

ENTRYPOINT ["tini", "--"]
CMD ["sh", "-c", "uvicorn hermes.api.server:server --host 0.0.0.0 --port 7860 --workers 2 --loop uvloop --http httptools --log-level info --access-log --proxy-headers --forwarded-allow-ips '*'"]