Rsr2425 commited on
Commit
cda4639
·
1 Parent(s): c1a68be

Consolidated FE hosting to FastAPI for now

Browse files
Files changed (5) hide show
  1. Dockerfile +4 -19
  2. Dockerfile.test +6 -9
  3. backend/app/main.py +24 -4
  4. run_local.sh +1 -0
  5. start.sh +0 -12
Dockerfile CHANGED
@@ -11,32 +11,17 @@ RUN npm run build
11
  # Use Python image with uv pre-installed and nginx
12
  FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim
13
 
14
- RUN apt-get update && apt-get install -y nginx
15
-
16
  WORKDIR /app
17
 
18
-
19
  # Install backend dependencies and make pytest available
20
  COPY backend/ backend/
21
  COPY pyproject.toml .
22
  RUN uv sync && uv pip install .
23
- ENV PATH="/root/.local/bin:/root/.uv/venv/bin:${PATH}"
24
-
25
- # Set up frontend
26
- COPY --from=frontend-builder /app/frontend/build /usr/share/nginx/html
27
- COPY frontend/nginx.conf /etc/nginx/conf.d/default.conf
28
-
29
- # Add uv's bin directory to PATH
30
  ENV PATH="/app/.venv/bin:/root/.local/bin:/root/.uv/venv/bin:${PATH}"
31
 
32
- EXPOSE 80 8000
33
-
34
- # Set up nginx confgi
35
- RUN mkdir -p /var/lib/nginx/body /var/cache/nginx
36
- RUN chmod -R 777 /var/lib/nginx /var/cache/nginx
37
- RUN chmod -R 755 /app/.venv
38
 
39
- COPY start.sh /start.sh
40
- RUN chmod +x /start.sh
41
 
42
- CMD ["/start.sh"]
 
11
  # Use Python image with uv pre-installed and nginx
12
  FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim
13
 
 
 
14
  WORKDIR /app
15
 
 
16
  # Install backend dependencies and make pytest available
17
  COPY backend/ backend/
18
  COPY pyproject.toml .
19
  RUN uv sync && uv pip install .
 
 
 
 
 
 
 
20
  ENV PATH="/app/.venv/bin:/root/.local/bin:/root/.uv/venv/bin:${PATH}"
21
 
22
+ # Set up frontend
23
+ COPY --from=frontend-builder /app/frontend/build /app/static
 
 
 
 
24
 
25
+ EXPOSE 80
 
26
 
27
+ CMD ["uvicorn", "backend.app.main:app", "--host", "0.0.0.0", "--port", "80"]
Dockerfile.test CHANGED
@@ -1,11 +1,12 @@
1
  # Use Node.js image for frontend
2
- FROM node:20-slim AS frontend
3
 
4
  WORKDIR /app/frontend
5
  COPY frontend/package*.json ./
6
  RUN npm install --legacy-peer-deps
7
 
8
  COPY frontend/ ./
 
9
 
10
  # Use Python image with uv pre-installed
11
  FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim
@@ -21,13 +22,9 @@ WORKDIR /app
21
  # Copy backend code
22
  COPY backend/ backend/
23
  COPY pyproject.toml .
24
-
25
- # Install backend dependencies and pytest
26
- RUN uv sync && uv pip install pytest && uv pip install .
27
- ENV PATH="/root/.local/bin:/root/.uv/venv/bin:${PATH}"
28
 
29
  # Copy frontend from builder
30
- COPY --from=frontend /app/frontend /app/frontend
31
-
32
- # Add uv's bin directory to PATH
33
- ENV PATH="/app/.venv/bin:/root/.local/bin:/root/.uv/venv/bin:${PATH}"
 
1
  # Use Node.js image for frontend
2
+ FROM node:20-slim AS frontend-builder
3
 
4
  WORKDIR /app/frontend
5
  COPY frontend/package*.json ./
6
  RUN npm install --legacy-peer-deps
7
 
8
  COPY frontend/ ./
9
+ RUN npm run build
10
 
11
  # Use Python image with uv pre-installed
12
  FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim
 
22
  # Copy backend code
23
  COPY backend/ backend/
24
  COPY pyproject.toml .
25
+ RUN uv sync && uv pip install .
26
+ ENV PATH="/app/.venv/bin:/root/.local/bin:/root/.uv/venv/bin:${PATH}"
 
 
27
 
28
  # Copy frontend from builder
29
+ COPY --from=frontend-builder /app/frontend /app/frontend
30
+ COPY --from=frontend-builder /app/frontend/build /app/static
 
 
backend/app/main.py CHANGED
@@ -1,5 +1,7 @@
1
- from fastapi import FastAPI
 
2
  from fastapi.middleware.cors import CORSMiddleware
 
3
  from pydantic import BaseModel
4
  from backend.app.problem_generator import ProblemGenerator
5
 
@@ -19,12 +21,30 @@ class UrlInput(BaseModel):
19
  class UserQuery(BaseModel):
20
  user_query: str
21
 
22
- @app.post("/crawl/")
23
  async def crawl_documentation(input_data: UrlInput):
24
  print(f"Received url {input_data.url}")
25
  return {"status": "received"}
26
 
27
- @app.post("/problems/")
28
  async def generate_problems(query: UserQuery):
29
  problems = ProblemGenerator().generate_problems(query.user_query)
30
- return {"Problems": problems}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, HTTPException
2
+ from fastapi.staticfiles import StaticFiles
3
  from fastapi.middleware.cors import CORSMiddleware
4
+ from fastapi.responses import FileResponse
5
  from pydantic import BaseModel
6
  from backend.app.problem_generator import ProblemGenerator
7
 
 
21
  class UserQuery(BaseModel):
22
  user_query: str
23
 
24
+ @app.post("/api/crawl/")
25
  async def crawl_documentation(input_data: UrlInput):
26
  print(f"Received url {input_data.url}")
27
  return {"status": "received"}
28
 
29
+ @app.post("/api/problems/")
30
  async def generate_problems(query: UserQuery):
31
  problems = ProblemGenerator().generate_problems(query.user_query)
32
+ return {"Problems": problems}
33
+
34
+ # Serve static files
35
+ app.mount("/static", StaticFiles(directory="/app/static/static"), name="static")
36
+
37
+ # Root path handler
38
+ @app.get("/")
39
+ async def serve_root():
40
+ return FileResponse("/app/static/index.html")
41
+
42
+ # Catch-all route for serving index.html
43
+ @app.get("/{full_path:path}")
44
+ async def serve_react(full_path: str):
45
+ # Skip API routes
46
+ if full_path.startswith("api/"):
47
+ raise HTTPException(status_code=404, detail="Not found")
48
+
49
+ # For all other routes, serve the React index.html
50
+ return FileResponse("/app/static/index.html")
run_local.sh CHANGED
@@ -12,6 +12,7 @@ docker build -t simplify .
12
  # Run the container
13
  echo "Starting container..."
14
  docker run -d \
 
15
  --name simplify \
16
  -p 80:80 \
17
  -p 8000:8000 \
 
12
  # Run the container
13
  echo "Starting container..."
14
  docker run -d \
15
+ --env-file .env \
16
  --name simplify \
17
  -p 80:80 \
18
  -p 8000:8000 \
start.sh DELETED
@@ -1,12 +0,0 @@
1
- #!/bin/bash
2
-
3
- # Load environment variables from .env
4
- set -a
5
- source .env
6
- set +a
7
-
8
- # Start nginx
9
- nginx
10
-
11
- # Start the FastAPI application
12
- uvicorn backend.app.main:app --host 0.0.0.0 --port 8000