Spaces:
Sleeping
Sleeping
Update Dockerfile
Browse files- Dockerfile +34 -10
Dockerfile
CHANGED
|
@@ -1,30 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
FROM python:3.9-slim
|
| 2 |
|
| 3 |
WORKDIR /app
|
| 4 |
|
| 5 |
-
# Install
|
| 6 |
RUN apt-get update && \
|
| 7 |
apt-get install -y --no-install-recommends \
|
| 8 |
ffmpeg \
|
| 9 |
&& rm -rf /var/lib/apt/lists/*
|
| 10 |
|
| 11 |
-
# Copy
|
| 12 |
-
COPY
|
| 13 |
-
|
| 14 |
|
| 15 |
# Application files
|
| 16 |
COPY app.py audio_generator.py ./
|
| 17 |
|
| 18 |
-
# Create output directory
|
| 19 |
-
RUN mkdir -p /app/
|
| 20 |
-
chmod 777 /app/
|
| 21 |
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
| 23 |
PORT=7860
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
HEALTHCHECK --interval=30s --timeout=10s \
|
| 28 |
CMD curl -f http://localhost:${PORT}/health || exit 1
|
| 29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
CMD ["python", "app.py"]
|
|
|
|
| 1 |
+
# Stage 1: Builder
|
| 2 |
+
FROM python:3.9-slim as builder
|
| 3 |
+
|
| 4 |
+
WORKDIR /app
|
| 5 |
+
COPY requirements.txt .
|
| 6 |
+
|
| 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 |
+
RUN pip install --user --no-cache-dir -r requirements.txt
|
| 14 |
+
|
| 15 |
+
# Stage 2: Runtime
|
| 16 |
FROM python:3.9-slim
|
| 17 |
|
| 18 |
WORKDIR /app
|
| 19 |
|
| 20 |
+
# Install runtime dependencies
|
| 21 |
RUN apt-get update && \
|
| 22 |
apt-get install -y --no-install-recommends \
|
| 23 |
ffmpeg \
|
| 24 |
&& rm -rf /var/lib/apt/lists/*
|
| 25 |
|
| 26 |
+
# Copy Python dependencies
|
| 27 |
+
COPY --from=builder /root/.local /root/.local
|
| 28 |
+
COPY --from=builder /app/requirements.txt .
|
| 29 |
|
| 30 |
# Application files
|
| 31 |
COPY app.py audio_generator.py ./
|
| 32 |
|
| 33 |
+
# Create output directory with correct permissions
|
| 34 |
+
RUN mkdir -p /app/tts_outputs && \
|
| 35 |
+
chmod 777 /app/tts_outputs
|
| 36 |
|
| 37 |
+
# Environment configuration
|
| 38 |
+
ENV PATH=/root/.local/bin:$PATH \
|
| 39 |
+
PYTHONUNBUFFERED=1 \
|
| 40 |
+
PYTHONPATH=/app \
|
| 41 |
PORT=7860
|
| 42 |
|
| 43 |
+
# Healthcheck
|
|
|
|
| 44 |
HEALTHCHECK --interval=30s --timeout=10s \
|
| 45 |
CMD curl -f http://localhost:${PORT}/health || exit 1
|
| 46 |
|
| 47 |
+
EXPOSE ${PORT}
|
| 48 |
+
|
| 49 |
+
# Run as non-root user
|
| 50 |
+
RUN useradd -m ttsuser && \
|
| 51 |
+
chown -R ttsuser /app
|
| 52 |
+
USER ttsuser
|
| 53 |
+
|
| 54 |
CMD ["python", "app.py"]
|