exposing fastapi
Browse files- Dockerfile +8 -1
- nginx.conf +33 -0
- start.sh +9 -0
Dockerfile
CHANGED
|
@@ -4,6 +4,7 @@ WORKDIR /app
|
|
| 4 |
|
| 5 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 6 |
build-essential \
|
|
|
|
| 7 |
&& rm -rf /var/lib/apt/lists/*
|
| 8 |
|
| 9 |
COPY requirements.txt .
|
|
@@ -11,9 +12,15 @@ RUN pip install --no-cache-dir -r requirements.txt
|
|
| 11 |
|
| 12 |
COPY . .
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
RUN useradd -m -u 1000 user
|
| 15 |
USER user
|
| 16 |
|
| 17 |
EXPOSE 7860
|
| 18 |
|
| 19 |
-
CMD ["
|
|
|
|
| 4 |
|
| 5 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 6 |
build-essential \
|
| 7 |
+
nginx \
|
| 8 |
&& rm -rf /var/lib/apt/lists/*
|
| 9 |
|
| 10 |
COPY requirements.txt .
|
|
|
|
| 12 |
|
| 13 |
COPY . .
|
| 14 |
|
| 15 |
+
RUN chmod +x start.sh
|
| 16 |
+
|
| 17 |
+
# Allow non-root nginx: writable pid/log/cache dirs
|
| 18 |
+
RUN mkdir -p /tmp/nginx && \
|
| 19 |
+
chmod -R 777 /var/log/nginx /var/lib/nginx /tmp/nginx
|
| 20 |
+
|
| 21 |
RUN useradd -m -u 1000 user
|
| 22 |
USER user
|
| 23 |
|
| 24 |
EXPOSE 7860
|
| 25 |
|
| 26 |
+
CMD ["./start.sh"]
|
nginx.conf
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pid /tmp/nginx/nginx.pid;
|
| 2 |
+
|
| 3 |
+
events {
|
| 4 |
+
worker_connections 1024;
|
| 5 |
+
}
|
| 6 |
+
|
| 7 |
+
http {
|
| 8 |
+
client_body_temp_path /tmp/nginx/client_body;
|
| 9 |
+
proxy_temp_path /tmp/nginx/proxy;
|
| 10 |
+
fastcgi_temp_path /tmp/nginx/fastcgi;
|
| 11 |
+
uwsgi_temp_path /tmp/nginx/uwsgi;
|
| 12 |
+
scgi_temp_path /tmp/nginx/scgi;
|
| 13 |
+
server {
|
| 14 |
+
listen 7860;
|
| 15 |
+
|
| 16 |
+
# Route /api/* to FastAPI (strip /api prefix)
|
| 17 |
+
location /api/ {
|
| 18 |
+
proxy_pass http://127.0.0.1:8000/;
|
| 19 |
+
proxy_set_header Host $host;
|
| 20 |
+
proxy_set_header X-Real-IP $remote_addr;
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
# Everything else goes to Streamlit
|
| 24 |
+
location / {
|
| 25 |
+
proxy_pass http://127.0.0.1:8501;
|
| 26 |
+
proxy_set_header Host $host;
|
| 27 |
+
proxy_set_header X-Real-IP $remote_addr;
|
| 28 |
+
proxy_http_version 1.1;
|
| 29 |
+
proxy_set_header Upgrade $http_upgrade;
|
| 30 |
+
proxy_set_header Connection "upgrade";
|
| 31 |
+
}
|
| 32 |
+
}
|
| 33 |
+
}
|
start.sh
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# Start FastAPI
|
| 3 |
+
uvicorn main:app --host 0.0.0.0 --port 8000 &
|
| 4 |
+
|
| 5 |
+
# Start Streamlit
|
| 6 |
+
streamlit run app.py --server.port 8501 --server.address 0.0.0.0 --server.headless true &
|
| 7 |
+
|
| 8 |
+
# Start nginx in foreground
|
| 9 |
+
nginx -g "daemon off;" -c /app/nginx.conf
|