File size: 1,280 Bytes
2a0f699
 
 
6ea319c
 
 
 
 
 
 
 
 
 
 
 
2a0f699
 
 
 
 
 
 
 
 
6ea319c
2a0f699
 
 
 
 
6ea319c
2a0f699
6ea319c
2a0f699
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# 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"]