Spaces:
Building
Building
added Docker
Browse files- Dockerfile +42 -0
Dockerfile
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Use a multi-stage build to optimize the image size
|
2 |
+
|
3 |
+
# Stage 1: Build React frontend
|
4 |
+
FROM node:14 as frontend-builder
|
5 |
+
|
6 |
+
WORKDIR /app/frontend
|
7 |
+
|
8 |
+
# Copy frontend code
|
9 |
+
COPY frontend/package*.json ./
|
10 |
+
RUN npm install
|
11 |
+
|
12 |
+
COPY frontend/ ./
|
13 |
+
RUN npm run build
|
14 |
+
|
15 |
+
# Stage 2: Build FastAPI backend
|
16 |
+
FROM python:3.8-slim as backend-builder
|
17 |
+
|
18 |
+
WORKDIR /app/backend
|
19 |
+
|
20 |
+
# Copy backend code
|
21 |
+
COPY backend/requirements.txt ./
|
22 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
23 |
+
|
24 |
+
COPY backend/ ./
|
25 |
+
|
26 |
+
# Stage 3: Final stage
|
27 |
+
FROM python:3.8-slim
|
28 |
+
|
29 |
+
WORKDIR /app
|
30 |
+
|
31 |
+
# Copy built frontend from the first stage
|
32 |
+
COPY --from=frontend-builder /app/frontend/build /app/frontend/build
|
33 |
+
|
34 |
+
# Copy backend from the second stage
|
35 |
+
COPY --from=backend-builder /app/backend /app/backend
|
36 |
+
|
37 |
+
# Expose ports
|
38 |
+
EXPOSE 7860
|
39 |
+
EXPOSE 8000
|
40 |
+
|
41 |
+
# Start both frontend and backend
|
42 |
+
CMD ["sh", "-c", "cd /app/backend && uvicorn main:app --host 0.0.0.0 --port 8000 & cd /app/frontend/build && serve -s -l 7860"]
|