File size: 1,105 Bytes
e4ef1fc
f332108
 
 
 
 
 
 
 
 
 
e4ef1fc
f332108
 
 
 
e4ef1fc
 
 
 
 
 
 
 
f332108
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Frontend Stage
FROM node:14 as frontend

WORKDIR /frontend

COPY frontend/package*.json ./
RUN npm install

COPY frontend /frontend
RUN npm run build

# Backend Stage
FROM python:3.8-slim

WORKDIR /app

# Set environment variables for custom cache directories
ENV NPM_CONFIG_PREFIX=/app/.npm-global
ENV XDG_CACHE_HOME=/app/.cache

# Ensure cache directories exist and have correct permissions
RUN mkdir -p /app/.npm-global && chown -R 1000:0 /app/.npm-global
RUN mkdir -p /app/.cache && chown -R 1000:0 /app/.cache

# Install node to serve the React app
RUN apt-get update && apt-get install -y nodejs npm && apt-get clean

# Install FastAPI dependencies
COPY backend/app/requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy the React build from the frontend stage
COPY --from=frontend /frontend/build /app/frontend/build

# Copy the backend code
COPY backend/app /app

# Expose ports (for documentation purposes)
EXPOSE 8000
EXPOSE 3000

# Use the CMD directive to start both services
CMD uvicorn main:app --host 0.0.0.0 --port 8000 & cd frontend/build && npx serve -s -l 3000