Pulastya-B commited on
Commit
9f49815
·
unverified ·
1 Parent(s): c10a976

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +30 -22
Dockerfile CHANGED
@@ -1,21 +1,24 @@
1
- # Multi-stage build for Google Cloud Run
2
  # Stage 1: Build Frontend
3
- FROM node:20-alpine as frontend-builder
 
4
 
5
  WORKDIR /frontend
6
 
7
- # Copy frontend files
8
  COPY FRRONTEEEND/package*.json ./
9
  RUN npm install
10
 
11
  COPY FRRONTEEEND/ ./
12
  RUN npm run build
13
 
 
 
14
  # Stage 2: Build Python environment
15
- FROM python:3.13-slim as builder
 
16
 
17
- # Install system dependencies
18
- RUN apt-get update && apt-get install -y \
19
  gcc \
20
  g++ \
21
  make \
@@ -25,51 +28,56 @@ RUN apt-get update && apt-get install -y \
25
  RUN python -m venv /opt/venv
26
  ENV PATH="/opt/venv/bin:$PATH"
27
 
28
- # Copy requirements and install Python packages
 
 
 
29
  COPY requirements.txt .
30
- RUN pip install --no-cache-dir --upgrade pip && \
31
- pip install --no-cache-dir -r requirements.txt
32
 
 
 
33
  # Stage 3: Runtime environment
34
- FROM python:3.13-slim
 
35
 
36
- # Install runtime dependencies only
37
- RUN apt-get update && apt-get install -y \
38
  libgomp1 \
 
39
  && rm -rf /var/lib/apt/lists/*
40
 
41
- # Copy virtual environment from builder
42
  COPY --from=builder /opt/venv /opt/venv
43
  ENV PATH="/opt/venv/bin:$PATH"
44
 
45
- # Set working directory
46
  WORKDIR /app
47
 
48
- # Copy application code
49
  COPY src/ /app/src/
50
  COPY examples/ /app/examples/
51
 
52
- # Copy built frontend from frontend-builder
53
  COPY --from=frontend-builder /frontend/dist /app/FRRONTEEEND/dist
54
 
55
- # Create necessary directories for Cloud Run ephemeral storage
56
- RUN mkdir -p /tmp/data_science_agent \
 
57
  /tmp/outputs/models \
58
  /tmp/outputs/plots \
59
  /tmp/outputs/reports \
60
  /tmp/outputs/data \
61
  /tmp/cache_db
62
 
63
- # Set environment variables
64
  ENV PYTHONUNBUFFERED=1
65
  ENV PORT=8080
66
  ENV OUTPUT_DIR=/tmp/outputs
67
  ENV CACHE_DB_PATH=/tmp/cache_db/cache.db
68
  ENV ARTIFACT_BACKEND=local
69
 
70
- # Cloud Run expects the service to listen on the PORT env variable
71
  EXPOSE 8080
72
 
73
- # Run the FastAPI application with uvicorn
74
  CMD ["uvicorn", "src.api.app:app", "--host", "0.0.0.0", "--port", "8080"]
75
-
 
1
+ # ===============================
2
  # Stage 1: Build Frontend
3
+ # ===============================
4
+ FROM node:20-alpine AS frontend-builder
5
 
6
  WORKDIR /frontend
7
 
 
8
  COPY FRRONTEEEND/package*.json ./
9
  RUN npm install
10
 
11
  COPY FRRONTEEEND/ ./
12
  RUN npm run build
13
 
14
+
15
+ # ===============================
16
  # Stage 2: Build Python environment
17
+ # ===============================
18
+ FROM python:3.12-slim AS builder
19
 
20
+ # Install build dependencies (needed for ML wheels)
21
+ RUN apt-get update && apt-get install -y --no-install-recommends \
22
  gcc \
23
  g++ \
24
  make \
 
28
  RUN python -m venv /opt/venv
29
  ENV PATH="/opt/venv/bin:$PATH"
30
 
31
+ # Upgrade pip tooling
32
+ RUN pip install --upgrade pip setuptools wheel
33
+
34
+ # Install Python dependencies
35
  COPY requirements.txt .
36
+ RUN pip install --no-cache-dir -r requirements.txt
 
37
 
38
+
39
+ # ===============================
40
  # Stage 3: Runtime environment
41
+ # ===============================
42
+ FROM python:3.12-slim
43
 
44
+ # Install runtime shared libraries
45
+ RUN apt-get update && apt-get install -y --no-install-recommends \
46
  libgomp1 \
47
+ libstdc++6 \
48
  && rm -rf /var/lib/apt/lists/*
49
 
50
+ # Copy virtual environment
51
  COPY --from=builder /opt/venv /opt/venv
52
  ENV PATH="/opt/venv/bin:$PATH"
53
 
54
+ # App working directory
55
  WORKDIR /app
56
 
57
+ # Copy backend code
58
  COPY src/ /app/src/
59
  COPY examples/ /app/examples/
60
 
61
+ # Copy frontend build
62
  COPY --from=frontend-builder /frontend/dist /app/FRRONTEEEND/dist
63
 
64
+ # Cloud Run ephemeral directories
65
+ RUN mkdir -p \
66
+ /tmp/data_science_agent \
67
  /tmp/outputs/models \
68
  /tmp/outputs/plots \
69
  /tmp/outputs/reports \
70
  /tmp/outputs/data \
71
  /tmp/cache_db
72
 
73
+ # Environment variables
74
  ENV PYTHONUNBUFFERED=1
75
  ENV PORT=8080
76
  ENV OUTPUT_DIR=/tmp/outputs
77
  ENV CACHE_DB_PATH=/tmp/cache_db/cache.db
78
  ENV ARTIFACT_BACKEND=local
79
 
 
80
  EXPOSE 8080
81
 
82
+ # Start FastAPI
83
  CMD ["uvicorn", "src.api.app:app", "--host", "0.0.0.0", "--port", "8080"]