Some checks failed
build / container (push) Failing after 14s
Runs on pushes to master, tag pushes and pull requests:
* the Dockerfile's new `test` stage runs the whole suite, so a failing
test stops the image from being built or pushed at all
* the image builds with plain docker rather than the buildx and login
actions, so a job never has to reach the internet to fetch third-party
actions -- the most common way a self-hosted runner fails
* it pushes to this instance's registry, deriving the host from
github.server_url instead of hardcoding it
Tags published: `latest` and the branch or tag name (only master moves
`latest`), plus an immutable sha-<short> so an image can be traced back to
its commit. Pull requests build but never push, so a fork cannot publish
into the registry.
Two things the gate caught once it ran inside a container:
* the suite reads config.example.json from the repository root, a hidden
dependency that would have failed the first pipeline run
* `[ "$ref_name" = "$DEFAULT_BRANCH" ]` under `set -u` would have aborted
every branch build if that env key were ever renamed; it now has an
inline fallback
`make test-docker` runs the same gate locally, and README.md documents what
the runner needs: docker reachable from the job, and a token allowed to
write packages.
Also untrack .pi/, which holds pi session task output rather than project
files, and ignore it.
48 lines
1.9 KiB
Docker
48 lines
1.9 KiB
Docker
# ---- test stage ----------------------------------------------------------
|
|
# Runs the suite inside the build, so a pipeline can gate the published image
|
|
# on it without needing Python on the runner: docker build --target test .
|
|
#
|
|
# A plain `docker build .` does not build this stage, and nothing from here
|
|
# reaches the runtime image -- the tests are never copied into it.
|
|
FROM python:3.13-alpine AS test
|
|
WORKDIR /src
|
|
COPY app/ ./app/
|
|
COPY tests/ ./tests/
|
|
COPY tools/ ./tools/
|
|
# One test asserts that the shipped example configuration loads, so the suite
|
|
# needs it at the repository root, exactly as it sits in a working tree.
|
|
COPY config.example.json ./
|
|
ENV PYTHONDONTWRITEBYTECODE=1
|
|
# Deliberately not piped into `tail`: a pipeline reports the exit status of its
|
|
# last command, so the gate would pass even when the tests failed.
|
|
RUN python -m unittest discover -s tests -t .
|
|
|
|
# ---- runtime stage -------------------------------------------------------
|
|
# The whole server is the Python standard library, so the image needs no build
|
|
# toolchain, no wheels and no virtual environment -- just an interpreter, a trust
|
|
# store for upstream TLS, and the code.
|
|
FROM python:3.13-alpine
|
|
|
|
RUN apk add --no-cache ca-certificates \
|
|
&& adduser -D -u 10001 -h /srv app
|
|
|
|
ENV PYTHONUNBUFFERED=1 \
|
|
PYTHONDONTWRITEBYTECODE=1 \
|
|
CONFIG_PATH=/config/config.json
|
|
|
|
WORKDIR /srv
|
|
COPY app/ ./app/
|
|
COPY config.example.json ./
|
|
|
|
# Runs as an unprivileged user with no writable path: the server keeps nothing on
|
|
# disk, so the container can be run read-only (see docker-compose.yaml).
|
|
USER app
|
|
EXPOSE 8080
|
|
|
|
# The health endpoint answers without credentials and never calls upstream, so
|
|
# this checks the process, not the network.
|
|
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \
|
|
CMD ["python", "-c", "import sys, urllib.request; sys.exit(0 if urllib.request.urlopen('http://127.0.0.1:8080/healthz', timeout=4).status == 200 else 1)"]
|
|
|
|
ENTRYPOINT ["python", "-m", "app"]
|