FROM python:3.12-slim # Set environment variables ENV PYTHONDONTWRITEBYTECODE=1 \ PYTHONUNBUFFERED=1 # Set the working directory inside the container WORKDIR /app # Install system dependencies required for MySQL and other libraries RUN apt-get update && apt-get install -y --no-install-recommends git && \ rm -rf /var/lib/apt/lists/* # Create a new non-root user and switch to it RUN groupadd --system appuser && useradd --system --create-home --gid appuser appuser COPY files/requirements.txt /tmp/requirements.txt RUN sleep 5 # Install Python dependencies RUN pip install --upgrade pip && pip install --no-cache-dir -r /tmp/requirements.txt COPY . . # RUN /usr/local/bin/alembic -c alembic/alembic.ini upgrade head # Change ownership to the new user RUN chown -R appuser:appuser /app # Switch to the new non-root user USER appuser ENTRYPOINT ["/app/scripts/run.sh"]