shaliz-kong commited on
Commit
12d2187
·
1 Parent(s): 3493c8b

refactored dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +33 -14
Dockerfile CHANGED
@@ -1,24 +1,43 @@
1
- # ---- 1. base image ---------------------------------------------------------
2
  FROM python:3.11-slim
3
 
4
- # ---- 2. system dependencies -----------------------------------------------
5
- RUN apt-get update && apt-get install -y --no-install-recommends \
6
- redis-server \
7
- supervisor \
8
- unzip \
9
- && rm -rf /var/lib/apt/lists/*
10
 
11
- # ---- 3. Python deps -------------------------------------------------------
12
  COPY requirements.txt /tmp/
13
  RUN pip install --no-cache-dir -r /tmp/requirements.txt
14
 
15
- # ---- 4. Copy app -----------------------------------------------------------
16
  COPY . /app
17
  WORKDIR /app
18
 
19
- # ---- 5. Create supervisord config with proper newlines --------------------
20
- RUN mkdir -p /etc/supervisor/conf.d /var/log/supervisor && \
21
- printf '[supervisord]\nnodaemon=true\n\n[program:redis]\ncommand=redis-server --bind 127.0.0.1 --port 6379 --maxmemory 128mb\nautostart=true\nautorestart=true\n\n[program:app]\ncommand=python -m uvicorn app.main:app --host 0.0.0.0 --port 7860\ndirectory=/app\nenvironment=REDIS_URL=redis://localhost:6379\nautostart=true\nautorestart=true\n\n[program:scheduler]\ncommand=python /app/scheduler_loop.py\ndirectory=/app\nenvironment=REDIS_URL=redis://localhost:6379\nautostart=true\nautorestart=true\n' > /etc/supervisor/conf.d/supervisord.conf
 
22
 
23
- # ---- 6. Start ----------------------------------------------------------------
24
- CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  FROM python:3.11-slim
2
 
3
+ # Install Redis and Supervisor
4
+ RUN apt-get update && apt-get install -y redis-server supervisor && rm -rf /var/lib/apt/lists/*
 
 
 
 
5
 
6
+ # Install Python dependencies
7
  COPY requirements.txt /tmp/
8
  RUN pip install --no-cache-dir -r /tmp/requirements.txt
9
 
10
+ # Copy application
11
  COPY . /app
12
  WORKDIR /app
13
 
14
+ # Create supervisord config using heredoc (works on HF builder)
15
+ RUN cat > /etc/supervisord.conf << 'EOF'
16
+ [supervisord]
17
+ nodaemon=true
18
 
19
+ [program:redis]
20
+ command=redis-server --bind 127.0.0.1 --port 6379 --maxmemory 128mb
21
+ autostart=true
22
+ autorestart=true
23
+
24
+ [program:app]
25
+ command=python -m uvicorn app.main:app --host 0.0.0.0 --port 7860
26
+ directory=/app
27
+ environment=REDIS_URL=redis://localhost:6379
28
+ autostart=true
29
+ autorestart=true
30
+
31
+ [program:scheduler]
32
+ command=python /app/scheduler_loop.py
33
+ directory=/app
34
+ environment=REDIS_URL=redis://localhost:6379
35
+ autostart=true
36
+ autorestart=true
37
+ EOF
38
+
39
+ # Expose port
40
+ EXPOSE 7860
41
+
42
+ # Start supervisord
43
+ CMD ["/usr/bin/supervisord", "-c", "/etc/supervisord.conf"]