BirthdayM / Dockerfile
ayush2917's picture
Update Dockerfile
af22415 verified
raw
history blame
1.21 kB
FROM python:3.10-slim
WORKDIR /app
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ENV HUGGINGFACE_API_TOKEN=${HUGGINGFACE_API_TOKEN}
ENV TRANSFORMERS_CACHE=/tmp/cache
ENV HF_HOME=/tmp/cache
# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
curl \
&& mkdir -p /tmp/cache \
&& chmod 777 /tmp/cache \
&& rm -rf /var/lib/apt/lists/*
# Copy requirements first to leverage Docker cache
COPY requirements.txt .
# Install Python dependencies
RUN pip install --no-cache-dir --upgrade pip \
&& pip install --no-cache-dir -r requirements.txt
# Copy application code
COPY . .
# Create necessary directories and initialize empty cache if needed
RUN mkdir -p static/audio static/assets \
&& python -c "import joblib; joblib.dump({}, 'embeddings_cache.joblib')" \
&& chmod 666 embeddings_cache.joblib
# Expose port
EXPOSE 7860
# Run Gunicorn with optimized settings
CMD ["gunicorn", "--bind", "0.0.0.0:7860", "--workers", "1", "--threads", "4", "--timeout", "120", "app:app"]
# Healthcheck
HEALTHCHECK --interval=30s --timeout=3s \
CMD curl -f http://localhost:7860/health || exit 1