# 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