Repository navigation
feat(deploy): one deploy of a stack at a time, under a per-checkout lock - #1041
Merged
Merged
Conversation
On 2026-10-07 a hand `make up` and a `make converge` ran eighteen seconds apart from the deployment checkout. Both recreated alertmanager and blackbox-exporter, and the second failed halfway on a container-name conflict before recording what it applied. scripts/deploy-lock.sh is a per-stack flock in the checkout's git dir. `make up` (render included, via an internal `_up`) runs under it and waits up to HOMELAB_DEPLOY_LOCK_WAIT (900s), naming the holder, then exits 75. converge.sh holds it from reading HEAD to recording, waits up to HOMELAB_CONVERGE_LOCK_WAIT (600s), and otherwise leaves the stack for the next run with exit 0. Its own `make up` passes through via HOMELAB_DEPLOY_LOCK_HELD. Fixtures: 12 in deploy-lock.sh --self-test (concurrent holders, deadline, other stack, nesting, sourced form, stale holder), and a converge case that fails when the lock is removed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
🟡 Changes recommended
Terminating the lock wrapper can release the lock while its deployment command remains running.
1 open finding
What changed in this PR
Adds per-stack deployment locking to prevent concurrent Compose deployments from the same checkout.
Changes:
- Introduces a reusable
flock-based deploy lock with self-tests. - Applies locking to
make upand convergence. - Documents lock behavior and the triggering incident.
| File | Description |
|---|---|
scripts/deploy-lock.sh |
Implements lock acquisition, holder reporting, command wrapping, and tests. |
scripts/converge.sh |
Holds the deploy lock throughout convergence. |
Makefile |
Runs the complete up workflow under the lock. |
scripts/README.md |
Catalogs the new utility. |
docs/runbooks/converge-the-host.md |
Documents contention behavior and diagnostics. |
docs/changelog.md |
Records the deployment incident and remediation. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
The wrapper is the lock's only owner, because its command runs with the descriptor closed. A SIGTERM to the wrapper alone freed the lock while the deploy carried on, so another deploy could start on top of it. The command now runs in the background with stdin passed explicitly. TERM, INT and HUP are forwarded to it, and the wrapper waits until it has really exited, returning its status. SIGKILL remains the one gap. Five new self-test cases: a TERM-ignoring child keeps the lock held, the wrapper returns the child's status, the lock frees after, TERM reaches an ordinary child, and stdin still arrives. Reverting to the foreground run fails the first two. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # docs/changelog.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Why
On 2026-10-07 two sessions deployed the observability stack from the deployment checkout on
prometheuseighteen seconds apart: amake upat 15:41:49 UTC and amake convergeat 15:42:07. Both recreatedalertmanagerandblackbox-exporterat once. Compose renames a container to<id>_<name>while it replaces it, so the second run's recreate hit the first's temporary name (/ee680d332de7_alertmanager is already in use).check_mounted_config.pyfailed, and thatmake upexited 2 beforerecord-applied.shran. The first run happened to finish and record, so the host ended up fine, but nothing guaranteed it. The hourly converge timer and a handmake upcan collide the same way.What
scripts/deploy-lock.sh(new): a per-stackflockin the checkout's.git(git rev-parse --git-path homelab-deploy-<stack>.lock, besiderecord-applied.sh's record). Each checkout has its own, so a worktree never blocks the deployment checkout, and it never shows ingit status.deploy-lock.sh [--wait S] STACK -- CMD…, or sourced fordeploy_lock_acquire.pid,user,since,cmd) into the file, and--holder STACKprints it. The lock itself is theflock, not the text, so a holder that died leaves the lock free.flockit warns and runs unlocked, rather than turning a missing guard into an outage.make up: the existing recipe moves unchanged to an internal_up, rendering included.upruns it under the lock and waits up toHOMELAB_DEPLOY_LOCK_WAIT(900s), naming the holder.make helpstill lists onlyup.converge.sh: takes the lock right after its checkout preconditions and holds it from reading HEAD to recording. If another deploy still holds it afterHOMELAB_CONVERGE_LOCK_WAIT(600s), it logs "still held the deploy lock", exits 0 and records nothing. HEAD may be mid-move at that point, so anything it recorded would describe a deploy in progress; the next hourly run asks again. Its ownmake uppasses straight through viaHOMELAB_DEPLOY_LOCK_HELD, since a secondflockon the same file from the child would otherwise wait forever on its parent. The comment listing the guards that may exit before recording now names this one.docs/runbooks/converge-the-host.md, a row inscripts/README.md, and a changelog entry.Evidence
deploy-lock.sh --self-testpasses 17/17. It covers:timeout, so a regression fails rather than hangs);converge.sh --self-testpasses 95/95, after rebasing onto feat(converge): deploy the newest commit that passed CI, not only the tip (#1026) #1032, which changed converge. The new case, "leaves alone a stack another deploy holds the lock for", checks exit 0, the log line, and thatmakewas never reached. Mutation: withdeploy_lock_acquirereplaced bytrue, that case fails (make reached).self-tests.sh --require-all: 854 fixtures across 47 suites (46 before this, since discovery found the new suite).make -n upreaches the real recipe through the lock.make helpshowsupand not_up.validate.shpasses, with the 4 usual worktree-only skips.lint.sh(pinned ruff and ansible-lint via pipx) passes, as docheck_docs.pyandshellcheck -x.Not exercised: a real concurrent
make upagainst the live stack. Running one from a worktree would recreate production containers. After merge, the converge journal will show the lock is invisible on an uncontended run, anddeploy-lock.sh --holder observabilityreads empty between deploys.🤖 Generated with Claude Code