File size: 1,863 Bytes
7ebcfb8
f32dba9
 
d94d73d
f32dba9
7ebcfb8
 
f32dba9
a2206e4
f32dba9
 
d94d73d
f32dba9
 
 
 
 
 
7ebcfb8
f32dba9
3e11369
f32dba9
3e11369
 
d94d73d
 
 
7ebcfb8
c05862d
d94d73d
 
c05862d
 
dc2764b
c05862d
 
 
 
 
 
dc2764b
c05862d
7ebcfb8
 
611e2b4
c05862d
 
3e11369
f32dba9
7ebcfb8
3e11369
7ebcfb8
fa9777d
3e11369
7ebcfb8
 
f32dba9
 
c05862d
 
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
# Use the official Python slim image
FROM python:3.10-slim-bookworm

# Set environment variables to control caching and Python behavior
ENV DEBIAN_FRONTEND=noninteractive
ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1
ENV HF_HOME=/app/cache
ENV NUMBA_CACHE_DIR=/app/cache/numba_cache
ENV CUDA_VISIBLE_DEVICES=""

# Install essential system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
    git \
    build-essential \
    espeak-ng \
    libsndfile1 \
    ffmpeg \
    curl \
    && rm -rf /var/lib/apt/lists/*

# Set the working directory
WORKDIR /app

# ---- START: Non-Root User Configuration ----
# Create a new user 'appuser' with UID 1000 and create their home directory
RUN useradd --create-home --uid 1000 appuser

# Switch to the non-root user
USER appuser

# ---- Add this line to fix the PATH issue ----
ENV PATH="/home/appuser/.local/bin:${PATH}"

# Create the cache directory and set ownership to the new user
# This needs to run as root, so we'll adjust the Dockerfile structure slightly
USER root
RUN mkdir -p /app/cache && chown -R appuser:appuser /app /app/cache
USER appuser
# ---- END: Non-Root User Configuration ----

# Copy requirements file and install dependencies as the non-root user
COPY --chown=appuser:appuser requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Clone the NeuTTS Air repository
RUN git clone https://github.com/neuphonic/neutts-air.git

# Copy the application code
COPY --chown=appuser:appuser app.py .

# Expose the application port
EXPOSE 7860

# Add a health check to monitor the application's status
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
    CMD curl -f http://localhost:7860/health || exit 1

# Set the command to run the application
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1"]