PlatDetect / Dockerfile
haisyam's picture
Update kodingan PlatDetect
1f6c75f
Raw History Blame Contribute Delete
2.4 kB
# ═══════════════════════════════════════════════════════════════════════════
# PRODUK AI β€” Dockerfile for Hugging Face Spaces
# Multi-stage build: Node (frontend) β†’ Python (backend + serve)
# ═══════════════════════════════════════════════════════════════════════════
# ── Stage 1: Build Frontend ────────────────────────────────────────────────
FROM node:20-slim AS frontend-builder
WORKDIR /app/frontend
# Install dependencies
COPY frontend/package.json frontend/package-lock.json* ./
RUN npm ci --no-audit --no-fund
# Copy source & build
COPY frontend/ ./
# Set empty API base URL so frontend uses same origin in production
ENV VITE_API_BASE_URL=""
RUN npm run build
# ── Stage 2: Python Backend + Serve Frontend ──────────────────────────────
FROM python:3.12-slim
# System deps for OpenCV headless & general build
RUN apt-get update && apt-get install -y --no-install-recommends \
libgl1 \
libglib2.0-0 \
libsm6 \
libxext6 \
libxrender1 \
&& rm -rf /var/lib/apt/lists/*
# Create non-root user (HF Spaces requirement)
RUN useradd -m -u 1000 user
USER user
ENV HOME=/home/user \
PATH=/home/user/.local/bin:$PATH
WORKDIR /home/user/app
# Install Python dependencies
COPY --chown=user backend/requirements.txt ./requirements.txt
RUN pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir -r requirements.txt
# Copy backend source
COPY --chown=user backend/ ./
# Copy built frontend from stage 1
COPY --from=frontend-builder --chown=user /app/frontend/dist ./frontend_dist
# Create necessary directories
RUN mkdir -p uploads results data models
# Expose port 7860 (HF Spaces default)
EXPOSE 7860
# Health check
HEALTHCHECK --interval=30s --timeout=10s --retries=3 \
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:7860/health')" || exit 1
# Start the backend
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]