FROM python:3.10-slim WORKDIR /code # Install system dependencies RUN apt-get update && apt-get install -y \ build-essential \ curl \ software-properties-common \ && rm -rf /var/lib/apt/lists/* # Create a non-root user RUN useradd -m -u 1000 chainlit_user # Copy requirements first for better caching COPY requirements.txt /code/requirements.txt RUN pip install --no-cache-dir -r requirements.txt # Create necessary directories RUN mkdir -p /code/.files && \ mkdir -p /code/.chainlit # Copy the rest of the application COPY . /code/ # Set permissions RUN chown -R chainlit_user:chainlit_user /code && \ chmod -R 755 /code && \ chmod -R 777 /code/.files && \ chmod -R 777 /code/.chainlit # Set environment variables ENV HOST=0.0.0.0 ENV PORT=7860 ENV PYTHONPATH=/code ENV OPENAI_API_KEY=${OPENAI_API_KEY} ENV PYTHONUNBUFFERED=1 # Switch to non-root user USER chainlit_user # Command to run the application CMD chainlit run app.py --host $HOST --port $PORT