# Pinned base image (lab3 → lab4). Update digest when bumping Python. FROM python:3.12.8-slim-bookworm AS runtime ENV PYTHONDONTWRITEBYTECODE=1 \ PYTHONUNBUFFERED=1 \ APP_HOST=0.0.0.0 \ APP_PORT=8080 \ PYTHONPATH=/app/src \ MIGRATIONS_DIR=/app/migrations \ UPLOAD_SPOOL_DIR=/tmp/messenger-spool WORKDIR /app RUN groupadd --system --gid 10001 app \ && useradd --system --uid 10001 --gid app --home /app --shell /usr/sbin/nologin app # djpeg (libjpeg-turbo) fully decodes uploaded JPEGs with -strict; prlimit (util-linux) caps it. RUN apt-get update \ && apt-get install -y --no-install-recommends libjpeg-turbo-progs=1:2.1.5-2 \ && rm -rf /var/lib/apt/lists/* COPY requirements.txt . RUN pip install --no-cache-dir --upgrade pip==24.3.1 \ && pip install --no-cache-dir --retries 10 --timeout 60 -r requirements.txt # Code stays root-owned and read-only for the runtime user. COPY src ./src COPY migrations ./migrations USER app EXPOSE 8080 HEALTHCHECK --interval=5s --timeout=3s --start-period=15s --retries=5 \ CMD python -c "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8080/health/ready', timeout=2)" CMD ["python", "-m", "messenger"]