Saad-gengini commited on
Commit
fe72343
·
1 Parent(s): 7ab3094

new endpoint

Browse files
Files changed (4) hide show
  1. Dockerfile +19 -11
  2. README.md +1 -0
  3. nginx.conf +41 -0
  4. start.sh +11 -0
Dockerfile CHANGED
@@ -1,16 +1,24 @@
1
- # Read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
2
- # you will also find guides on how best to write your Dockerfile
3
 
4
- FROM python:3.9
5
-
6
- RUN useradd -m -u 1000 user
7
- USER user
8
- ENV PATH="/home/user/.local/bin:$PATH"
9
 
10
  WORKDIR /app
11
 
12
- COPY --chown=user ./requirements.txt requirements.txt
13
- RUN pip install --no-cache-dir --upgrade -r requirements.txt
 
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
- COPY --chown=user . /app
16
- CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
 
1
+ FROM python:3.11-slim
 
2
 
3
+ # Install nginx
4
+ RUN apt-get update && apt-get install -y nginx && rm -rf /var/lib/apt/lists/*
 
 
 
5
 
6
  WORKDIR /app
7
 
8
+ # Python deps
9
+ COPY requirements.txt .
10
+ RUN pip install --no-cache-dir -r requirements.txt
11
+
12
+ # App + nginx config
13
+ COPY app.py .
14
+ COPY nginx.conf /etc/nginx/nginx.conf
15
+ COPY start.sh /start.sh
16
+ RUN chmod +x /start.sh
17
+
18
+ # Hugging Face sets PORT=app_port; here it's 7860 so we're fine
19
+ ENV PORT=7860
20
+
21
+ # Expose for local testing (not strictly needed for Spaces)
22
+ EXPOSE 7860
23
 
24
+ CMD ["/start.sh"]
 
README.md CHANGED
@@ -5,6 +5,7 @@ colorFrom: yellow
5
  colorTo: indigo
6
  sdk: docker
7
  pinned: false
 
8
  ---
9
 
10
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
5
  colorTo: indigo
6
  sdk: docker
7
  pinned: false
8
+ app_port: 7860
9
  ---
10
 
11
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
nginx.conf ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # /etc/nginx/nginx.conf
2
+ events {}
3
+
4
+ http {
5
+ # Upstream for FastAPI
6
+ upstream fastapi_backend {
7
+ server 127.0.0.1:8000;
8
+ }
9
+
10
+ # (Optional) upstream for something on 9200, e.g. Elasticsearch
11
+ upstream es_backend {
12
+ server 127.0.0.1:9200;
13
+ }
14
+
15
+ server {
16
+ # Must match your app_port (7860)
17
+ listen 7860;
18
+
19
+ # FastAPI exposed as /api/...
20
+ location /api/ {
21
+ proxy_pass http://fastapi_backend/;
22
+ proxy_set_header Host $host;
23
+ proxy_set_header X-Real-IP $remote_addr;
24
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
25
+ }
26
+
27
+ # Optional: proxy /es/ to port 9200
28
+ location /es/ {
29
+ proxy_pass http://es_backend/;
30
+ proxy_set_header Host $host;
31
+ proxy_set_header X-Real-IP $remote_addr;
32
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
33
+ }
34
+
35
+ # Optional: serve a static frontend or simple index
36
+ location / {
37
+ return 200 "Nginx is up. Try /api/hello\n";
38
+ add_header Content-Type text/plain;
39
+ }
40
+ }
41
+ }
start.sh ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ set -e
3
+
4
+ # Start FastAPI (internal only)
5
+ uvicorn app:app --host 0.0.0.0 --port 8000 &
6
+
7
+ # TODO: start other internal services here if you want
8
+ # e.g. elasticsearch, another API, etc.
9
+
10
+ # Start nginx in foreground so Docker container stays alive
11
+ nginx -g "daemon off;"