Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
73 lines (59 loc) · 2.98 KB
/
Copy pathDockerfile
File metadata and controls
73 lines (59 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# Two stages so the runtime image carries the installed package and its
# dependencies but none of the build tooling.
FROM python:3.12-slim AS build
ENV PIP_DISABLE_PIP_VERSION_CHECK=1 \
PIP_NO_CACHE_DIR=1
WORKDIR /src
# Dependency layer first: the lock changes far less often than the source, so
# an edit to a module reuses the cached dependency install.
#
# Installing from requirements.lock rather than from pyproject means two builds
# of the same commit produce the same image. Resolving from ranges would let a
# release published between them change what ships, silently.
COPY requirements.lock ./
RUN python -m venv /opt/venv \
&& /opt/venv/bin/pip install --upgrade pip \
&& /opt/venv/bin/pip install -r requirements.lock
COPY pyproject.toml README.md LICENSE ./
COPY ops_recall ops_recall
# --no-deps: the lock above already installed the full transitive set, and
# resolving again here would let pip pull something newer than the lock.
RUN /opt/venv/bin/pip install --no-deps .
FROM python:3.12-slim AS runtime
# Non-root: the service reads an index and calls read-only telemetry probes, so
# there is nothing it legitimately needs root for.
RUN useradd --create-home --uid 10001 ops
# The package is installed into site-packages, so the repo-relative defaults
# in config.py do not resolve inside the image; point them at the copied data.
ENV PATH="/opt/venv/bin:$PATH" \
PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
OPS_RECALL_DATA_DIR=/app/data/seed \
OPS_RECALL_TELEMETRY_FIXTURE=/app/data/telemetry/current_state.json
COPY --from=build /opt/venv /opt/venv
WORKDIR /app
# The seed corpus and telemetry fixture ship with the image so `docker run`
# produces the demo with no volume mounts. Point OPS_RECALL_DATA_DIR at a
# mounted directory to index a real archive instead.
COPY --chown=ops:ops data data
COPY --chown=ops:ops evals evals
# Declared last so a rebuild for a new tag reuses every layer above. The
# defaults keep a local `docker build` honest: an image that was not built by
# the release workflow says so rather than claiming a version it may not be.
ARG VERSION=0.0.0-dev
ARG REVISION=unknown
LABEL org.opencontainers.image.title="ops-recall" \
org.opencontainers.image.description="Reconstructs a firing alert from a team's own incident history." \
org.opencontainers.image.source="https://github.com/russellw/ops-recall" \
org.opencontainers.image.licenses="AGPL-3.0-or-later" \
org.opencontainers.image.version="$VERSION" \
org.opencontainers.image.revision="$REVISION"
USER ops
EXPOSE 8000
# The index is built at startup from the configured sources, so readiness is
# not the same as the process being up -- /healthz is only green once the
# lifespan hook has finished indexing.
HEALTHCHECK --interval=30s --timeout=3s --start-period=20s --retries=3 \
CMD python -c "import urllib.request,sys; sys.exit(0 if urllib.request.urlopen('http://127.0.0.1:8000/healthz', timeout=2).status == 200 else 1)"
ENTRYPOINT ["ops-recall"]
CMD ["serve"]