File size: 1,065 Bytes
7bf41e6 54660dc 7bf41e6 |
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 40 41 42 43 |
# Use NVIDIA CUDA base image if possible, otherwise standard python
FROM python:3.10-slim
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV TRANSFORMERS_CACHE=/app/cache
ENV MPLCONFIGDIR=/app/cache
ENV HOME=/home/user
# Install system dependencies
RUN apt-get update && apt-get install -y build-essential libgl1 libglib2.0-0 && rm -rf /var/lib/apt/lists/*
# Set up a new user named "user" with UID 1000
RUN useradd -m -u 1000 user
# Create app directory
WORKDIR /app
# Install dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Create cache directory with right permissions
RUN mkdir -p /app/cache && chmod 777 /app/cache
# Switch to the "user" user
USER user
# Set home to /home/user
ENV HOME=/home/user
ENV PATH=/home/user/.local/bin:$PATH
# Copy app code (owned by user)
COPY --chown=user . .
# Expose port (HuggingFace default is 7860)
EXPOSE 7860
# Start command
# We use uvicorn to run the FastAPI app on port 7860
CMD ["python", "api.py", "--port", "7860"]
|