Rajhuggingface4253 commited on
Commit
7ebcfb8
·
verified ·
1 Parent(s): a2206e4

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +24 -17
Dockerfile CHANGED
@@ -1,47 +1,54 @@
 
1
  FROM python:3.10-slim-bookworm
2
 
3
- # Set environment variables
4
  ENV DEBIAN_FRONTEND=noninteractive
5
- ENV HF_HUB_ENABLE_HF_TRANSFER=1
 
6
  ENV HF_HOME=/app/cache
7
  ENV NUMBA_CACHE_DIR=/app/cache/numba_cache
8
- ENV PYTHONUNBUFFERED=1
9
  ENV CUDA_VISIBLE_DEVICES=""
10
 
11
- # Install system dependencies
12
  RUN apt-get update && apt-get install -y --no-install-recommends \
13
  git \
14
  build-essential \
15
  espeak-ng \
16
  libsndfile1 \
17
  ffmpeg \
 
18
  && rm -rf /var/lib/apt/lists/*
19
 
20
  # Set the working directory
21
  WORKDIR /app
22
 
23
- # Create and permission the cache directory
24
- RUN mkdir -p /app/cache && chmod -R 777 /app/cache
 
 
 
 
25
 
26
- # Copy requirements first for better caching
27
- COPY requirements.txt .
 
28
 
29
- # Install Python dependencies
30
- RUN pip install --no-cache-dir -U pip && \
31
- pip install --no-cache-dir -r requirements.txt
32
 
33
- # Clone NeuTTS Air repository
34
  RUN git clone https://github.com/neuphonic/neutts-air.git
35
 
36
  # Copy the application code
37
- COPY app.py .
38
 
39
- # Expose the port
40
  EXPOSE 7860
41
 
42
- # Health check
43
- HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
44
  CMD curl -f http://localhost:7860/health || exit 1
45
 
46
- # Command to run the application
47
  CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1"]
 
1
+ # Use the official Python slim image
2
  FROM python:3.10-slim-bookworm
3
 
4
+ # Set environment variables to control caching and Python behavior
5
  ENV DEBIAN_FRONTEND=noninteractive
6
+ ENV PYTHONUNBUFFERED=1
7
+ ENV PYTHONDONTWRITEBYTECODE=1
8
  ENV HF_HOME=/app/cache
9
  ENV NUMBA_CACHE_DIR=/app/cache/numba_cache
 
10
  ENV CUDA_VISIBLE_DEVICES=""
11
 
12
+ # Install essential system dependencies
13
  RUN apt-get update && apt-get install -y --no-install-recommends \
14
  git \
15
  build-essential \
16
  espeak-ng \
17
  libsndfile1 \
18
  ffmpeg \
19
+ curl \
20
  && rm -rf /var/lib/apt/lists/*
21
 
22
  # Set the working directory
23
  WORKDIR /app
24
 
25
+ # ---- START: Non-Root User Configuration ----
26
+ # Create a new user 'appuser' with UID 1000 and create their home directory
27
+ RUN useradd --create-home --uid 1000 appuser
28
+
29
+ # Create the cache directory and set ownership to the new user
30
+ RUN mkdir -p /app/cache && chown -R appuser:appuser /app /app/cache
31
 
32
+ # Switch to the non-root user
33
+ USER appuser
34
+ # ---- END: Non-Root User Configuration ----
35
 
36
+ # Copy requirements file and install dependencies as the non-root user
37
+ COPY --chown=appuser:appuser requirements.txt .
38
+ RUN pip install --no-cache-dir -r requirements.txt
39
 
40
+ # Clone the NeuTTS Air repository
41
  RUN git clone https://github.com/neuphonic/neutts-air.git
42
 
43
  # Copy the application code
44
+ COPY --chown=appuser:appuser app.py .
45
 
46
+ # Expose the application port
47
  EXPOSE 7860
48
 
49
+ # Add a health check to monitor the application's status
50
+ HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
51
  CMD curl -f http://localhost:7860/health || exit 1
52
 
53
+ # Set the command to run the application
54
  CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1"]