Rajhuggingface4253 commited on
Commit
a833272
·
verified ·
1 Parent(s): df85082

Rename Dockerfile to dockerfile

Browse files
Files changed (2) hide show
  1. Dockerfile +0 -67
  2. dockerfile +64 -0
Dockerfile DELETED
@@ -1,67 +0,0 @@
1
- # --- Builder Stage ---
2
- # This stage has build tools like git
3
- FROM python:3.10-slim-bookworm as builder
4
-
5
- ENV DEBIAN_FRONTEND=noninteractive
6
- ENV HF_HOME=/app/cache
7
- ENV HUGGINGFACE_HUB_CACHE=/app/cache
8
-
9
- RUN apt-get update && apt-get install -y --no-install-recommends git curl \
10
- && rm -rf /var/lib/apt/lists/*
11
-
12
- WORKDIR /app
13
-
14
- # Clone the neutts-air source code
15
- RUN git clone https://github.com/neuphonic/neutts-air.git
16
-
17
- # --- Final Stage ---
18
- # This is the lean, final image for production
19
- FROM python:3.10-slim-bookworm
20
-
21
- ENV DEBIAN_FRONTEND=noninteractive
22
- ENV HF_HOME=/app/cache
23
- ENV HUGGINGFACE_HUB_CACHE=/app/cache
24
- ENV HF_HUB_DISABLE_LOCKING=1
25
- ENV PYTHONUNBUFFERED=1
26
- ENV PYTHONDONTWRITEBYTECODE=1
27
-
28
- # Install essential system dependencies for the model
29
- RUN apt-get update && apt-get install -y --no-install-recommends \
30
- espeak-ng libsndfile1 ffmpeg \
31
- && rm -rf /var/lib/apt/lists/*
32
-
33
- # Create a non-root user and the cache directory
34
- RUN useradd -m -u 1000 appuser && \
35
- mkdir -p /app/cache && \
36
- chown -R appuser:appuser /app
37
-
38
- # Set working directory
39
- WORKDIR /app
40
-
41
- # Copy the cloned neutts-air code from the builder stage
42
- COPY --from=builder --chown=appuser:appuser /app/neutts-air /app/neutts-air
43
-
44
- # Switch to the non-root user
45
- USER appuser
46
-
47
- # Copy requirements and install them as the non-root user
48
- COPY --chown=appuser:appuser requirements.txt .
49
- RUN pip install --no-cache-dir --upgrade pip && \
50
- pip install --no-cache-dir -r requirements.txt
51
-
52
- # Copy our application, wrapper, and pre-loading script
53
- COPY --chown=appuser:appuser app.py .
54
- COPY --chown=appuser:appuser neutts_wrapper.py .
55
- COPY --chown=appuser:appuser preload_neutts.py .
56
-
57
- # Run the pre-loading script to download the model into the image
58
- RUN python preload_neutts.py
59
-
60
- EXPOSE 7860
61
-
62
- # Add a health check for production monitoring
63
- HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
64
- CMD curl -f http://localhost:7860/health || exit 1
65
-
66
- # Command to run the application
67
- CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dockerfile ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # [file name]: Dockerfile
2
+ FROM python:3.10-slim
3
+
4
+ # Set environment variables
5
+ ENV DEBIAN_FRONTEND=noninteractive
6
+ ENV HF_HOME=/app/cache
7
+ ENV HUGGINGFACE_HUB_CACHE=/app/cache
8
+ ENV NUMBA_CACHE_DIR=/tmp/numba_cache
9
+ ENV HF_HUB_DISABLE_LOCKING=1
10
+ ENV PYTHONUNBUFFERED=1
11
+ ENV PYTHONDONTWRITEBYTECODE=1
12
+
13
+ WORKDIR /app
14
+
15
+ # Install system dependencies
16
+ RUN apt-get update && apt-get install -y --no-install-recommends \
17
+ espeak-ng \
18
+ libsndfile1 \
19
+ git \
20
+ ffmpeg \
21
+ curl \
22
+ && rm -rf /var/lib/apt/lists/*
23
+
24
+ # Create a non-root user with a home directory
25
+ RUN useradd -m -u 1000 appuser && \
26
+ mkdir -p /app/cache /tmp/numba_cache /app/temp_audio && \
27
+ chown -R appuser:appuser /app /tmp/numba_cache
28
+
29
+ # Switch to non-root user for Python package installation
30
+ USER appuser
31
+
32
+ # Set home directory for the user (important for pip cache)
33
+ ENV HOME=/home/appuser
34
+ ENV PATH="/home/appuser/.local/bin:${PATH}"
35
+
36
+ # Copy requirements first (for better caching)
37
+ COPY --chown=appuser:appuser requirements.txt .
38
+
39
+ # Install Python dependencies as non-root user
40
+ RUN pip install --user --no-cache-dir --upgrade pip && \
41
+ pip install --user --no-cache-dir -r requirements.txt
42
+
43
+ # Clone neutts-air (shallow clone to save space)
44
+ RUN if [ ! -d "neutts-air" ]; then \
45
+ echo "Cloning neutts-air (shallow clone)..."; \
46
+ git clone --depth 1 https://github.com/neuphonic/neutts-air.git; \
47
+ fi
48
+
49
+ # Copy application code
50
+ COPY --chown=appuser:appuser app.py .
51
+ COPY --chown=appuser:appuser neutts_wrapper.py .
52
+ COPY --chown=appuser:appuser preload_model.py .
53
+
54
+ # Pre-load models during build
55
+ RUN python preload_model.py
56
+
57
+ EXPOSE 7860
58
+
59
+ # Health check
60
+ HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
61
+ CMD curl -f http://localhost:7860/health || exit 1
62
+
63
+ # Command to run the application
64
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1"]