fmegahed commited on
Commit
f566273
·
verified ·
1 Parent(s): 01b7f8a

Update DockerFile to Avoid Having a Second Port

Browse files
Files changed (1) hide show
  1. Dockerfile +44 -67
Dockerfile CHANGED
@@ -1,67 +1,44 @@
1
- FROM python:3.12.11-slim
2
-
3
- # Set environment variables for Python
4
- ENV PYTHONUNBUFFERED=1
5
- ENV PYTHONDONTWRITEBYTECODE=1
6
-
7
- # Create app directory and switch to it
8
- WORKDIR /app
9
-
10
- # Install system dependencies required for your packages
11
- RUN apt-get update && \
12
- apt-get install -y \
13
- build-essential \
14
- curl \
15
- git \
16
- libgomp1 \
17
- supervisor \
18
- && rm -rf /var/lib/apt/lists/*
19
-
20
- # Copy requirements first for better Docker layer caching
21
- COPY requirements.txt .
22
-
23
- # Install Python dependencies
24
- RUN pip install --no-cache-dir --upgrade pip && \
25
- pip install --no-cache-dir -r requirements.txt
26
-
27
- # Copy the entire application
28
- COPY . .
29
-
30
- # Create necessary directories if they don't exist
31
- RUN mkdir -p /app/data /app/embeddings /app/graph /app/metadata /var/log/supervisor
32
-
33
- # Create supervisor configuration
34
- COPY <<EOF /etc/supervisor/conf.d/supervisord.conf
35
- [supervisord]
36
- nodaemon=true
37
- logfile=/var/log/supervisor/supervisord.log
38
- pidfile=/var/run/supervisord.pid
39
-
40
- [program:realtime_server]
41
- command=python realtime_server.py --port=7861 --host=0.0.0.0
42
- directory=/app
43
- autostart=true
44
- autorestart=true
45
- stderr_logfile=/var/log/supervisor/realtime_server.err.log
46
- stdout_logfile=/var/log/supervisor/realtime_server.out.log
47
- priority=100
48
-
49
- [program:streamlit]
50
- command=streamlit run app.py --server.port=7860 --server.address=0.0.0.0 --server.enableXsrfProtection=false --server.enableCORS=false
51
- directory=/app
52
- autostart=true
53
- autorestart=true
54
- stderr_logfile=/var/log/supervisor/streamlit.err.log
55
- stdout_logfile=/var/log/supervisor/streamlit.out.log
56
- priority=200
57
- EOF
58
-
59
- # Expose both ports (Streamlit on 7860, Realtime API on 7861)
60
- EXPOSE 7860 7861
61
-
62
- # Health check for both services
63
- HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
64
- CMD curl --fail http://localhost:7860/_stcore/health && curl --fail http://localhost:7861/health || exit 1
65
-
66
- # Use supervisor to run both services
67
- CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
 
1
+ FROM python:3.12.11-slim
2
+
3
+ ENV PYTHONUNBUFFERED=1 \
4
+ PYTHONDONTWRITEBYTECODE=1 \
5
+ PIP_NO_CACHE_DIR=1 \
6
+ DEBIAN_FRONTEND=noninteractive
7
+
8
+ WORKDIR /app
9
+
10
+ # System deps
11
+ RUN apt-get update && apt-get install -y --no-install-recommends \
12
+ build-essential curl git libgomp1 supervisor nginx \
13
+ && rm -rf /var/lib/apt/lists/*
14
+
15
+ # Requirements first (better caching)
16
+ COPY requirements.txt .
17
+ RUN python -m pip install --upgrade pip \
18
+ && pip install -r requirements.txt
19
+
20
+ # App source
21
+ COPY . .
22
+
23
+ # Nginx + Supervisor configs
24
+ COPY nginx.conf /etc/nginx/nginx.conf
25
+ COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
26
+
27
+ # Needed dirs
28
+ RUN mkdir -p /app/data /app/embeddings /app/graph /app/metadata \
29
+ /var/log/supervisor /run
30
+
31
+ # (Optional) Drop root
32
+ RUN useradd -m -u 1000 appuser \
33
+ && chown -R appuser:appuser /app /var/log/supervisor /run
34
+ USER appuser
35
+
36
+ # HF Spaces proxies this port
37
+ EXPOSE 7860
38
+
39
+ # Healthcheck hits Streamlit through Nginx (public path) and API via path
40
+ HEALTHCHECK --interval=30s --timeout=10s --start-period=90s --retries=3 \
41
+ CMD curl -fsS http://localhost:7860/_stcore/health >/dev/null \
42
+ && curl -fsS http://localhost:7860/api/health >/dev/null || exit 1
43
+
44
+ CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]