# Use an official lightweight Python base image FROM python:3.10-slim # Set environment variables ENV PYTHONDONTWRITEBYTECODE=1 ENV PYTHONUNBUFFERED=1 ENV PORT=7860 # Set working directory WORKDIR /code # Install system dependencies if any are needed RUN apt-get update && apt-get install -y --no-install-recommends \ build-essential \ && rm -rf /var/lib/apt/lists/* # Copy requirements and install dependencies COPY requirements.txt /code/ RUN pip install --no-cache-dir --upgrade -r requirements.txt # Create directories and files with write access for Hugging Face non-root user (UID 1000) RUN mkdir -p /code/logs && \ touch /code/emails.db && \ chmod -R 777 /code # Copy the rest of the application code COPY . /code/ # Set ownership of the application directory to the non-root user (UID 1000) RUN chown -R 1000:1000 /code # Switch to the non-root user (Hugging Face standard) USER 1000 # Expose port 7860 (Hugging Face standard port) EXPOSE 7860 # Command to run the FastAPI app CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]