# Use an official Python image as a base FROM python:3.11.11-slim-bullseye # Set the working directory to /app WORKDIR /app # Create a new user and group RUN groupadd -r appgroup RUN useradd -r -g appgroup -G appgroup -m -d /app -s /bin/false appuser # Copy the requirements file COPY requirements.txt . # Install the dependencies RUN pip install -r requirements.txt RUN apt-get update && apt-get install -y libgl1 RUN apt-get update && apt-get install -y libglib2.0-dev RUN apt-get update && apt-get install -y libzbar0 # Copy the application code COPY . . # Expose the port EXPOSE 8000 # Copy the entrypoint script COPY entrypoint.sh /app/entrypoint.sh # Make the script executable RUN chmod +x /app/entrypoint.sh # Change ownership of the app directory to the new user RUN chown -R appuser:appgroup /app RUN find /app -path "*/migrations/*.py" -not -name "__init__.py" -delete RUN find /app -path "*/migrations/*.pyc" -delete # Set the entrypoint to execute the script as the new user ENTRYPOINT ["sh", "-c", "python3 manage.py makemigrations && python3 manage.py migrate && python3 manage.py collectstatic --no-input && python3 manage.py runserver 0.0.0.0:8000"]