Skip to content

feat(greffer): v2 self-update redesign — socket-only :latest + per-container recreate - #93

Merged
omarsy merged 9 commits into
mainfrom
feat/greffer-self-update-v2-recreate
Jun 17, 2026
Merged

omarsy merged 9 commits into
mainfrom
feat/greffer-self-update-v2-recreate

Conversation

@omarsy

@omarsy omarsy commented Jun 17, 2026

Copy link
Copy Markdown
Member

What

Implements the v2 self-update mechanism redesign (HLD greffon#181, with #182 §8 fix + #183 keep-target_tag). Supersedes the shipped compose-based v2 updater: the updater is now socket-only (no compose file, no /work, no GREFFER_HOST_CONFIG_DIR) and recreates each stack container in place via the Docker API.

Closes the open greffer#92 (its host_config_dir approach is removed by this design).

Mechanism

Per update: discover the stack by compose service label → verify-and-pull every image at the server-resolved target_tag (resolve digest, cosign-verify repo-bound, pull by digest) fail-closed before any recreate → per container in order (nginx → greffer → tunnel-sidecar): tag the outgoing image :previous, retag local :latest to the verified digest, recreate carrying config (the §8 fidelity rule) → socket /readyz gate → on success dangling-prune after an anti-downgrade guard; on any failure or exception, roll the whole stack back (recreate from the captured old image and restore :latest).

Key design points (all in the HLD):

  • target_tag kept (server-resolved): all images pull the same version → cohesive release + deterministic; reuses manager#120. Default latest.
  • verify-then-pull-by-digest keeps cosign and closes the tag-moved TOCTOU; a pre-run no-downgrade refusal blocks a numeric downgrade before any old image runs.
  • §10 lock: the updater flocks /data/.update.lock; v1 greffer update relocates to the same volume mountpoint; the controller 409s start/stop/update while an update holds it.
  • updater image stays digest-pinned (most load-bearing, runs first); floor/manifest/ratchet removed from the v2 path; Dockerfile.updater drops the compose plugin.

Tests / review

CLI suite 252 green, app suite 557 green; em-dash clean; no co-author trailers. New recreate/engine/gate test modules + spawn/controller/lock coverage.

Went through a multi-lens adversarial review (security, §8 fidelity, engine/rollback correctness, concurrency, test quality) to convergence: it caught real failure-path gaps — rollback now restores :latest, a mid-recreate exception rolls back, the gate verifies every container's image (not just the greffer), the v1 lock fallback is non-silent — all fixed, confirming round clean.

Manager needs at most a confirm-it-still-fits pass (the API contract is unchanged: empty-body POST, server-resolved target, 202 + updating grace). Frontend: no change (the v2 Update now UI already posts an empty body).

🤖 Generated with Claude Code

omarsy added 8 commits June 17, 2026 22:10
…design)

First increment of the v2 :latest + per-container recreate redesign (HLD
greffon#181, merged). New updater.recreate module with the Docker-API primitives
the socket-only updater needs (no compose file):

- discover_stack: find the greffon stack by compose service label (HLD §4),
  ordered nginx -> greffer -> tunnel-sidecar (§6), repo mapped from the SERVICE
  label not the image name (a prior recreate leaves a bare-digest image);
- verify_then_pull: resolve :latest -> index digest D, cosign-verify D repo-bound,
  pull by @d (only the verified bytes), then retag local :latest -> D (§3 + §13;
  pull-by-digest-then-retag closes the tag-moved TOCTOU and keeps no-downgrade);
- current_image_id / tag_previous: capture the outgoing image and name it
  :previous as a persistent rollback target (§9);
- dangling_prune: dangling-only image prune (§5), never -a / never id-targeted
  rmi, so it cannot reap :latest/:previous or an in-use image.

17 new unit tests (mocked docker/cosign via compose._run); full CLI suite 220
green. Engine rewrite to orchestrate these (recreate loop, fidelity carry-over,
socket /readyz gate, rollback) is the next increment.
… delta)

Increment 2a of the v2 :latest redesign. Adds the per-container fidelity recreate
to updater.recreate, built to the corrected §8 vs-OLD delta (greffon#182):

- build_create_argv: pure reconstruction of the docker create argv from
  docker inspect. Image-influenced fields (Env/Labels/Cmd/Entrypoint/Healthcheck/
  User/WorkingDir/StopSignal) use the vs-OLD delta (carry only what compose
  changed from the OLD image, so the NEW image's baked defaults win for untouched
  vars: a relocated venv or the new GREFFER_UPDATER_IMAGE digest is not clobbered).
  Infra fields carried verbatim: NetworkMode (host-sidecar trap + service-name
  alias for greffer<->nginx DNS), Mounts from .Mounts with :ro preserved,
  PortBindings, RestartPolicy, LogConfig, ExtraHosts.
- inspect_container / image_config helpers (image_config fail-opens to carry
  verbatim if the old image is unreadable).
- recreate_one: inspect -> stop -> rm -> create (same name) -> start, fail-closed.

12 new tests (env-delta drops baked/keeps runtime + operator-pin carried, compose
labels carried, host-network sidecar + :ro + healthcheck, nginx ports, recreate
ordering + abort paths). Full CLI suite 232 green. Next: socket /readyz gate +
engine run loop + rollback + __main__ simplification.
… :latest)

Increment 2b: the orchestration that ties the primitives together.

- engine.run_remote_update (rewritten socket-only): discover stack -> verify+pull
  EVERY image by digest fail-closed (no :latest moved, nothing recreated on a
  verify failure) -> snapshot all containers -> per container in order tag
  :previous, retag :latest to the verified digest, recreate -> /readyz gate -> on
  success dangling-prune after a cheap anti-downgrade guard (app.__version__,
  honest-CI only) -> roll the whole stack back on any failure.
- gate.health_gate (new): socket /readyz gate mirroring update.health_gate but via
  docker exec <name> (stable across recreate); reuses parse_readyz + GATE_*/
  TOLERABLE_DEGRADED_REASONS; check_version=False path for the rollback re-gate.
- recreate: split verify_then_pull into verify_and_pull (no retag) + retag_latest
  so the whole stack verifies before any tag moves; add rollback_one (recreate
  from the captured old image id, by name) + socket probes (exec_readyz/
  exec_version/container_running/container_image_id_by_name/restart_count);
  recreate_one accepts a pre-captured inspect for rollback reuse.
- compose: extract GREFFER_READYZ_PROBE so the compose and socket paths probe
  identically (no drift, the lesson from the lock-filename gap).

67 updater tests (engine refusal/rollback/downgrade, gate outcomes, main lock,
recreate split + rollback + socket probes); full CLI suite 246 green. Dead floor/
manifest machinery removal + __init__ docstring refresh next.
…(v2 :latest)

The :latest redesign drops the min_supported floor + signed-manifest + ratchet
(HLD §7/§11; cosign is kept via verify-then-pull). The engine rewrite already
stopped using floor.py, so remove the now-dead module and split its tests:
keep the provenance tests (test_updater_provenance.py), drop the floor tests.
Refresh updater/__init__.py, which still described the old compose-engine +
floor flow. Full CLI suite 236 green.
…no-downgrade

Implements the keep-target_tag decision (HLD greffon#183). The updater pulls a
server-resolved version instead of always :latest, recovering cross-image
cohesion (all images pull the same version) and determinism:

- recreate.verify_and_pull/verify_then_pull take tag="latest"; resolve
  <repo>:<tag> (the pull source) while the retag target stays local :latest.
- engine.run_remote_update takes target_tag (default latest), threads it to the
  verify+pull-all phase, and adds the pre-run no-downgrade refusal: a NUMERIC
  target lower than the running app.__version__ (read on the current, still-trusted
  image) refuses BEFORE pulling; a non-numeric target (latest) is not comparable
  and falls through to the post-gate guard. Equal target passes (idempotent).
- __main__ reads GREFFER_UPDATER_TARGET_TAG (blank -> None -> latest).

cohesion guarantee holds because verify+pull is fail-closed over ALL images before
any recreate. 7 new tests (tag threading + default latest + pre-run refusal +
non-numeric skip + equal-ok + blank-env). Full CLI suite 243 green.
…(v2 :latest)

Increment 3, the greffer app side of the :latest redesign:

- spawn_updater: mounts ONLY the docker socket + /data (drops the /work compose-dir
  mount and the /app discovery); passes the server-resolved target_tag via
  GREFFER_UPDATER_TARGET_TAG and runs  with no
  positional arg; drops manifest_url + mode (the socket updater has no manifest and
  discovers the stack by label). Keeps the digest-pin contract on the updater image.
- update_in_progress(lock_path): non-blocking flock probe of /data/.update.lock
  (acquire-then-release, so it never holds the lock the updater needs).
- controller: _refuse_if_updating 409s on start/stop/update while an update is
  recreating the stack (HLD §10, the dropped controller-409 mechanism restored);
  remote_update calls spawn_updater with the new signature and probes before spawn.

App suite 555 green (spawn socket-only + target_tag-env + update_in_progress + the
update-in-progress 409). v1 lock relocation + Dockerfile.updater compose-plugin
drop are next.
…ater compose plugin

Increment 4 (HLD §10). The redesigned in-container updater locks
/data/.update.lock (the greffon-data volume); the host v1 `greffer update` locked
<config_dir>/.update.lock, a DIFFERENT inode, so the two never contended. Relocate
v1 to the volume mountpoint so host-v1 and remote-v2 flock the SAME inode:

- compose.data_volume_mountpoint(compose_file): resolve <project>_<volume>'s host
  mountpoint via `docker volume inspect` (project from the compose `name:`, volume
  from the /data named-volume line); None if /data is a bind / unresolvable.
- update._update_lock_path: prefer that mountpoint, fall back to the config dir.
- _acquire_update_lock: if opening the resolved mountpoint path fails (volume dir
  absent), fall back to the config-dir lock rather than crash the operator's run
  (degraded: serializes two host runs, won't contend with the remote updater).
- Dockerfile.updater: drop docker-cli-compose (the socket model recreates per
  container via the Docker API, no compose); refresh the header (/data not /work,
  GREFFER_UPDATER_TARGET_TAG not a positional arg).

CLI suite 248 green (data_volume_mountpoint named/bind/docker-fail + lock-path
relocation/fallback). This completes the greffer code; full review + PR next.
…gate/lock)

Multi-lens adversarial review of the full diff surfaced real gaps in the FAILURE
paths; fixed to convergence:

- engine rollback now restores :latest to the old image per repo (restore_latest),
  not just recreates the container — else a later `docker compose up` re-applies
  the rejected image (the §3 anti-pattern on the rollback path).
- phase 2b + gate wrapped in try/except -> rollback: a RAISE mid-recreate (not
  just a False return) can no longer escape leaving the stack half-updated.
- gate verifies EVERY container is on its new image (applied_image_ids map), not
  just the greffer, so a sibling that came up on the old image can't pass.
- _is_downgrade pads to equal length (0.3 vs 0.3.0 no longer a false downgrade).
- v1 lock fallback to the config dir is now non-silent (warns that a concurrent
  remote update may not be detected) instead of silently losing §10 contention.
- recreate warns (no silent drop) if a container is on >1 network or uses tmpfs
  (the template uses neither; guards a hand-edited/future config).

Tests added: start/stop 409-while-updating, cosign-before-pull ordering, the
/data lock filename rendezvous, rollback-restores-:latest, exception-rolls-back,
downgrade length-pad. CLI 252 + app 557 green; em-dash clean.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 106c468b01

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +479 to +481
if not _run(["rm", "-f", container_ref], timeout=60).ok:
logger.error("recreate %s: removing old container failed", service)
return False

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Handle missing containers during rollback

When a forward recreate removes the old container and then docker create fails, engine records that service for rollback, but rollback_one() calls back into this same rm -f check using the container name. At that point no container with that name exists, and Docker reports No such container with a non-zero status for docker rm -f (as reproduced in docker/cli#2677), so rollback returns before recreating the old image and leaves the service absent. Treat a missing container as already removed on the rollback path or otherwise allow create-from-old to proceed.

Useful? React with 👍 / 👎.

…test

Bump the greffer version so merging publishes a NEW :0.3.5 image instead of
rewriting the mutable :0.3.4 tag (the redesign changes the updater mechanism).
Update the register version assertions accordingly.

Also fix the Windows CI build: test_default_lock_is_data_update_lock asserted
str(Path) == '/data/.update.lock', which is backslashed on Windows. Use
as_posix() so the assertion is OS-independent (the in-container DEFAULT_LOCK is
unchanged; only the test was POSIX-assuming).
@omarsy
omarsy merged commit 38f2e78 into main Jun 17, 2026
6 checks passed
@omarsy
omarsy deleted the feat/greffer-self-update-v2-recreate branch June 17, 2026 22:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant