Spaces:
Build error
Build error
Update Dockerfile
Browse files- Dockerfile +77 -20
Dockerfile
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
FROM python:3.9-slim
|
| 2 |
|
| 3 |
-
WORKDIR /
|
| 4 |
|
| 5 |
# Install nginx
|
| 6 |
RUN apt-get update && apt-get install -y nginx && rm -rf /var/lib/apt/lists/*
|
|
@@ -14,7 +14,10 @@ RUN mkdir -p /tmp/nginx/client_body \
|
|
| 14 |
&& chmod -R 777 /tmp/nginx
|
| 15 |
|
| 16 |
# Copy the entire project first
|
| 17 |
-
COPY . /
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
# Install dependencies - try both possible locations for requirements.txt
|
| 20 |
RUN if [ -f "requirements.txt" ]; then \
|
|
@@ -29,7 +32,7 @@ RUN if [ -f "requirements.txt" ]; then \
|
|
| 29 |
# Need to make sure we listen on port 7860 (Hugging Face Spaces requirement)
|
| 30 |
ENV PORT=7860
|
| 31 |
|
| 32 |
-
# Create a complete nginx configuration
|
| 33 |
RUN echo 'worker_processes auto;\n\
|
| 34 |
pid /tmp/nginx.pid;\n\
|
| 35 |
\n\
|
|
@@ -43,7 +46,7 @@ http {\n\
|
|
| 43 |
\n\
|
| 44 |
# Redirect logs to stdout/stderr\n\
|
| 45 |
access_log /dev/stdout;\n\
|
| 46 |
-
error_log /dev/stderr;\n\
|
| 47 |
\n\
|
| 48 |
# Set up paths that do not require root access\n\
|
| 49 |
client_body_temp_path /tmp/nginx/client_body;\n\
|
|
@@ -57,25 +60,44 @@ http {\n\
|
|
| 57 |
tcp_nodelay on;\n\
|
| 58 |
keepalive_timeout 65;\n\
|
| 59 |
types_hash_max_size 2048;\n\
|
|
|
|
|
|
|
|
|
|
| 60 |
\n\
|
| 61 |
server {\n\
|
| 62 |
-
listen 7860;\n\
|
| 63 |
-
server_name
|
|
|
|
|
|
|
|
|
|
| 64 |
\n\
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
location / {\n\
|
| 66 |
-
root /
|
| 67 |
index index.html;\n\
|
| 68 |
-
try_files $uri $uri/ =404;\n\
|
| 69 |
}\n\
|
| 70 |
\n\
|
|
|
|
| 71 |
location /frontend/ {\n\
|
| 72 |
-
alias /
|
|
|
|
| 73 |
}\n\
|
| 74 |
\n\
|
|
|
|
| 75 |
location /static/ {\n\
|
| 76 |
-
alias /
|
|
|
|
|
|
|
| 77 |
}\n\
|
| 78 |
\n\
|
|
|
|
| 79 |
location /api/ {\n\
|
| 80 |
proxy_pass http://localhost:8000/api/;\n\
|
| 81 |
proxy_set_header Host $host;\n\
|
|
@@ -86,27 +108,62 @@ http {\n\
|
|
| 86 |
}\n\
|
| 87 |
}' > /etc/nginx/nginx.conf
|
| 88 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
# Create a script to run both the API and Nginx
|
| 90 |
RUN echo '#!/bin/bash\n\
|
| 91 |
-
echo "
|
| 92 |
-
find /
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
if [ -f "backend/main.py" ]; then\n\
|
| 100 |
python -m uvicorn backend.main:app --host 0.0.0.0 --port 8000 &\n\
|
| 101 |
else\n\
|
| 102 |
python -m uvicorn main:app --host 0.0.0.0 --port 8000 &\n\
|
| 103 |
fi\n\
|
|
|
|
| 104 |
echo "Starting Nginx..."\n\
|
| 105 |
nginx -g "daemon off;"\n\
|
| 106 |
-
' > /
|
| 107 |
|
| 108 |
# Expose port 7860 (required for Hugging Face Spaces)
|
| 109 |
EXPOSE 7860
|
| 110 |
|
| 111 |
# Run the combined services
|
| 112 |
-
CMD ["/
|
|
|
|
| 1 |
FROM python:3.9-slim
|
| 2 |
|
| 3 |
+
WORKDIR /app
|
| 4 |
|
| 5 |
# Install nginx
|
| 6 |
RUN apt-get update && apt-get install -y nginx && rm -rf /var/lib/apt/lists/*
|
|
|
|
| 14 |
&& chmod -R 777 /tmp/nginx
|
| 15 |
|
| 16 |
# Copy the entire project first
|
| 17 |
+
COPY . /app
|
| 18 |
+
|
| 19 |
+
# Ensure correct permissions for the frontend files
|
| 20 |
+
RUN chmod -R 755 /app/frontend
|
| 21 |
|
| 22 |
# Install dependencies - try both possible locations for requirements.txt
|
| 23 |
RUN if [ -f "requirements.txt" ]; then \
|
|
|
|
| 32 |
# Need to make sure we listen on port 7860 (Hugging Face Spaces requirement)
|
| 33 |
ENV PORT=7860
|
| 34 |
|
| 35 |
+
# Create a complete nginx configuration with better error handling
|
| 36 |
RUN echo 'worker_processes auto;\n\
|
| 37 |
pid /tmp/nginx.pid;\n\
|
| 38 |
\n\
|
|
|
|
| 46 |
\n\
|
| 47 |
# Redirect logs to stdout/stderr\n\
|
| 48 |
access_log /dev/stdout;\n\
|
| 49 |
+
error_log /dev/stderr info;\n\
|
| 50 |
\n\
|
| 51 |
# Set up paths that do not require root access\n\
|
| 52 |
client_body_temp_path /tmp/nginx/client_body;\n\
|
|
|
|
| 60 |
tcp_nodelay on;\n\
|
| 61 |
keepalive_timeout 65;\n\
|
| 62 |
types_hash_max_size 2048;\n\
|
| 63 |
+
\n\
|
| 64 |
+
# Disable directory listings\n\
|
| 65 |
+
autoindex off;\n\
|
| 66 |
\n\
|
| 67 |
server {\n\
|
| 68 |
+
listen 7860 default_server;\n\
|
| 69 |
+
server_name _;\n\
|
| 70 |
+
\n\
|
| 71 |
+
# Improved error handling\n\
|
| 72 |
+
error_page 403 404 /404.html;\n\
|
| 73 |
\n\
|
| 74 |
+
# Create a custom 404 page\n\
|
| 75 |
+
location = /404.html {\n\
|
| 76 |
+
add_header Content-Type text/html;\n\
|
| 77 |
+
return 200 "<html><head><title>GeoTools Hub - Page Not Found</title></head><body style=\"font-family: Arial, sans-serif; color: #333; text-align: center; padding: 50px;\"><h1>Page Not Found</h1><p>Sorry, the page you are looking for does not exist.</p><p><a href=\"/\">Return to Home</a></p></body></html>";\n\
|
| 78 |
+
}\n\
|
| 79 |
+
\n\
|
| 80 |
+
# Root location serving frontend\n\
|
| 81 |
location / {\n\
|
| 82 |
+
root /app/frontend;\n\
|
| 83 |
index index.html;\n\
|
| 84 |
+
try_files $uri $uri/ /index.html =404;\n\
|
| 85 |
}\n\
|
| 86 |
\n\
|
| 87 |
+
# Explicit frontend folder location\n\
|
| 88 |
location /frontend/ {\n\
|
| 89 |
+
alias /app/frontend/;\n\
|
| 90 |
+
autoindex off;\n\
|
| 91 |
}\n\
|
| 92 |
\n\
|
| 93 |
+
# Static files location\n\
|
| 94 |
location /static/ {\n\
|
| 95 |
+
alias /app/frontend/static/;\n\
|
| 96 |
+
autoindex off;\n\
|
| 97 |
+
add_header Cache-Control "public, max-age=3600";\n\
|
| 98 |
}\n\
|
| 99 |
\n\
|
| 100 |
+
# API endpoint proxying\n\
|
| 101 |
location /api/ {\n\
|
| 102 |
proxy_pass http://localhost:8000/api/;\n\
|
| 103 |
proxy_set_header Host $host;\n\
|
|
|
|
| 108 |
}\n\
|
| 109 |
}' > /etc/nginx/nginx.conf
|
| 110 |
|
| 111 |
+
# Create a debug index.html file to ensure we have something to serve
|
| 112 |
+
RUN echo '<!DOCTYPE html>\n\
|
| 113 |
+
<html lang="en">\n\
|
| 114 |
+
<head>\n\
|
| 115 |
+
<meta charset="UTF-8">\n\
|
| 116 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">\n\
|
| 117 |
+
<title>GeoTools Hub</title>\n\
|
| 118 |
+
<style>\n\
|
| 119 |
+
body { font-family: Arial, sans-serif; margin: 0; padding: 0; background-color: #f4f6f9; }\n\
|
| 120 |
+
.container { max-width: 800px; margin: 0 auto; padding: 2rem; }\n\
|
| 121 |
+
h1 { color: #3b82f6; text-align: center; }\n\
|
| 122 |
+
p { color: #333; line-height: 1.6; }\n\
|
| 123 |
+
.card { background: white; border-radius: 8px; padding: 1.5rem; margin: 1rem 0; box-shadow: 0 2px 4px rgba(0,0,0,0.1); }\n\
|
| 124 |
+
</style>\n\
|
| 125 |
+
</head>\n\
|
| 126 |
+
<body>\n\
|
| 127 |
+
<div class="container">\n\
|
| 128 |
+
<h1>GeoTools Hub</h1>\n\
|
| 129 |
+
<div class="card">\n\
|
| 130 |
+
<p>This is a fallback page created by the Docker container.</p>\n\
|
| 131 |
+
<p>If you see this page, it means the nginx server is working, but your original frontend files might not be accessible.</p>\n\
|
| 132 |
+
<p>Check the container logs for more information.</p>\n\
|
| 133 |
+
</div>\n\
|
| 134 |
+
</div>\n\
|
| 135 |
+
</body>\n\
|
| 136 |
+
</html>' > /app/frontend/index.html.fallback
|
| 137 |
+
|
| 138 |
# Create a script to run both the API and Nginx
|
| 139 |
RUN echo '#!/bin/bash\n\
|
| 140 |
+
echo "Container directory structure:"\n\
|
| 141 |
+
find /app -type f -name "*.html" | sort\n\
|
| 142 |
+
\n\
|
| 143 |
+
# Check if frontend/index.html exists, if not use fallback\n\
|
| 144 |
+
if [ ! -f "/app/frontend/index.html" ]; then\n\
|
| 145 |
+
echo "WARNING: index.html not found, using fallback page"\n\
|
| 146 |
+
cp /app/frontend/index.html.fallback /app/frontend/index.html\n\
|
| 147 |
+
fi\n\
|
| 148 |
+
\n\
|
| 149 |
+
# Check file permissions\n\
|
| 150 |
+
echo "File permissions in frontend:"\n\
|
| 151 |
+
ls -la /app/frontend\n\
|
| 152 |
+
\n\
|
| 153 |
+
echo "Starting API server..."\n\
|
| 154 |
+
cd /app\n\
|
| 155 |
if [ -f "backend/main.py" ]; then\n\
|
| 156 |
python -m uvicorn backend.main:app --host 0.0.0.0 --port 8000 &\n\
|
| 157 |
else\n\
|
| 158 |
python -m uvicorn main:app --host 0.0.0.0 --port 8000 &\n\
|
| 159 |
fi\n\
|
| 160 |
+
\n\
|
| 161 |
echo "Starting Nginx..."\n\
|
| 162 |
nginx -g "daemon off;"\n\
|
| 163 |
+
' > /app/start.sh && chmod +x /app/start.sh
|
| 164 |
|
| 165 |
# Expose port 7860 (required for Hugging Face Spaces)
|
| 166 |
EXPOSE 7860
|
| 167 |
|
| 168 |
# Run the combined services
|
| 169 |
+
CMD ["/app/start.sh"]
|