sreepathi-ravikumar commited on
Commit
be4a4fa
·
verified ·
1 Parent(s): 2ef3598

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +19 -17
Dockerfile CHANGED
@@ -1,54 +1,56 @@
1
- # Stage 1: Builder for dependencies
2
  FROM python:3.9-slim as builder
3
 
4
  WORKDIR /app
5
 
6
- # Install build dependencies
7
  RUN apt-get update && \
8
  apt-get install -y --no-install-recommends \
9
  gcc \
10
  python3-dev \
11
  && rm -rf /var/lib/apt/lists/*
12
 
13
- # Copy and install requirements
 
 
 
 
14
  COPY requirements.txt .
15
- RUN pip install --user --no-cache-dir -r requirements.txt
16
 
17
- # Stage 2: Runtime image
18
  FROM python:3.9-slim
19
 
20
  WORKDIR /app
21
 
22
- # Install runtime dependencies
23
  RUN apt-get update && \
24
  apt-get install -y --no-install-recommends \
25
  ffmpeg \
26
  && rm -rf /var/lib/apt/lists/*
27
 
28
- # Copy Python dependencies from builder
29
- COPY --from=builder /root/.local /root/.local
30
- COPY --from=builder /app/requirements.txt .
31
 
32
- # Copy application files
33
  COPY app.py audio_generator.py ./
34
 
35
- # Create and configure output directory
36
  RUN mkdir -p /app/tts_outputs && \
37
  chmod 777 /app/tts_outputs
38
 
39
- # Environment configuration
40
- ENV PATH=/root/.local/bin:$PATH \
41
- PYTHONUNBUFFERED=1 \
42
- PYTHONPATH=/app \
43
  PORT=7860
44
 
45
- # Healthcheck
46
  HEALTHCHECK --interval=30s --timeout=10s \
47
  CMD curl -f http://localhost:${PORT}/health || exit 1
48
 
49
  EXPOSE ${PORT}
50
 
51
- # Run as non-root user
52
  RUN useradd -m ttsuser && \
53
  chown -R ttsuser /app
54
  USER ttsuser
 
1
+ # Stage 1: Install all dependencies
2
  FROM python:3.9-slim as builder
3
 
4
  WORKDIR /app
5
 
6
+ # 1. Install system dependencies
7
  RUN apt-get update && \
8
  apt-get install -y --no-install-recommends \
9
  gcc \
10
  python3-dev \
11
  && rm -rf /var/lib/apt/lists/*
12
 
13
+ # 2. Create and activate virtual environment
14
+ RUN python -m venv /opt/venv
15
+ ENV PATH="/opt/venv/bin:$PATH"
16
+
17
+ # 3. Install Python packages
18
  COPY requirements.txt .
19
+ RUN pip install --no-cache-dir -r requirements.txt
20
 
21
+ # Stage 2: Create lightweight runtime image
22
  FROM python:3.9-slim
23
 
24
  WORKDIR /app
25
 
26
+ # 1. Install runtime dependencies
27
  RUN apt-get update && \
28
  apt-get install -y --no-install-recommends \
29
  ffmpeg \
30
  && rm -rf /var/lib/apt/lists/*
31
 
32
+ # 2. Copy virtual environment from builder
33
+ COPY --from=builder /opt/venv /opt/venv
34
+ ENV PATH="/opt/venv/bin:$PATH"
35
 
36
+ # 3. Copy application files
37
  COPY app.py audio_generator.py ./
38
 
39
+ # 4. Create output directory
40
  RUN mkdir -p /app/tts_outputs && \
41
  chmod 777 /app/tts_outputs
42
 
43
+ # 5. Environment configuration
44
+ ENV PYTHONUNBUFFERED=1 \
 
 
45
  PORT=7860
46
 
47
+ # 6. Healthcheck
48
  HEALTHCHECK --interval=30s --timeout=10s \
49
  CMD curl -f http://localhost:${PORT}/health || exit 1
50
 
51
  EXPOSE ${PORT}
52
 
53
+ # 7. Run as non-root user
54
  RUN useradd -m ttsuser && \
55
  chown -R ttsuser /app
56
  USER ttsuser