Update Dockerfile
Browse files- 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 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
| 17 |
|
|
|
|
| 18 |
RUN useradd -m appuser
|
| 19 |
-
|
| 20 |
-
|
|
|
|
| 21 |
chown -R appuser:appuser /app/.cache
|
| 22 |
|
| 23 |
# Switch to non-root user
|
| 24 |
USER appuser
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
WORKDIR /app
|
| 29 |
|
| 30 |
-
#
|
| 31 |
-
RUN python3 -m pip install --upgrade pip &&
|
|
|
|
| 32 |
|
| 33 |
-
# Install
|
| 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
|
| 41 |
RUN mkdir -p /app/static
|
| 42 |
COPY --from=frontend /app/frontend/dist/ /app/static/
|
| 43 |
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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"]
|