support-system / Dockerfile
ayush2917's picture
Update Dockerfile
e13aa67 verified
# Use a slim Python 3.9 base image
FROM python:3.9-slim-buster@sha256:320a7a4250aba4249f458872adecf92eea88dc6abd2d76dc5c0f01cac9b53990
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
HF_HOME=/app/cache \
HUGGINGFACE_HUB_DISABLE_XET=1 \
PIP_NO_CACHE_DIR=1
# Set working directory
WORKDIR /app
# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
gcc \
g++ \
&& rm -rf /var/lib/apt/lists/*
# Upgrade pip to the latest version
RUN pip install --upgrade pip
# Copy requirements first for better caching
COPY requirements.txt .
# Install dependencies from requirements.txt
RUN pip install --no-cache-dir -r requirements.txt || { echo "Failed to install requirements"; exit 1; }
# Pre-download models
RUN python -c "from sentence_transformers import SentenceTransformer; SentenceTransformer('all-MiniLM-L6-v2', cache_folder='/app/cache')" || { echo "Failed to pre-download SentenceTransformer model"; exit 1; }
RUN python -c "from transformers import AutoModelForCausalLM, AutoTokenizer; AutoModelForCausalLM.from_pretrained('distilgpt2', cache_dir='/app/cache'); AutoTokenizer.from_pretrained('distilgpt2', cache_dir='/app/cache')" || { echo "Failed to pre-download transformer model"; exit 1; }
# Verify cache contents
RUN ls -l /app/cache && \
find /app/cache -type f || { echo "Cache verification failed"; exit 1; }
# Create directories, user, and set permissions
RUN mkdir -p /app/data /app/cache && \
useradd -m myuser && \
chown -R myuser:myuser /app && \
chmod -R u+rw /app/data
# Copy all project files
COPY . .
# Set non-root user
USER myuser
# Expose port for Gunicorn
EXPOSE 8000
# Start Gunicorn with a single worker to reduce memory usage
CMD ["gunicorn", "--bind", "0.0.0.0:8000", "--workers", "1", "--timeout", "120", "app:app"]