vocalcore / Dockerfile
tscr-369's picture
Update Dockerfile
37f1850 verified
# Use Python 3.11 slim image for faster startup
FROM python:3.11-slim
# Install system dependencies
RUN apt-get update && apt-get install -y \
git \
ffmpeg \
libsndfile1 \
curl \
&& rm -rf /var/lib/apt/lists/*
# Create a non-root user
RUN useradd --create-home --shell /bin/bash appuser
# Set working directory
WORKDIR /app
# Create cache directory for Hugging Face Hub with proper permissions
RUN mkdir -p /app/.cache && \
chown -R appuser:appuser /app/.cache && \
chmod -R 755 /app/.cache
# Create temp directory with proper permissions
RUN mkdir -p /tmp && \
chown -R appuser:appuser /tmp && \
chmod -R 755 /tmp
# Set environment variables for Hugging Face Hub
ENV HF_HOME=/app/.cache
ENV HF_DATASETS_CACHE=/app/.cache/datasets
ENV HF_HUB_CACHE=/app/.cache/hub
# Copy requirements first for better caching
COPY requirements.txt .
# Install Python dependencies
RUN pip install --upgrade pip && \
pip install -r requirements.txt
# Copy application code
COPY main.py .
# Change ownership of the app directory
RUN chown -R appuser:appuser /app
# Switch to non-root user
USER appuser
# Expose port
EXPOSE 8000
# Health check
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8000/health || exit 1
# Run the application
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]