File size: 1,970 Bytes
1947612
 
 
 
 
 
 
 
95ddc8a
 
 
1947612
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e89a065
1947612
 
95ddc8a
1947612
 
 
95ddc8a
e89a065
 
95ddc8a
1947612
 
e89a065
1947612
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Use Python 3.11-slim as the robust base image
FROM python:3.11-slim

# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV PORT=7860

# HF model repo where dermavision.onnx is stored (override with --build-arg)
ARG HF_MODEL_REPO=WilfredAyine/dermavision-onnx

WORKDIR /app

# Install system dependencies, curl, OpenCV support, Node.js 20,
# and native build tools required by better-sqlite3 (node-gyp)
RUN apt-get update && apt-get install -y --no-install-recommends \
    curl \
    libglib2.0-0 \
    libgl1 \
    build-essential \
    python3-dev \
    libsqlite3-dev \
    && curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
    && apt-get install -y nodejs \
    && rm -rf /var/lib/apt/lists/*

# ---- Prepare Django Python Backend ----
COPY backend/requirements.txt ./backend/requirements.txt
# Upgrade pip and install requirements + gunicorn + huggingface_hub for model download
RUN pip install --no-cache-dir --upgrade pip setuptools wheel \
    && pip install --no-cache-dir -r ./backend/requirements.txt \
    && pip install --no-cache-dir gunicorn huggingface_hub

COPY backend/ ./backend/

# ---- Download ONNX model from Hugging Face Hub ----
# Single-line form required — Dockerfile parser breaks on multi-line python3 -c "..." blocks
RUN python3 -c "import pathlib, huggingface_hub; dst=pathlib.Path('/app/backend/model'); dst.mkdir(parents=True, exist_ok=True); huggingface_hub.hf_hub_download(repo_id='${HF_MODEL_REPO}', filename='dermavision.onnx', local_dir=str(dst)); print('Model downloaded OK')"

# ---- Prepare Node.js & React Frontend ----
COPY package*.json ./
# Force installation of devDependencies (Vite, esbuild, typescript) for building
RUN npm ci --include=dev

COPY . .
# Build both the Vite frontend and bundle the Express server
RUN npm run build

# Copy start script
COPY start.sh ./start.sh
RUN chmod +x ./start.sh

# Hugging Face Spaces expects port 7860
EXPOSE 7860

CMD ["./start.sh"]