# 1. Base Image: Use a slim Python image FROM python:3.10-slim # 2. Set Environment Variables # General Python/PIP settings ENV PYTHONUNBUFFERED=1 ENV PIP_NO_CACHE_DIR=off ENV PIP_DISABLE_PIP_VERSION_CHECK=on # Hugging Face cache settings ENV HF_HOME="/app/huggingface_cache" ENV TRANSFORMERS_CACHE="/app/huggingface_cache/transformers" # Optional: For Hugging Face token (if needed for private models, Gemma is public) # ENV HUGGING_FACE_HUB_TOKEN="your_hf_token_here" # Pass at runtime or via secrets # 3. Set Working Directory WORKDIR /app # 4. Copy requirements file and install dependencies # This is done before copying the rest of the app to leverage Docker layer caching. COPY requirements.txt . RUN apt-get update && apt-get install -y --no-install-recommends \ build-essential \ && rm -rf /var/lib/apt/lists/* RUN pip install --no-cache-dir -r requirements.txt # 5. Copy the rest of the application code COPY app.py . # 6. Create the cache directory and set permissions RUN mkdir -p $HF_HOME && chmod -R 777 $HF_HOME # Note: chmod 777 is permissive; for production, consider a more specific user/group. # 7. Expose the port the app runs on EXPOSE 8000 # 8. Command to run the application CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]