Skip to content

feat(release): production service image for scheduled jobs and webhook handlers #753

Closed

Description

@dan-petty

Problem Statement

devops-cli runs in the homelab cluster (#741: any devops command as a Job), and the Service (#752, deployed by #1083) runs the roadmap jobs (#981) there, where the LLM gateway and Prometheus are reachable. Both need an image of their own. The only image devops-cli builds today is the devcontainer, which is a development workstation (git ls-files finds no other Dockerfile, no .dockerignore and no .trivyignore at 9c879ae):

  • .devcontainer/Dockerfile:1 starts from debian:sid, unpinned.
  • It installs shellcheck, gnome-keyring, dbus-x11 and bubblewrap (:16-23) and pre-commit (:36).
  • .devcontainer/devcontainer.json:7-29 adds docker-in-docker, kubectl, helm, minikube, Node, Copilot CLI and Claude Code.

No workflow produces an SBOM, a provenance attestation or a vulnerability scan for any image. release.yml:129-150 pushes the devcontainer image with devcontainers/ci, and ci.yml:101-189 builds the PR image the same way (and pushes it as pr-<n>, :189). rg -n -i 'sbom|attest|provenance|trivy' .github/workflows finds nothing. The release job grants no id-token or attestations permission (release.yml:24-28) and exposes no job outputs:.

What the service needs at runtime (checked at 9c879ae):

  • Python packages. pyproject.toml:11-57 declares 46 runtime dependencies and no extras. The locked runtime closure is 123 packages; all install from wheels except ratelimit 2.2.1, a pure-Python sdist (uv.lock:2809-2812), so no compiler is needed. pyproject.toml declares no readme, so the wheel build does not read README.md. [project.scripts] installs the devops entry point (pyproject.toml:60-61).
  • gh and git. run_gh runs the gh binary (github/rate_limiter.py:1874, CONST_GH_CLI at config/constants.py:676). Git runs as a subprocess (git/operations.py:276, commands/release.py:803-823) and through GitPython for clones (git/operations.py:195-199).
  • A server. devops serve (commands/serve.py:33-133) runs the FastAPI app on 127.0.0.1:8000 by default (config/defaults.py:314-315) and has a --docs/--no-docs switch (serve.py:67). It already answers /healthz with status and version (server/routes/health.py:22-34).
  • Writable paths. The CLI writes to .data relative to the working directory (config/defaults.py:30), which DEVOPS_CLI_DATA_DIR overrides (config/settings.py:724). It reads ~/.config/devops-cli (config/constants.py:15).

Where the CLI lets the service work (checked at 9c879ae):

  • No home under /var. CONST_FORBIDDEN_SYSTEM_DIRS lists /etc, /usr, /bin, /sbin, /var, /sys and /proc (config/constants.py:185-193); core/paths.py:99-103 adds /dev and /boot. run_subprocess refuses a working directory under them (core/process.py:200-203). Clone refuses a destination under them (git/operations.py:170-184). write_file refuses a target under them (output/file_writer.py:25-31). So a home, data directory or checkout under /var breaks git, clones and data writes. /home and /app are allowed.
  • Child processes get a filtered environment. run_subprocess passes only allowlisted variables (core/process.py:27-77) and drops names matching *TOKEN*, *SECRET*, *KEY*, *PASSWORD*, *CREDENTIAL*, *AUTH* or *PRIVATE* (:86-94). It adds GH_TOKEN back only when the binary is gh (:206-215, :247-248). GIT_CONFIG_GLOBAL and GIT_CONFIG_SYSTEM pass through (:71-72) but GIT_CONFIG_COUNT/GIT_CONFIG_KEY_*/GIT_CONFIG_VALUE_* do not, so the devcontainer's credential-helper variables never reach git through it, and neither does the token, for example on git push (commands/release.py:822-823). GitPython's clone inherits the full environment.
  • A passwd entry. getpass.getuser() (core/audit.py:47) fails for a UID that has no passwd entry and no USER/LOGNAME variable.

The cluster's conventions are in k8s/llm/gateway/deployment.yaml:

  • UID and GID 1000, runAsNonRoot and seccomp RuntimeDefault (:22-28);
  • no privilege escalation, a read-only root filesystem and all capabilities dropped (:34-39);
  • /tmp on an emptyDir (:74-75, :100-101).

All four homelab nodes are amd64 (kubectl get nodes -o wide, 2026-10-01).

Proposed Solution

A service image that CI builds and the release workflow publishes.

Dockerfile at the repo root, with a .dockerignore

.dockerignore admits only pyproject.toml, uv.lock, README.md and src/. README.md stays in the allowlist for the devcontainer build, whose COPY pyproject.toml README.md (.devcontainer/Dockerfile:40) shares the repo-root context (.devcontainer/devcontainer.json:3-6); the service Dockerfile need not copy it. The smoke test adds no file to the tree (it is a run: block in each workflow, see below), so nothing else enters the allowlist.

  • A uv stage: FROM ghcr.io/astral-sh/uv:<version>@sha256:… AS uv.
  • Builder stage on python:3.14-slim-trixie, pinned by digest:
    • uv copied from the uv stage;
    • uv sync --locked --no-dev --no-editable into /app/.venv, with UV_COMPILE_BYTECODE=1 and UV_PYTHON_DOWNLOADS=never;
    • the pinned gh release tarball, fetched with ADD --checksum=sha256:… and unpacked.
  • Final stage on the same base digest. It holds git from Debian (--no-install-recommends), the gh binary and /app/.venv. It holds no uv, no dev-group package, no compiler, no apt lists or caches, and no credentials.
  • A user devops with UID and GID 1000 and home /home/devops, created with useradd. USER 1000:1000. /home/devops is both HOME and WORKDIR. DEVOPS_CLI_DATA_DIR=/home/devops/.data.
  • /etc/gitconfig, written with git config --system, makes !gh auth git-credential the credential helper for https://github.com and https://gist.github.com. These are the same two helpers that .devcontainer/devcontainer.json:47-54 sets through GIT_CONFIG_*. Git reads a system config whatever environment run_subprocess passes it.
  • Environment:
    • PATH starts with /app/.venv/bin;
    • PYTHONUNBUFFERED=1, GH_PROMPT_DISABLED=1 and GH_NO_UPDATE_NOTIFIER=1. The two GH_ variables only matter when a person runs gh in the container. run_subprocess does not pass them on, and gh does not prompt or check for updates without a terminal.
  • ENTRYPOINT ["devops"], CMD ["serve", "--host", "0.0.0.0", "--no-docs"], EXPOSE 8000.

Smoke test: one run: block, inlined in both workflows

The smoke test is a single run: block whose text is identical in ci.yml and release.yml. The image reference reaches it through env: IMAGE: … (the locally loaded tag in CI, the built tag before the push in the release job), never through ${{ }} inside the script. No script file, composite action or devops subcommand is added; actionlint, which the gate already runs over every workflow (commands/ci.py:436-439) and which runs shellcheck over each run: block when shellcheck is on the path (the devcontainer installs it, .devcontainer/Dockerfile:16-23), lints it. By hand, a person runs the same commands with devops-cli-service:local in place of $IMAGE (they are listed verbatim in the Acceptance Criteria). The block starts the image with --read-only --tmpfs /tmp --tmpfs /home/devops:uid=1000,gid=1000 --cap-drop ALL --security-opt no-new-privileges and checks that:

  • /healthz returns "status":"ok" and the pyproject.toml version;
  • id -u prints 1000;
  • gh --version and git --version succeed;
  • a probe gets past the CLI's own guards. It writes a file into the data directory with write_text_file (output/file_writer.py:174), runs git status through run_subprocess in a repo under $HOME, and gets devops from getpass.getuser();
  • command -v uv, command -v gcc and python -c 'import pytest' fail.

ci.yml: a service-image job

  • No needs, permissions: contents: read.
  • Runs on pull requests into main when an input changes, and always on workflow_dispatch (ci.yml:16 already declares the trigger). The inputs are Dockerfile, .dockerignore, .trivyignore, src, pyproject.toml, uv.lock, README.md and .github/workflows/ci.yml, declared in an IMAGE_CONTENT_PATHS env block the way the devcontainer job does (ci.yml:124-148). The smoke test is part of ci.yml itself, so it needs no entry of its own.
  • Builds with push: false and load: true, then runs the smoke test, then the Trivy scan.

ci.yml: the devcontainer job's change filter also watches .dockerignore

The devcontainer build uses the repo root as its context too (.devcontainer/devcontainer.json:3-6). Nothing else in that job (ci.yml:101-189) changes.

release.yml

  • The release job exposes version as a job output (from steps.ver, release.yml:59-73; the job has no outputs: today).
  • A new service-image job has needs: release and these permissions: contents: read, packages: write, id-token: write and attestations: write.
  • It builds and loads the image, runs the smoke test and then the Trivy scan.
  • Only then does it push ghcr.io/dan-petty/devops-cli/service:v<version> and :latest, with sbom: true and OCI labels from docker/metadata-action (source, revision, version, licenses=MIT; LICENSE:1 is MIT).
  • Last, actions/attest-build-provenance attests the pushed digest with push-to-registry: true.

Trivy settings in both workflows

scanners: vuln, severity: HIGH,CRITICAL, ignore-unfixed: true and exit-code: 1. aquasecurity/trivy-action is pinned by commit SHA, and that commit must itself reference aquasecurity/setup-trivy by commit SHA. The Trivy binary is pinned by version. A finding that cannot be fixed yet goes in .trivyignore with a reason and an exp: date.

.github/dependabot.yml

A docker entry for / that follows the existing two entries (:3-31, both targeting release/v0.2.14 today).

Tests (structural tuple assertions that only read files)

  • The path-filter test test_devcontainer_image_path_filter_covers_dockerfile_sources (tests/test_architectural_invariants.py:428-460) and its helpers _dockerfile_build_context_sources (:397) and _ci_image_content_paths (:416-425, hard-wired to jobs["devcontainer"]) are parametrized over both images: .devcontainer/Dockerfile with the devcontainer job, and Dockerfile with the service-image job. Each filter must also watch .dockerignore.
  • Every FROM and COPY --from= image in Dockerfile carries @sha256:. Stage names are exempt.
  • tests/test_ci.py pins the CI job's if, push: false and permissions, beside the existing devcontainer job test (:616-628).
  • It also pins the release job's needs, permissions, step order (build, smoke, scan, push, attest), Trivy inputs and sbom: true, and checks that no run: in either new job contains ${{. No test reads release.yml today (rg -n release.yml tests/ finds only a path label string at tests/test_reference_extractor.py:246), so this adds the first such test.
  • One tests/test_ci.py assertion loads both workflows, finds the smoke step of each service-image job by name, and asserts that the two run: strings are equal and that the string contains --read-only, --cap-drop ALL and no-new-privileges.

Docs

docs/ROUTINE_TASKS.md:270 (step 5 of the release procedure) names the service image and the verify command, gh attestation verify oci://ghcr.io/dan-petty/devops-cli/service:v<version> -R dan-petty/devops-cli --signer-workflow dan-petty/devops-cli/.github/workflows/release.yml.

Changelog

changelog.d/753.md; CHANGELOG.md and docs/ROADMAP.md are not edited.

Scope

One pull request delivering: Dockerfile, .dockerignore, the smoke-test run: block in both workflows, the service-image job in ci.yml and in release.yml (plus the version output and the .dockerignore filter entry), the Dependabot docker entry, the tests above, the docs/ROUTINE_TASKS.md line, the task file docs/agent/tasks/task-753-production-service-image.md and changelog.d/753.md.

Constraints:

  • The final image holds only the Python runtime, the locked runtime dependencies, devops-cli, gh, git and their libraries.
  • HOME, the data directory and any checkout stay outside CONST_FORBIDDEN_SYSTEM_DIRS.
  • Image builds and scans run in GitHub Actions or by hand, never in uv run devops ci. The in-gate tests only read files and add under 1 s.
  • Every new uses: is pinned by commit SHA, and so is trivy-action's own setup-trivy reference. Expressions reach run: scripts only through env:.
  • The devcontainer image is unchanged. Its job changes only by watching .dockerignore.
  • The image is built for linux/amd64 only.
  • The smoke test lives only in the two workflow files: no scripts/ directory, shell file, composite action or devops subcommand is added for it.

Key Questions

Acceptance Criteria

  • The image builds from a clean clone: docker build -t devops-cli-service:local .. The builder runs this and records the size from docker image ls devops-cli-service:local in the task file.
  • The smoke test passes by hand with the commands below, which are the same commands the two workflow run: blocks run with $IMAGE in place of devops-cli-service:local. Each command does what its comment says:
    docker run -d --name svc --read-only --tmpfs /tmp --tmpfs /home/devops:uid=1000,gid=1000 --cap-drop ALL --security-opt no-new-privileges -p 8000:8000 devops-cli-service:local
    curl -fsS --retry 10 --retry-connrefused --retry-delay 1 http://127.0.0.1:8000/healthz   # "status":"ok" and the pyproject.toml version
    docker run --rm --entrypoint id devops-cli-service:local -u                    # 1000
    docker run --rm --entrypoint gh devops-cli-service:local --version            # exits 0
    docker run --rm --entrypoint git devops-cli-service:local --version           # exits 0
    docker run --rm --read-only --tmpfs /tmp --tmpfs /home/devops:uid=1000,gid=1000 --cap-drop ALL --security-opt no-new-privileges --entrypoint python devops-cli-service:local -c "import getpass, pathlib, subprocess; from devops_cli.config.settings import load_settings; from devops_cli.core.process import run_subprocess; from devops_cli.output.file_writer import write_text_file; write_text_file(load_settings().data.dir / 'probe.txt', 'ok'); repo = pathlib.Path.home() / 'probe'; subprocess.run(['git', 'init', '-q', str(repo)], check=True); assert run_subprocess(['git', 'status', '--porcelain'], cwd=repo).returncode == 0; assert getpass.getuser() == 'devops'"   # exits 0
    docker run --rm --entrypoint sh devops-cli-service:local -c 'command -v uv'   # exits non-zero
    docker run --rm --entrypoint sh devops-cli-service:local -c 'command -v gcc'  # exits non-zero
    docker run --rm --entrypoint python devops-cli-service:local -c 'import pytest'  # exits non-zero
    
  • gh workflow run ci.yml --ref <delivering branch> produces a run whose service-image job passes its build, smoke and Trivy steps and pushes nothing. The run's link goes in the task file.
  • The devcontainer still builds with the new .dockerignore: the builder runs docker build -f .devcontainer/Dockerfile . and it succeeds.
  • git ls-files | rg '^scripts/|\.sh$|^\.github/actions/smoke' is still empty on the delivering branch: the smoke test added no script or composite action.
  • The new tests pass (uv run pytest tests/test_ci.py tests/test_architectural_invariants.py). The builder breaks each guarded property once, confirms that its check fails, and notes each result in the task file. The properties are:
    • a FROM without @sha256:;
    • a COPY source that the service filter does not watch;
    • .dockerignore missing from either filter;
    • the scan moved after the push;
    • push: true in the CI job;
    • ${{ inside a new run:;
    • the two workflows' smoke-test run: strings differing by one character, and one of them losing --read-only, --cap-drop ALL or no-new-privileges;
    • HOME, WORKDIR and DEVOPS_CLI_DATA_DIR under /var/lib/devops-cli, which must make the smoke probe exit non-zero.
  • The task file records the pinned trivy-action commit and the setup-trivy commit SHA that its action.yml uses.
  • uv run actionlint passes (commands/ci.py:436-439 runs it in the gate), which lints both copies of the smoke-test block. uv run devops ci passes within budget, and the new tests add under 1 s in total, measured with uv run pytest tests/test_ci.py tests/test_architectural_invariants.py --durations=0.
  • rg -n 'package-ecosystem: "docker"' .github/dependabot.yml finds the new entry.
  • changelog.d/753.md exists; git diff --name-only main...HEAD lists neither CHANGELOG.md nor docs/ROADMAP.md.
  • Pending a person, after v0.2.26 ships:
    • gh attestation verify oci://ghcr.io/dan-petty/devops-cli/service:v0.2.26 -R dan-petty/devops-cli --signer-workflow dan-petty/devops-cli/.github/workflows/release.yml exits 0.
    • docker buildx imagetools inspect ghcr.io/dan-petty/devops-cli/service:v0.2.26 --format '{{ json .SBOM }}' prints an SPDX document.
    • DOCKER_CONFIG=$(mktemp -d) docker pull ghcr.io/dan-petty/devops-cli/service:v0.2.26 succeeds without a login.
    • docker run --rm ghcr.io/dan-petty/devops-cli/service:v0.2.26 --version prints devops-cli 0.2.26 (main.py:190 prefixes the version with devops-cli).

Out of Scope

Dependencies

Activity

  1. added this to the v0.2.26 milestone on Sep 30, 2026
  2. added
    type/feature
    priority/p1-high
    scope/release
    on Sep 30, 2026
  3. dan-petty commented on Oct 3, 2026

    @dan-petty
    OwnerAuthor

    Owner's order of 2026-10-03: this item is the first merge of v0.2.26, then #741 (the in-cluster runtime that runs this image as cluster jobs), then #420. #742 starts in parallel. The Deployment references moved to #1083.

  4. dan-petty commented on Oct 4, 2026

    @dan-petty
    OwnerAuthor

    Closed by #1152, merged into release/v0.2.26.

    GitHub only acts on closing keywords when a pull request merges into the default branch, so this was closed by devops gh issues close-merged.

  5. added a commit that references this issue on Oct 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority/p1-highscope/releasetype/feature

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions