AishwaryaNJ commited on
Commit
178b896
·
1 Parent(s): 1e11bce

Add Docker, Nginx, and Supervisor configuration for application deployment

Browse files
Files changed (3) hide show
  1. Dockerfile +14 -3
  2. nginx.conf +35 -0
  3. supervisord.conf +27 -0
Dockerfile CHANGED
@@ -4,11 +4,19 @@ ENV PYTHONDONTWRITEBYTECODE=1 \
4
  PYTHONUNBUFFERED=1 \
5
  PIP_NO_CACHE_DIR=1
6
 
 
 
 
 
 
 
7
  WORKDIR /app
8
 
 
9
  COPY requirements.txt .
10
  RUN pip install --upgrade pip && pip install -r requirements.txt
11
 
 
12
  COPY app ./app
13
  COPY scripts ./scripts
14
  COPY data ./data
@@ -16,8 +24,11 @@ COPY models ./models
16
  COPY .env.example ./.env.example
17
  COPY README.md ./README.md
18
 
19
- EXPOSE 8000
 
 
20
 
21
- HEALTHCHECK --interval=30s --timeout=5s --start-period=20s --retries=3 CMD python -c "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8000/health')"
 
22
 
23
- CMD ["uvicorn", "app.api:app", "--host", "0.0.0.0", "--port", "8000"]
 
4
  PYTHONUNBUFFERED=1 \
5
  PIP_NO_CACHE_DIR=1
6
 
7
+ # Install system dependencies
8
+ RUN apt-get update && apt-get install -y \
9
+ supervisor \
10
+ nginx \
11
+ && rm -rf /var/lib/apt/lists/*
12
+
13
  WORKDIR /app
14
 
15
+ # Install Python dependencies
16
  COPY requirements.txt .
17
  RUN pip install --upgrade pip && pip install -r requirements.txt
18
 
19
+ # Copy project files
20
  COPY app ./app
21
  COPY scripts ./scripts
22
  COPY data ./data
 
24
  COPY .env.example ./.env.example
25
  COPY README.md ./README.md
26
 
27
+ # Copy config files
28
+ COPY nginx.conf /etc/nginx/nginx.conf
29
+ COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
30
 
31
+ # HF Spaces requires port 7860
32
+ EXPOSE 7860
33
 
34
+ CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
nginx.conf ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ worker_processes 1;
2
+ error_log /var/log/nginx/error.log warn;
3
+ pid /var/run/nginx.pid;
4
+
5
+ events {
6
+ worker_connections 1024;
7
+ }
8
+
9
+ http {
10
+ include /etc/nginx/mime.types;
11
+ default_type application/octet-stream;
12
+ sendfile on;
13
+ keepalive_timeout 65;
14
+
15
+ server {
16
+ listen 7860;
17
+
18
+ location /api/ {
19
+ proxy_pass http://127.0.0.1:8000/;
20
+ proxy_set_header Host $host;
21
+ proxy_set_header X-Real-IP $remote_addr;
22
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
23
+ proxy_set_header X-Forwarded-Proto $scheme;
24
+ }
25
+
26
+ location / {
27
+ proxy_pass http://127.0.0.1:8501;
28
+ proxy_set_header Host $host;
29
+ proxy_set_header X-Real-IP $remote_addr;
30
+ proxy_http_version 1.1;
31
+ proxy_set_header Upgrade $http_upgrade;
32
+ proxy_set_header Connection "upgrade";
33
+ }
34
+ }
35
+ }
supervisord.conf ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [supervisord]
2
+ nodaemon=true
3
+ logfile=/var/log/supervisor/supervisord.log
4
+ pidfile=/var/run/supervisord.pid
5
+
6
+ [program:fastapi]
7
+ command=uvicorn app.api:app --host 127.0.0.1 --port 8000
8
+ directory=/app
9
+ autostart=true
10
+ autorestart=true
11
+ stderr_logfile=/var/log/supervisor/fastapi.err.log
12
+ stdout_logfile=/var/log/supervisor/fastapi.out.log
13
+
14
+ [program:streamlit]
15
+ command=streamlit run app/dashboard.py --server.address=127.0.0.1 --server.port=8501 --server.headless=true
16
+ directory=/app
17
+ autostart=true
18
+ autorestart=true
19
+ stderr_logfile=/var/log/supervisor/streamlit.err.log
20
+ stdout_logfile=/var/log/supervisor/streamlit.out.log
21
+
22
+ [program:nginx]
23
+ command=nginx -g "daemon off;"
24
+ autostart=true
25
+ autorestart=true
26
+ stderr_logfile=/var/log/supervisor/nginx.err.log
27
+ stdout_logfile=/var/log/supervisor/nginx.out.log