FROM python:3.11-slim # Set environment variables ENV PYTHONDONTWRITEBYTECODE=1 ENV PYTHONUNBUFFERED=1 ENV PORT=7860 ENV DJANGO_SETTINGS_MODULE=config.settings # Set work directory WORKDIR /app # Install system dependencies RUN apt-get update && apt-get install -y \ build-essential \ libpq-dev \ && rm -rf /var/lib/apt/lists/* # Add non-root user specifically for HF Spaces RUN useradd -m -u 1000 user RUN chown -R user:user /app USER user ENV PATH="/home/user/.local/bin:$PATH" # Copy requirements COPY --chown=user:user requirements/ requirements/ # Install python dependencies RUN pip install --no-cache-dir --upgrade pip RUN pip install --no-cache-dir -r requirements/prod.txt # Copy project files COPY --chown=user:user . . # Run collectstatic RUN python manage.py collectstatic --noinput # Expose port for HF Spaces EXPOSE 7860 # Make start script executable RUN chmod +x start.sh # Start the application CMD ["./start.sh"]