File size: 3,440 Bytes
6aa6081
 
38a891d
6aa6081
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1f52113
38a891d
 
6aa6081
 
 
 
 
 
 
 
 
 
 
5e480e2
6aa6081
 
 
 
1f52113
38a891d
1f52113
 
38a891d
1f52113
6aa6081
 
1f52113
 
6aa6081
 
 
 
 
 
 
1f52113
 
 
 
6aa6081
38a891d
6aa6081
1f52113
 
38a891d
 
 
 
 
 
 
1f52113
 
6aa6081
1f52113
6aa6081
 
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
# syntax=docker/dockerfile:1
# ---------------------------------------------------------------------------
# Talos Access — image for Hugging Face Spaces / external Postgres
#   Stage 1: build the React/Vite frontend (esbuild bundle, no tsc gate)
#   Stage 2: Python backend (FastAPI + dlib/face_recognition) serving the SPA
# ---------------------------------------------------------------------------

# ---- Stage 1: frontend build ----
FROM node:22-slim AS frontend
WORKDIR /fe
COPY frontend/package.json ./
RUN npm install
COPY frontend/ ./
# Use vite directly (skip `tsc -b`): esbuild transpiles regardless of the
# project's pre-existing strict type errors; this matches how dev runs today.
RUN npx vite build

# ---- Stage 2: backend + static SPA ----
# NOTA: imagen optimizada para Hugging Face Spaces, que ejecuta el contenedor como
# UID 1000 (no root). La DB es externa (Supabase en prod, docker-compose Postgres en dev);
# sólo se necesita DATABASE_URL en runtime (HF Space secret o docker-compose env).
FROM ubuntu:24.04 AS app
ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=America/Caracas
ENV PYTHONUNBUFFERED=1

# Only runtime libs are needed: dlib ships as a prebuilt wheel (dlib-bin), so we
# avoid the heavy/OOM-prone source compile entirely. libgl1/libglib2.0-0 are for
# opencv-python-headless.
RUN apt-get update && apt-get install -y --no-install-recommends \
    python3 python3-pip \
    libgl1 libglib2.0-0 \
    libmagic1 \
    tzdata \
    && ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone \
    && rm -rf /var/lib/apt/lists/*

# Hugging Face Spaces corre como UID 1000. ubuntu:24.04 ya trae un usuario 'ubuntu'
# en UID 1000, así que lo eliminamos antes de crear 'user'.
RUN (userdel -r ubuntu 2>/dev/null || true) && useradd -m -u 1000 user
ENV HOME=/home/user \
    PATH=/home/user/.local/bin:/usr/local/bin:/usr/bin:/sbin:/bin

WORKDIR /app

# Install Python deps (system-wide, legibles por cualquier usuario). Use the prebuilt
# dlib wheel, then install the rest without rebuilding dlib/face_recognition from source.
COPY backend/requirements.txt .
RUN pip3 install --no-cache-dir --break-system-packages dlib-bin && \
    grep -ivE '^(face[-_]recognition|dlib)([=<>! ]|$)' requirements.txt > /tmp/reqs.txt && \
    pip3 install --no-cache-dir --break-system-packages -r /tmp/reqs.txt && \
    pip3 install --no-cache-dir --break-system-packages --no-deps face_recognition==1.3.0 face_recognition_models && \
    pip3 install --no-cache-dir --break-system-packages Pillow click numpy

# Backend source + built frontend (servido por FastAPI en /app/static), propiedad
# del usuario de runtime para evitar problemas de permisos en HF.
COPY --chown=user backend/ /app/
COPY --chown=user --from=frontend /fe/dist /app/static

RUN sed -i 's/\r$//' /app/entrypoint.sh && chmod +x /app/entrypoint.sh

# Config de runtime no secreta. IMPORTANTE: define JWT_SECRET_KEY como Secret del
# Space (el default 'change_me_in_production' es inseguro y el código es público).
# DATABASE_URL (Supabase URL) and POSTGRES_PASSWORD are injected at runtime
# via HF Space secrets or docker-compose environment.
ENV POSTGRES_HOST=postgres \
    POSTGRES_PORT=5432 \
    POSTGRES_USER=talos \
    POSTGRES_DB=talos_access \
    SEED_DEMO=1
# Comillas simples: Docker preserva así las comillas internas (JSON válido ["*"]).
ENV CORS_ORIGINS='["*"]'

USER user
EXPOSE 8000
CMD ["sh", "entrypoint.sh"]