- 2 API-реплики (api-1, api-2) с уникальным INSTANCE_ID - Nginx load balancer с health-check и failover - PostgreSQL источник истины, Valkey кэш сессий - Idempotency-Key в заголовке, replay возвращает исходное сообщение - X-Instance-Id в каждом ответе для идентификации реплики - /version и /info эндпоинты - Housekeeping-loop для очистки истёкших сессий и ключей - stop-one.sh/cmd для failover-теста, restart.sh/cmd для persistence - Исправлены импорты config/models/api/store/sessions - Добавлены миграции 004 (idempotency), 005 (indexes), 006 (message_id) - Отчёт с доказательствами критериев уровня 3 и 4 - Все тесты проходят: smoke, 26 student tests, failover, persistence, degradation
36 lines
1.4 KiB
Docker
36 lines
1.4 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
|
|
# Windows hosts may store CRLF; Python and /bin/sh need LF.
|
|
RUN find /app/src -name '*.py' -print0 | xargs -0 sed -i 's/\r$//' \
|
|
&& sed -i 's/\r$//' /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"]
|