File size: 2,219 Bytes
477ca04
 
e4b6d93
477ca04
e4b6d93
477ca04
3856c4a
8f75e88
 
 
 
 
bcb7e49
 
477ca04
 
3856c4a
477ca04
 
 
aa776c7
477ca04
 
8f75e88
477ca04
aa776c7
477ca04
 
e4b6d93
 
 
 
 
aa776c7
8f75e88
 
477ca04
e4b6d93
8c5b9b8
e4b6d93
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8c5b9b8
3856c4a
477ca04
 
 
 
bcb7e49
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
FROM python:3.10-slim

# System deps — nginx added for reverse-proxying FastAPI + Streamlit
RUN apt-get update && apt-get install -y \
    nginx \
    poppler-utils \
    supervisor \
    libgl1 \
    libglib2.0-0 \
    libjpeg-dev \
    libpng-dev \
    libwebp-dev \
    tesseract-ocr \
    tesseract-ocr-eng \
    && rm -rf /var/lib/apt/lists/*

# Create non-root user
RUN useradd -m -u 1000 appuser
WORKDIR /app

# Install Python deps
COPY requirements.txt .
RUN pip install --no-cache-dir --upgrade pip && \
    pip install --no-cache-dir -r requirements.txt

# Copy app
COPY --chown=appuser:appuser . .

# nginx config — port 7860 routes /api/* → FastAPI:7861, else → Streamlit:8501
COPY nginx.conf /etc/nginx/nginx.conf
RUN mkdir -p /var/log/nginx /var/lib/nginx/body /run && \
    chown -R appuser:appuser /var/log/nginx /var/lib/nginx /run /etc/nginx

# Writable dirs
RUN mkdir -p /app/chroma_db /app/sample_docs /app/logs /tmp/chroma_db && \
    chown -R appuser:appuser /app/chroma_db /app/sample_docs /app/logs /tmp/chroma_db

# Supervisor config — runs nginx, Streamlit (8501), and FastAPI (7861)
RUN mkdir -p /app/supervisor && \
    printf '[supervisord]\n\
nodaemon=true\n\
logfile=/app/logs/supervisord.log\n\
pidfile=/app/logs/supervisord.pid\n\
\n\
[program:nginx]\n\
command=nginx -g "daemon off;"\n\
autostart=true\n\
autorestart=true\n\
stdout_logfile=/app/logs/nginx.log\n\
stderr_logfile=/app/logs/nginx_err.log\n\
\n\
[program:streamlit]\n\
command=streamlit run app.py --server.port=8501 --server.address=0.0.0.0 --server.headless=true --server.enableCORS=false --server.enableXsrfProtection=false --browser.gatherUsageStats=false\n\
directory=/app\n\
autostart=true\n\
autorestart=true\n\
stdout_logfile=/app/logs/streamlit.log\n\
stderr_logfile=/app/logs/streamlit_err.log\n\
\n\
[program:fastapi]\n\
command=uvicorn api:app --host=0.0.0.0 --port=7861\n\
directory=/app\n\
autostart=true\n\
autorestart=true\n\
stdout_logfile=/app/logs/fastapi.log\n\
stderr_logfile=/app/logs/fastapi_err.log\n\
' > /app/supervisor/supervisord.conf && \
    chown -R appuser:appuser /app/supervisor

USER appuser

EXPOSE 7860

CMD ["/usr/bin/supervisord", "-c", "/app/supervisor/supervisord.conf"]