# syntax=docker/dockerfile:1
#
# Packages the example outbox worker (examples/outbox_worker) as a standalone image for
# local container testing of the eventcommon publisher/consumer/outbox stack. This library
# itself ships as a wheel/sdist (see `make build`); this image is a runnable demonstration,
# not a production artifact of the library.

FROM python:3.14-slim AS builder

WORKDIR /src

COPY pyproject.toml README.md ./
COPY src ./src
COPY examples ./examples

RUN pip install --no-cache-dir --prefix=/install "."

FROM python:3.14-slim

# Pinning apt versions on python:3.14-slim is brittle: Debian's archive rotates old
# point-release versions out, breaking the build on every base image bump.
# hadolint ignore=DL3008
RUN apt-get update && apt-get install -y --no-install-recommends curl \
    && rm -rf /var/lib/apt/lists/* \
    && useradd --no-create-home --shell /usr/sbin/nologin appuser

WORKDIR /app

ARG APP_NAME=eventcommon-outbox-worker-example
ARG BUILD_VERSION=unknown

COPY --from=builder /install /usr/local
COPY examples ./examples

ENV APP_NAME=${APP_NAME} \
    APP_ENV=prod \
    BUILD_VERSION=${BUILD_VERSION} \
    HEARTBEAT_PATH=/tmp/heartbeat \
    PYTHONUNBUFFERED=1

# The worker has no HTTP server — health is a heartbeat file touched every 10s by the
# main loop (see examples/outbox_worker/main.py). A stale or missing file means the
# process is hung or dead.
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
    CMD python -c "import pathlib,sys,time; p=pathlib.Path('${HEARTBEAT_PATH:-/tmp/heartbeat}'); sys.exit(0 if p.exists() and time.time()-p.stat().st_mtime < 30 else 1)"

USER appuser

ENTRYPOINT ["python", "-m", "examples.outbox_worker.main"]
