33 lines
1.2 KiB
Docker
33 lines
1.2 KiB
Docker
# syntax=docker/dockerfile:1
|
|
# Runtime image is pinned by digest, dependencies by version in requirements.txt.
|
|
FROM python:3.12.7-slim-bookworm@sha256:60d9996b6a8a3689d36db740b49f4327be3be09a21122bd02fb8895abb38b50d
|
|
|
|
ENV PYTHONDONTWRITEBYTECODE=1 \
|
|
PYTHONUNBUFFERED=1 \
|
|
APP_HOST=0.0.0.0 \
|
|
APP_PORT=8080
|
|
|
|
WORKDIR /app
|
|
|
|
# Unprivileged runtime user; the API never needs to write to the image.
|
|
RUN groupadd --system --gid 10001 messenger \
|
|
&& useradd --system --uid 10001 --gid messenger --no-create-home messenger
|
|
|
|
COPY requirements.txt /app/requirements.txt
|
|
RUN pip install --no-cache-dir --requirement /app/requirements.txt
|
|
|
|
COPY --chown=messenger:messenger src/ /app/src/
|
|
COPY --chown=messenger:messenger contracts/ /app/contracts/
|
|
COPY --chown=messenger:messenger --chmod=0555 entrypoint.sh /app/entrypoint.sh
|
|
|
|
USER messenger
|
|
EXPOSE 8080
|
|
STOPSIGNAL SIGTERM
|
|
|
|
# Readiness (not just liveness) so an unhealthy container is visible to Compose.
|
|
HEALTHCHECK --interval=5s --timeout=5s --start-period=20s --retries=3 \
|
|
CMD ["python", "-c", "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8080/health/ready', timeout=2).read()"]
|
|
|
|
# Migrations are idempotent; the entrypoint execs the server so it is PID 1.
|
|
ENTRYPOINT ["/app/entrypoint.sh"]
|