File size: 2,186 Bytes
7a87926
 
 
 
4dc6d9d
7a87926
 
 
 
6cd1f48
7a87926
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71f27c0
7a87926
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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

# ==========================================
# 1. Frontend Build Stage
# ==========================================
FROM node:22-alpine AS frontend-builder
WORKDIR /app/frontend

# Install dependencies
COPY web-ui/package.json web-ui/yarn.lock ./
RUN yarn install

# Copy source and build
COPY web-ui/ ./
# This will output to /app/frontend/out due to "output: 'export'" in next.config.ts
RUN yarn build

# ==========================================
# 2. Runtime Stage (Python/FastAPI)
# ==========================================
FROM python:3.9-slim

WORKDIR /app

# Install system dependencies
# git: for cloning dependencies
# libgl1-mesa-glx: for cv2 (opencv) which is often used in vision tasks
# libglib2.0-0: for cv2
RUN apt-get update && apt-get install -y \
    git \
    libgl1 \
    libglib2.0-0 \
    && rm -rf /var/lib/apt/lists/*

# Install Python dependencies
COPY requirements.txt .
# Ensure pip is up to date and install deps
# We add aiofiles manually as it is required for serving StaticFiles
RUN pip install --no-cache-dir --upgrade pip && \
    pip install --no-cache-dir aiofiles && \
    pip install --no-cache-dir -r requirements.txt

# Install 'depth-anything-3' from source (same as base ecr image logic but inline)
# Clone and install to ensure api.py is available
RUN git clone --depth 1 https://github.com/ByteDance-Seed/Depth-Anything-3.git /tmp/depth-anything-3 && \
    pip install --no-cache-dir /tmp/depth-anything-3 && \
    rm -rf /tmp/depth-anything-3

# Install local package
COPY . .
RUN pip install --no-cache-dir -e .

# Copy built frontend assets
COPY --from=frontend-builder /app/frontend/out /app/static

# Set up data directories with user permissions (HF user is 1000)
# We set HOME to /data so caching mostly goes there if configured
ENV DATA_DIR=/data
RUN mkdir -p /data/checkpoints /data/uploaded_datasets /data/preprocessed && \
    chmod -R 777 /data

# Configure HF Cache to use writable space
ENV XDG_CACHE_HOME=/data/.cache

# Expose HF Spaces port
EXPOSE 7860

# Start command: Use the specific HF entrypoint that serves static files
CMD ["uvicorn", "ylff.hf_server:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1"]