1- # Stage 1: Build the React app
2- FROM node:18-alpine AS build-frontend
3-
4- # Set working directory for React app
5- WORKDIR /app/frontend-react
6-
7- # Copy the React app package.json and install dependencies
8- COPY frontend-react/package.json frontend-react/package-lock.json ./
9- RUN npm install
10-
11- # Copy the rest of the React app files and build the app
12- COPY frontend-react/ ./
13- RUN npm run build
14-
15- # Stage 2: Set up the FastAPI backend with Python 3.11.6
16- FROM python:3.11.6-slim AS build-backend
17-
18- # Set working directory for FastAPI backend
19- WORKDIR /app
20-
21- # Copy the requirements file and install Python dependencies
22- COPY requirements.txt .
23- RUN pip install --no-cache-dir -r requirements.txt
24-
25- # Copy the FastAPI source code
26- COPY app.py ./
27- COPY src/ ./src/
28-
29- # Copy the built React app from the first stage to the FastAPI static folder
30- COPY --from=build-frontend /app/frontend-react/build ./frontend_build
31-
32- # Expose the port FastAPI will run on
33- EXPOSE 8000
34-
35- # Command to run the FastAPI app
36- CMD ["uvicorn" , "app:app" , "--host" , "0.0.0.0" , "--port" , "8000" ]
1+ # ----- Stage 1: Build the React frontend -----
2+ FROM node:16-alpine AS frontend-build
3+
4+ # Set the working directory for the frontend
5+ WORKDIR /frontend
6+
7+ # Copy package.json and package-lock.json
8+ COPY frontend/package*.json ./
9+
10+ # Install npm dependencies
11+ RUN npm install
12+
13+ # Copy the rest of the frontend code
14+ COPY frontend/ .
15+
16+ # Build the React app
17+ RUN npm run build
18+
19+ # ----- Stage 2: Set up the FastAPI backend -----
20+ FROM python:3.10-slim AS backend
21+
22+ # Set the working directory for the backend
23+ WORKDIR /app
24+
25+ # Copy backend requirements
26+ COPY backend/requirements.txt .
27+
28+ # Install Python dependencies
29+ RUN pip install --no-cache-dir -r requirements.txt
30+
31+ # Copy the backend source code
32+ COPY backend/ .
33+
34+ # Copy the frontend build output from the previous stage
35+ COPY --from=frontend-build /frontend/build ./frontend/build
36+
37+ # Expose the backend port
38+ EXPOSE 8000
39+
40+ # Command to run the FastAPI app
41+ CMD ["uvicorn" , "app:app" , "--host" , "0.0.0.0" , "--port" , "8000" ]
42+
0 commit comments