neu / Dockerfile
Rajhuggingface4253's picture
Rename dockerfile to Dockerfile
71c9bd8 verified
# 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 --extra-index-url https://download.pytorch.org/whl/cpu
# 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"]