gauthamnairy commited on
Commit
e1221d9
·
verified ·
1 Parent(s): 9d0b0fb

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +44 -30
Dockerfile CHANGED
@@ -2,6 +2,9 @@ FROM python:3.9-slim
2
 
3
  WORKDIR /code
4
 
 
 
 
5
  # Copy the entire project first
6
  COPY . /code
7
 
@@ -12,51 +15,62 @@ RUN if [ -f "requirements.txt" ]; then \
12
  pip install --no-cache-dir --upgrade -r backend/requirements.txt; \
13
  else \
14
  echo "No requirements.txt found. Installing minimal dependencies."; \
15
- pip install fastapi uvicorn httpx; \
16
  fi
17
 
18
  # Need to make sure we listen on port 7860 (Hugging Face Spaces requirement)
19
  ENV PORT=7860
20
 
21
- # Create a simple script to run the app
22
- RUN echo '#!/bin/bash\n\
23
- # Check where the files are located\n\
24
- echo "Content of root directory:"\n\
25
- ls -la /code\n\
26
  \n\
27
- # Check if frontend directory exists\n\
28
- if [ -d "/code/frontend" ]; then\n\
29
- echo "Frontend directory found:"\n\
30
- ls -la /code/frontend\n\
31
- fi\n\
32
  \n\
33
- # Check if backend directory exists\n\
34
- if [ -d "/code/backend" ]; then\n\
35
- echo "Backend directory found:"\n\
36
- ls -la /code/backend\n\
37
- fi\n\
38
  \n\
39
- # Run the app\n\
40
- echo "Starting application..."\n\
41
- cd /code\n\
42
  \n\
43
- # If main.py is in the backend directory\n\
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  if [ -f "backend/main.py" ]; then\n\
45
- python -m uvicorn backend.main:app --host 0.0.0.0 --port $PORT\n\
46
- # If app.py is in the root directory\n\
47
- elif [ -f "app.py" ]; then\n\
48
- python app.py\n\
49
- # If main.py is in the root directory\n\
50
- elif [ -f "main.py" ]; then\n\
51
- python -m uvicorn main:app --host 0.0.0.0 --port $PORT\n\
52
  else\n\
53
- echo "Could not find main.py or app.py. Please check your file structure."\n\
54
- exit 1\n\
55
  fi\n\
 
 
56
  ' > /code/start.sh && chmod +x /code/start.sh
57
 
58
  # Expose port 7860 (required for Hugging Face Spaces)
59
  EXPOSE 7860
60
 
61
- # Run the application
62
  CMD ["/code/start.sh"]
 
2
 
3
  WORKDIR /code
4
 
5
+ # Install nginx
6
+ RUN apt-get update && apt-get install -y nginx && rm -rf /var/lib/apt/lists/*
7
+
8
  # Copy the entire project first
9
  COPY . /code
10
 
 
15
  pip install --no-cache-dir --upgrade -r backend/requirements.txt; \
16
  else \
17
  echo "No requirements.txt found. Installing minimal dependencies."; \
18
+ pip install fastapi uvicorn httpx pyproj python-multipart; \
19
  fi
20
 
21
  # Need to make sure we listen on port 7860 (Hugging Face Spaces requirement)
22
  ENV PORT=7860
23
 
24
+ # Create nginx configuration
25
+ RUN echo 'server {\n\
26
+ listen 7860;\n\
27
+ server_name localhost;\n\
 
28
  \n\
29
+ location / {\n\
30
+ root /code/frontend;\n\
31
+ index index.html;\n\
32
+ try_files $uri $uri/ =404;\n\
33
+ }\n\
34
  \n\
35
+ location /frontend/ {\n\
36
+ alias /code/frontend/;\n\
37
+ }\n\
 
 
38
  \n\
39
+ location /static/ {\n\
40
+ alias /code/frontend/static/;\n\
41
+ }\n\
42
  \n\
43
+ location /api/ {\n\
44
+ proxy_pass http://localhost:8000/api/;\n\
45
+ proxy_set_header Host $host;\n\
46
+ proxy_set_header X-Real-IP $remote_addr;\n\
47
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n\
48
+ proxy_set_header X-Forwarded-Proto $scheme;\n\
49
+ }\n\
50
+ }' > /etc/nginx/conf.d/default.conf
51
+
52
+ # Make sure the nginx config is valid
53
+ RUN nginx -t
54
+
55
+ # Create a script to run both the API and Nginx
56
+ RUN echo '#!/bin/bash\n\
57
+ echo "Directory structure:"\n\
58
+ find /code -type d | sort\n\
59
+ echo "\nHTML files:"\n\
60
+ find /code -name "*.html" | sort\n\
61
+ echo "\nStarting API server..."\n\
62
+ cd /code\n\
63
  if [ -f "backend/main.py" ]; then\n\
64
+ python -m uvicorn backend.main:app --host 0.0.0.0 --port 8000 &\n\
 
 
 
 
 
 
65
  else\n\
66
+ python -m uvicorn main:app --host 0.0.0.0 --port 8000 &\n\
 
67
  fi\n\
68
+ echo "Starting Nginx..."\n\
69
+ nginx -g "daemon off;"\n\
70
  ' > /code/start.sh && chmod +x /code/start.sh
71
 
72
  # Expose port 7860 (required for Hugging Face Spaces)
73
  EXPOSE 7860
74
 
75
+ # Run the combined services
76
  CMD ["/code/start.sh"]