# Use the official Python 3.12.6 image | |
FROM python:3.12.6 | |
# Create a new group and user | |
RUN groupadd -r appuser && useradd -r -g appuser appuser | |
# Set environment variables for cache directories | |
ENV TRANSFORMERS_CACHE=/app/hf_cache | |
ENV HF_HOME=/app/hf_cache | |
# Create the cache directory and set permissions | |
RUN mkdir -p /app/hf_cache && chown -R appuser:appuser /app/hf_cache | |
# Set the working directory | |
WORKDIR /app | |
# Copy the current directory contents into the container at /app | |
COPY --chown=appuser:appuser . /app | |
# Install requirements | |
RUN pip install --no-cache-dir --upgrade -r requirements.txt | |
# Switch to the new user | |
USER appuser | |
# Start the FastAPI app on port 7860 | |
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"] | |