| # ========================================== | |
| # 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"] | |