File size: 2,409 Bytes
7632cf2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# ==========================================
# Stage 1: Build Frontend (React/TS/Vite)
# ==========================================
FROM node:20-slim AS frontend-builder
WORKDIR /app/frontend

# Copy frontend definitions
COPY frontend/package.json frontend/package-lock.json* ./
RUN npm install

# Copy source and build
COPY frontend/ ./
RUN npm run build

# ==========================================
# Stage 2: Build Backend (Golang)
# ==========================================
FROM golang:1.23 AS backend-builder
WORKDIR /app/backend

# Copy Go source
COPY main.go .

# Build static binary
RUN go mod init vchat-server && \
    go mod tidy && \
    CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o vchat-server main.go

# ==========================================
# Stage 3: Final Runtime (Hugging Face Space - API Lite)
# ==========================================
FROM python:3.11-slim

# Default to LITE_MODE=true for HF Spaces (API Only)
ENV PYTHONUNBUFFERED=1 \
    DEBIAN_FRONTEND=noninteractive \
    LITE_MODE=true \
    PATH="/home/user/.local/bin:$PATH" \
    PIP_NO_CACHE_DIR=1

# Create a non-root user (Required for HF Spaces)
RUN useradd -m -u 1000 user

WORKDIR /app

# 1. Install System Dependencies (FFmpeg required for yt-dlp)
RUN apt-get update && apt-get install -y --no-install-recommends \
    ffmpeg \
    git \
    curl \
    gnupg \
    ca-certificates \
    && rm -rf /var/lib/apt/lists/*

# 2. Install Python Dependencies
RUN pip install uv
COPY requirements.txt ./
RUN uv pip install --system -r requirements.txt
# Explicitly force latest yt-dlp to handle Twitter/X API changes
RUN uv pip install --system --upgrade "yt-dlp[default]"

# 3. Copy Python Application Code
COPY --chown=user src/ ./src/

# 4. Install Built Artifacts
COPY --from=backend-builder --chown=user /app/backend/vchat-server /app/vchat-server
RUN mkdir -p /app/static
COPY --from=frontend-builder --chown=user /app/frontend/dist /app/static

# 5. Setup Directories and Permissions
RUN mkdir -p /app/data /app/data/videos /app/data/labels /app/data/prompts /app/data/responses /app/metadata \
    && chown -R user:user /app/data /app/metadata

# 6. Setup Entrypoint
COPY --chown=user start.sh /app/start.sh
RUN sed -i 's/\r$//' /app/start.sh && \
    chmod +x /app/start.sh

# Switch to non-root user
USER user

# Expose the HF Space port
EXPOSE 7860

# Run the Orchestrator
CMD ["/app/start.sh"]