Spaces:
Running
Running
“vinit5112”
commited on
Commit
·
604e0d1
1
Parent(s):
5d2f496
combine docker
Browse files- Dockerfile +47 -0
- backend/Dockerfile +0 -19
- docker-compose.yml +0 -20
- frontend/Dockerfile +0 -34
- start.sh +7 -0
Dockerfile
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Root-level Dockerfile
|
2 |
+
|
3 |
+
# Stage 1: Build React frontend
|
4 |
+
FROM node:18-alpine AS frontend-build
|
5 |
+
|
6 |
+
WORKDIR /app/frontend
|
7 |
+
|
8 |
+
COPY frontend/package.json frontend/package-lock.json ./
|
9 |
+
RUN npm install
|
10 |
+
|
11 |
+
COPY frontend/ ./
|
12 |
+
RUN npm run build
|
13 |
+
|
14 |
+
|
15 |
+
# Stage 2: Build Python backend + serve frontend with Nginx
|
16 |
+
FROM python:3.9-slim
|
17 |
+
|
18 |
+
WORKDIR /app
|
19 |
+
|
20 |
+
# Install Python dependencies
|
21 |
+
COPY backend/requirements.txt .
|
22 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
23 |
+
|
24 |
+
# Copy backend code
|
25 |
+
COPY backend/ /app/backend
|
26 |
+
|
27 |
+
# Copy built frontend from previous stage
|
28 |
+
COPY --from=frontend-build /app/frontend/build /app/frontend_build
|
29 |
+
|
30 |
+
# Install nginx
|
31 |
+
RUN apt-get update && apt-get install -y nginx && rm -rf /var/lib/apt/lists/*
|
32 |
+
|
33 |
+
# Copy nginx config
|
34 |
+
COPY frontend/nginx.conf /etc/nginx/conf.d/default.conf
|
35 |
+
|
36 |
+
# Link built frontend to nginx root
|
37 |
+
RUN rm -rf /usr/share/nginx/html && \
|
38 |
+
ln -s /app/frontend_build /usr/share/nginx/html
|
39 |
+
|
40 |
+
# Copy script to run both frontend and backend
|
41 |
+
COPY start.sh /start.sh
|
42 |
+
RUN chmod +x /start.sh
|
43 |
+
|
44 |
+
# Expose Hugging Face compatible port
|
45 |
+
EXPOSE 7860
|
46 |
+
|
47 |
+
CMD ["/start.sh"]
|
backend/Dockerfile
DELETED
@@ -1,19 +0,0 @@
|
|
1 |
-
FROM python:3.9-slim
|
2 |
-
|
3 |
-
# Set the working directory in the container
|
4 |
-
WORKDIR /app
|
5 |
-
|
6 |
-
# Copy the requirements file and install dependencies
|
7 |
-
COPY requirements.txt .
|
8 |
-
RUN pip install --no-cache-dir -r requirements.txt
|
9 |
-
|
10 |
-
# Copy the rest of the backend application code
|
11 |
-
COPY . .
|
12 |
-
|
13 |
-
# Expose the port the app runs on
|
14 |
-
EXPOSE 8000
|
15 |
-
|
16 |
-
# Command to run the application
|
17 |
-
# We use app_v2:app because your main FastAPI instance is in the app_v2.py file.
|
18 |
-
# --host 0.0.0.0 makes the app accessible from outside the container.
|
19 |
-
CMD ["uvicorn", "app_v2:app", "--host", "0.0.0.0", "--port", "8000"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
docker-compose.yml
DELETED
@@ -1,20 +0,0 @@
|
|
1 |
-
version: '3.8'
|
2 |
-
|
3 |
-
services:
|
4 |
-
backend:
|
5 |
-
build:
|
6 |
-
context: ./backend
|
7 |
-
dockerfile: Dockerfile
|
8 |
-
image: ca-study-assistant-backend
|
9 |
-
container_name: backend-container
|
10 |
-
restart: unless-stopped
|
11 |
-
|
12 |
-
frontend:
|
13 |
-
build:
|
14 |
-
context: ./frontend
|
15 |
-
dockerfile: Dockerfile
|
16 |
-
image: ca-study-assistant-frontend
|
17 |
-
container_name: frontend-container
|
18 |
-
restart: unless-stopped
|
19 |
-
depends_on:
|
20 |
-
- backend # Ensures the backend starts before the frontend
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
frontend/Dockerfile
DELETED
@@ -1,34 +0,0 @@
|
|
1 |
-
# Stage 1: Build the React application
|
2 |
-
FROM node:18-alpine AS build
|
3 |
-
|
4 |
-
WORKDIR /app
|
5 |
-
|
6 |
-
# Copy package.json and package-lock.json
|
7 |
-
COPY package.json package-lock.json ./
|
8 |
-
|
9 |
-
# Install dependencies
|
10 |
-
RUN npm install
|
11 |
-
|
12 |
-
# Copy the rest of the application source code
|
13 |
-
COPY . .
|
14 |
-
|
15 |
-
# Build the application
|
16 |
-
RUN npm run build
|
17 |
-
|
18 |
-
# Stage 2: Serve the application with Nginx
|
19 |
-
FROM nginx:1.23-alpine
|
20 |
-
|
21 |
-
# Copy the build output from the build stage
|
22 |
-
COPY --from=build /app/build /usr/share/nginx/html
|
23 |
-
|
24 |
-
# Remove the default Nginx configuration
|
25 |
-
RUN rm /etc/nginx/conf.d/default.conf
|
26 |
-
|
27 |
-
# Copy our custom Nginx configuration
|
28 |
-
COPY nginx.conf /etc/nginx/conf.d
|
29 |
-
|
30 |
-
# Expose port 80
|
31 |
-
EXPOSE 7860
|
32 |
-
|
33 |
-
# Start Nginx
|
34 |
-
CMD ["nginx", "-g", "daemon off;"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
start.sh
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/bin/bash
|
2 |
+
|
3 |
+
# Run backend (FastAPI via Uvicorn) in background
|
4 |
+
uvicorn backend.app_v2:app --host 0.0.0.0 --port 8000 &
|
5 |
+
|
6 |
+
# Start Nginx to serve frontend
|
7 |
+
nginx -g "daemon off;"
|