Rsr2425 commited on
Commit
50f8987
·
1 Parent(s): 58973c7

Set up FE testing

Browse files
Dockerfile CHANGED
@@ -2,25 +2,18 @@
2
  FROM node:20-slim AS frontend-builder
3
 
4
  WORKDIR /app/frontend
5
-
6
- # Copy package files first for better caching
7
  COPY frontend/package*.json ./
8
- RUN npm cache clean --force && \
9
- npm install --legacy-peer-deps --force
10
-
11
- # Copy only the necessary frontend files
12
- COPY frontend/public ./public
13
- COPY frontend/src ./src
14
- COPY frontend/tsconfig.json .
15
- COPY frontend/jest.config.js .
16
- COPY frontend/.env .
17
 
18
- # Show more verbose output during build
19
- RUN npm run build --verbose
20
 
21
- # Use Python image with uv pre-installed
22
  FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim
23
 
 
 
 
24
  WORKDIR /app
25
 
26
  # Copy backend code
@@ -31,14 +24,15 @@ COPY pyproject.toml .
31
  RUN uv sync && uv pip install .
32
  ENV PATH="/root/.local/bin:/root/.uv/venv/bin:${PATH}"
33
 
34
- # Copy frontend build
35
- COPY --from=frontend-builder /app/frontend/build /app/frontend/build
 
36
 
37
- # Add uv's bin directory to PATH
38
- ENV PATH="/app/.venv/bin:/root/.local/bin:/root/.uv/venv/bin:${PATH}"
39
 
40
- # Expose port
41
- EXPOSE 8000
 
42
 
43
- # Run the application
44
- CMD ["uvicorn", "backend.app.main:app", "--host", "0.0.0.0", "--port", "8000"]
 
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 --production
 
 
 
 
 
 
 
 
7
 
8
+ COPY frontend/ ./
9
+ RUN npm run build
10
 
11
+ # Use Python image with uv pre-installed and nginx
12
  FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim
13
 
14
+ # Install nginx
15
+ RUN apt-get update && apt-get install -y nginx
16
+
17
  WORKDIR /app
18
 
19
  # Copy backend code
 
24
  RUN uv sync && uv pip install .
25
  ENV PATH="/root/.local/bin:/root/.uv/venv/bin:${PATH}"
26
 
27
+ # Copy frontend build and nginx config
28
+ COPY --from=frontend-builder /app/frontend/build /usr/share/nginx/html
29
+ COPY frontend/nginx.conf /etc/nginx/conf.d/default.conf
30
 
31
+ # Expose ports
32
+ EXPOSE 80 8000
33
 
34
+ # Create startup script
35
+ COPY start.sh /start.sh
36
+ RUN chmod +x /start.sh
37
 
38
+ CMD ["/start.sh"]
 
Dockerfile.test ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
12
+
13
+ # Set up Node.js and npm
14
+ RUN apt-get update && apt-get install -y \
15
+ curl \
16
+ && curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
17
+ && apt-get install -y nodejs
18
+
19
+ WORKDIR /app
20
+
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}"
frontend/nginx.conf ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ server {
2
+ listen 80;
3
+ server_name localhost;
4
+
5
+ location / {
6
+ root /usr/share/nginx/html;
7
+ try_files $uri $uri/ /index.html;
8
+ }
9
+
10
+ location /api/ {
11
+ proxy_pass http://localhost:8000/;
12
+ proxy_set_header Host $host;
13
+ proxy_set_header X-Real-IP $remote_addr;
14
+ }
15
+ }
frontend/src/components/DocumentInput.tsx CHANGED
@@ -6,7 +6,7 @@ function DocumentInput() {
6
 
7
  const handleSubmit = async () => {
8
  try {
9
- const response = await fetch('http://localhost:8000/crawl/', {
10
  method: 'POST',
11
  headers: {
12
  'Content-Type': 'application/json',
 
6
 
7
  const handleSubmit = async () => {
8
  try {
9
+ const response = await fetch('/api/crawl/', {
10
  method: 'POST',
11
  headers: {
12
  'Content-Type': 'application/json',
frontend/src/components/QuizGenerator.tsx CHANGED
@@ -10,7 +10,7 @@ function QuizGenerator({ onProblemsGenerated }: QuizGeneratorProps) {
10
 
11
  const handleGenerate = async () => {
12
  try {
13
- const response = await fetch('http://localhost:8000/problems/', {
14
  method: 'POST',
15
  headers: {
16
  'Content-Type': 'application/json',
 
10
 
11
  const handleGenerate = async () => {
12
  try {
13
+ const response = await fetch('/api/problems/', {
14
  method: 'POST',
15
  headers: {
16
  'Content-Type': 'application/json',
run_local.sh ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ # Stop and remove any existing container with the same name
4
+ echo "Stopping any existing simplify container..."
5
+ docker stop simplify 2>/dev/null || true
6
+ docker rm simplify 2>/dev/null || true
7
+
8
+ # Build the Docker image
9
+ echo "Building Docker image..."
10
+ docker build -t simplify .
11
+
12
+ # Run the container
13
+ echo "Starting container..."
14
+ docker run -d \
15
+ --name simplify \
16
+ -p 80:80 \
17
+ -p 8000:8000 \
18
+ simplify
19
+
20
+ echo "Services started!"
21
+ echo "Frontend available at: http://localhost"
22
+ echo "Backend available at: http://localhost:8000"
23
+ echo ""
24
+ echo "To view logs: docker logs -f simplify"
25
+ echo "To stop: docker stop simplify"
start.sh ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ # Start nginx
3
+ nginx
4
+
5
+ # Start the FastAPI application
6
+ uvicorn backend.app.main:app --host 0.0.0.0 --port 8000
stop_local.sh ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ echo "Stopping simplify container..."
4
+ docker stop simplify 2>/dev/null || true
5
+
6
+ echo "Removing simplify container..."
7
+ docker rm simplify 2>/dev/null || true
8
+
9
+ echo "Services stopped and cleaned up!"
test_local.sh ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ # Colors and formatting
4
+ BLUE='\033[0;34m'
5
+ GREEN='\033[0;32m'
6
+ YELLOW='\033[1;33m'
7
+ NC='\033[0m' # No Color
8
+ BOLD='\033[1m'
9
+ DIVIDER="=================================================================="
10
+
11
+ echo -e "\n${BLUE}${DIVIDER}"
12
+ echo -e "${BOLD}🔨 BUILD PHASE"
13
+ echo -e "${BLUE}${DIVIDER}${NC}"
14
+
15
+ # Build test image
16
+ echo -e "${YELLOW}Building test image...${NC}"
17
+ docker build -t simplify-test -f Dockerfile.test .
18
+
19
+ echo -e "\n${BLUE}${DIVIDER}"
20
+ echo -e "${BOLD}🧪 FRONTEND TESTS"
21
+ echo -e "${BLUE}${DIVIDER}${NC}"
22
+
23
+ # Run frontend tests
24
+ echo -e "${YELLOW}Running frontend tests...${NC}"
25
+ docker run simplify-test npm test --prefix frontend
26
+
27
+ echo -e "\n${BLUE}${DIVIDER}"
28
+ echo -e "${BOLD}🐍 BACKEND TESTS"
29
+ echo -e "${BLUE}${DIVIDER}${NC}"
30
+
31
+ # Run backend tests
32
+ echo -e "${YELLOW}Running backend tests...${NC}"
33
+ docker run simplify-test pytest backend/tests
34
+
35
+ echo -e "\n${GREEN}✨ Testing complete!${NC}\n"