Proff12 commited on
Commit
c4089f6
·
verified ·
1 Parent(s): 6c671a5

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +36 -14
Dockerfile CHANGED
@@ -1,48 +1,70 @@
1
  # --- Stage 1: Build React frontend ---
2
  FROM node:20-alpine AS frontend
 
3
  WORKDIR /app/frontend
 
 
4
  COPY frontend/package*.json ./
5
  COPY frontend/package-lock.json ./
6
- RUN npm install
 
 
7
  COPY frontend/ ./
8
  RUN npm run build
9
 
10
  # --- Stage 2: GPU-enabled Python backend ---
11
- # Requires NVIDIA Container Toolkit on host and runtime flag: --gpus all
12
  FROM nvidia/cuda:12.1.1-cudnn8-runtime-ubuntu22.04 AS backend
13
 
14
- ENV DEBIAN_FRONTEND=noninteractive PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1 PIP_NO_CACHE_DIR=1
15
-
16
- ENV HF_HOME=/app/.cache/huggingface
 
 
 
17
 
 
18
  RUN useradd -m appuser
19
- # Create cache directory and set permissions before switching
20
- RUN mkdir -p /app/.cache/huggingface/transformers && \
 
21
  chown -R appuser:appuser /app/.cache
22
 
23
  # Switch to non-root user
24
  USER appuser
25
- # Install Python and system deps
26
- RUN apt-get update && apt-get install -y --no-install-recommends python3 python3-pip python3-venv git && rm -rf /var/lib/apt/lists/*
 
 
 
27
 
28
  WORKDIR /app
29
 
30
- # Install CUDA-enabled PyTorch (cu121)
31
- RUN python3 -m pip install --upgrade pip && python3 -m pip install --index-url https://download.pytorch.org/whl/cu121 torch==2.4.1+cu121
 
32
 
33
- # Install remaining Python deps
34
  COPY backend/requirements.txt /app/backend/requirements.txt
35
  RUN python3 -m pip install -r /app/backend/requirements.txt
36
 
37
  # Copy backend code
38
  COPY backend/ /app/backend/
39
 
40
- # Copy frontend build to a static dir served by FastAPI
41
  RUN mkdir -p /app/static
42
  COPY --from=frontend /app/frontend/dist/ /app/static/
43
 
44
- ENV STATIC_DIR=/app/static MODEL_ID=FractalAIResearch/Fathom-R1-14B PIPELINE_TASK=text-generation QUANTIZE=auto
 
 
 
 
 
 
 
 
45
 
46
  EXPOSE 8000
47
 
 
48
  CMD ["uvicorn", "app.main:app", "--app-dir", "/app/backend", "--host", "0.0.0.0", "--port", "8000"]
 
1
  # --- Stage 1: Build React frontend ---
2
  FROM node:20-alpine AS frontend
3
+
4
  WORKDIR /app/frontend
5
+
6
+ # Install dependencies
7
  COPY frontend/package*.json ./
8
  COPY frontend/package-lock.json ./
9
+ RUN npm install --frozen-lockfile
10
+
11
+ # Build frontend
12
  COPY frontend/ ./
13
  RUN npm run build
14
 
15
  # --- Stage 2: GPU-enabled Python backend ---
 
16
  FROM nvidia/cuda:12.1.1-cudnn8-runtime-ubuntu22.04 AS backend
17
 
18
+ # Environment setup
19
+ ENV DEBIAN_FRONTEND=noninteractive \
20
+ PYTHONDONTWRITEBYTECODE=1 \
21
+ PYTHONUNBUFFERED=1 \
22
+ PIP_NO_CACHE_DIR=1 \
23
+ HF_HOME=/app/.cache/huggingface
24
 
25
+ # Create non-root user
26
  RUN useradd -m appuser
27
+
28
+ # Create cache directory and set permissions
29
+ RUN mkdir -p /app/.cache/huggingface && \
30
  chown -R appuser:appuser /app/.cache
31
 
32
  # Switch to non-root user
33
  USER appuser
34
+
35
+ # Install Python and system dependencies
36
+ RUN apt-get update && apt-get install -y --no-install-recommends \
37
+ python3 python3-pip python3-venv git curl && \
38
+ rm -rf /var/lib/apt/lists/*
39
 
40
  WORKDIR /app
41
 
42
+ # Upgrade pip and install CUDA-enabled PyTorch
43
+ RUN python3 -m pip install --upgrade pip && \
44
+ python3 -m pip install --index-url https://download.pytorch.org/whl/cu121 torch==2.4.1+cu121
45
 
46
+ # Install Python dependencies
47
  COPY backend/requirements.txt /app/backend/requirements.txt
48
  RUN python3 -m pip install -r /app/backend/requirements.txt
49
 
50
  # Copy backend code
51
  COPY backend/ /app/backend/
52
 
53
+ # Copy frontend build to static directory
54
  RUN mkdir -p /app/static
55
  COPY --from=frontend /app/frontend/dist/ /app/static/
56
 
57
+ # App-specific environment variables
58
+ ENV STATIC_DIR=/app/static \
59
+ MODEL_ID=FractalAIResearch/Fathom-R1-14B \
60
+ PIPELINE_TASK=text-generation \
61
+ QUANTIZE=auto
62
+
63
+ # Optional: Healthcheck endpoint
64
+ HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \
65
+ CMD curl -f http://localhost:8000/health || exit 1
66
 
67
  EXPOSE 8000
68
 
69
+ # Start FastAPI app
70
  CMD ["uvicorn", "app.main:app", "--app-dir", "/app/backend", "--host", "0.0.0.0", "--port", "8000"]