Add Dockerfile for running FastAPI backend and React frontend in a single HF Space container
Browse files- Dockerfile +34 -0
Dockerfile
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Dockerfile
|
| 2 |
+
|
| 3 |
+
# Base image to use
|
| 4 |
+
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.8
|
| 5 |
+
|
| 6 |
+
# Set the working directory to /app
|
| 7 |
+
WORKDIR /app
|
| 8 |
+
|
| 9 |
+
# Copy the backend application files
|
| 10 |
+
COPY ./backend /app/backend
|
| 11 |
+
|
| 12 |
+
# Copy the frontend application files
|
| 13 |
+
COPY ./frontend /app/frontend
|
| 14 |
+
|
| 15 |
+
# Install dependencies for the backend
|
| 16 |
+
RUN pip install --no-cache-dir -r /app/backend/requirements.txt
|
| 17 |
+
|
| 18 |
+
# Set the environment variables for FastAPI
|
| 19 |
+
ENV MODULE_NAME=backend.main:app
|
| 20 |
+
|
| 21 |
+
# Expose port 80 for the FastAPI app
|
| 22 |
+
EXPOSE 80
|
| 23 |
+
|
| 24 |
+
# Install Node.js for frontend
|
| 25 |
+
RUN apt-get update && apt-get install -y nodejs npm
|
| 26 |
+
|
| 27 |
+
# Build the React frontend
|
| 28 |
+
RUN cd frontend && npm install && npm run build
|
| 29 |
+
|
| 30 |
+
# Serve the React app
|
| 31 |
+
RUN cp -R frontend/build /app/frontend/build
|
| 32 |
+
|
| 33 |
+
# Start the FastAPI app
|
| 34 |
+
CMD uvicorn backend.main:app --host 0.0.0.0 --port 80 --reload
|