FROM python:3.9 WORKDIR /code COPY ./requirements.txt /code/requirements.txt RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt RUN pip install --upgrade pip RUN apt-get update && apt-get install -y \ libgl1-mesa-glx \ libglib2.0-0 ## # Set environment variables for cache and config directories ENV TRANSFORMERS_CACHE=/code/cache/transformers ENV MPLCONFIGDIR=/code/cache/matplotlib ENV FONTCONFIG_PATH=/code/cache/fontconfig ENV XDG_CACHE_HOME=/code/cache/xdg ENV YOLO_CONFIG_DIR=/code/cache/yolo # Create writable directories RUN mkdir -p /code/cache/huggingface \ /code/cache/matplotlib \ /code/cache/fontconfig \ /code/cache/xdg \ /code/cache/yolo && \ chown -R 1000:1000 /code/cache COPY . . # Ensure the current user owns the directories RUN chown -R 1000:1000 /code # Run the application as a non-root user for better security USER 1000 CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]