FROM python:3.11.15-bookworm
ENV DEBIAN_FRONTEND=noninteractive
# Install system dependencies required for GUI and OpenCV
RUN apt-get update -y \
&& apt-get install -y --no-install-recommends \
libgl1-mesa-glx \
libx11-6 \
libxext6 \
libxrender1 \
tk \
&& rm -rf /var/lib/apt/lists/*
# Create a non-root user for security
RUN groupadd -r appuser && useradd -m -r -g appuser -d /home/appuser -s /bin/bash appuser
# Prepare working directory and set ownership to non-root user
WORKDIR /app
COPY --chown=appuser:appuser requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
# Copy the rest of the application code
COPY --chown=appuser:appuser . .
# Ensure the app directory is owned by the non-root user
RUN chown -R appuser:appuser /app
USER appuser
CMD ["python","run.py"]