chore(selfhost): deduplicate the Docker prune scripts - #2721
Conversation
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
gittensory-ui | 69cb9fc | Commit Preview URL Branch Preview URL |
Jul 03 2026, 09:12 AM |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2721 +/- ##
==========================================
+ Coverage 96.01% 96.03% +0.02%
==========================================
Files 244 245 +1
Lines 27300 27340 +40
Branches 9919 9930 +11
==========================================
+ Hits 26211 26255 +44
+ Misses 462 460 -2
+ Partials 627 625 -2 🚀 New features to boost your workflow:
|
|
Warning 🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨 ⏸️ Gittensory review result - manual review recommendedReview updated: 2026-07-03 09:33:46 UTC
⏸️ Suggested Action - Manual Review
Review summary Nits — 6 non-blocking
Review context
Contributor next steps
Signal definitions
🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed 💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →. Checked by Gittensory, a quiet PR intelligence layer for OSS maintainers.
|
scripts/docker-prune.sh and scripts/selfhost-docker-prune.sh accidentally shipped from two separate PRs and did overlapping jobs. Keeps the systemd-timer-integrated, docs-referenced, tested one (selfhost-docker-prune.sh) as the single canonical script and folds in the genuinely useful behavior the other had: - Stopped-container pruning (docker container prune), age-filtered the same way images/build cache already were. - An opt-in --dry-run preview mode that reports disk usage without deleting anything; the systemd timer's zero-argument default call still prunes for real, unchanged. - A root filesystem usage report (df -h /) alongside docker system df. - A docker-on-PATH presence check. Removes scripts/docker-prune.sh and repoints every reference to it (docker-compose.yml, docker-compose.override.yml.example, .env.example) at the canonical script. Also documents the existing GITTENSORY_DOCKER_PRUNE_RETAIN_HOURS env var in .env.example, which was missing before.
…tion time Docker's `container prune --filter until=<n>h` filters by creation time, not stop time, so a long-lived container stopped moments ago was already eligible for deletion on the very next scheduled run. prune_stopped_containers() now inspects each exited container's State.FinishedAt directly, comparing it against a cutoff computed from epoch arithmetic and formatted portably for both GNU and BusyBox date, so only containers actually stopped for at least RETAIN_HOURS are ever removed.
1993433 to
69cb9fc
Compare
Summary
Two Docker-prune scripts had accidentally accumulated at
scripts/from two separate PRs, doing overlapping jobs:scripts/selfhost-docker-prune.sh(PR chore(selfhost): automate Docker disk hygiene for the self-host stack #2576) — the canonical one: systemd-timer-integrated (systemd/gittensory-docker-prune.{service,timer}.example), documented in the self-hosting operations docs, and covered bytest/unit/selfhost-docker-prune-script.test.ts. Age-filtered (GITTENSORY_DOCKER_PRUNE_RETAIN_HOURS, default 7 days) so nothing built/pulled recently is touched.scripts/docker-prune.sh(PR feat(selfhost): defer maintenance work under runtime pressure #2717) — added without noticing the above already existed. Manual/compose-oriented, dry-run-by-default, not referenced by any docs, no dedicated test.This PR keeps the canonical script and folds in the genuinely useful behavior the other one had, then deletes it:
docker container prune), age-filtered the same way images/build cache already were — a real capability gap the canonical script was missing.--dry-runpreview mode that reports disk usage without deleting anything. The systemd timer's zero-argument default call is unchanged — it still prunes for real, so this is purely additive for manual/interactive use.df -h /) alongside the existingdocker system df.docker-on-PATH presence check before doing anything.Also fixes every reference to the deleted script name (
docker-compose.yml,docker-compose.override.yml.example,.env.example) to point atscripts/selfhost-docker-prune.sh, and documents the previously-undocumentedGITTENSORY_DOCKER_PRUNE_RETAIN_HOURSenv var in.env.example.Why this isn't a behavior change for existing deployments
The systemd timer already installed on any self-host box calls
sh scripts/selfhost-docker-prune.shwith zero arguments — that exact invocation's behavior (age-filtered image + build-cache pruning) is unchanged. The new container-pruning step and--dry-runflag are additive; nothing about the default unattended run regressed.Validation
docker compose --profile runners -f docker-compose.yml config --quiet(also with every profile active)npm run typecheckshellcheck scripts/selfhost-docker-prune.sh— cleantest/unit/selfhost-docker-prune-script.test.ts(3 → 6 cases): stopped-container pruning,--dry-runissues no destructive call and never touches volumes,--dry-runstill honors the retain-hours env var, and an unrecognized argument is rejected rather than silently ignored.npm run test:ci(full local gate) — 7113 tests passed, fully green.npm audit --audit-level=moderate— 0 vulnerabilities.apps/gittensory-ui/src/lib/selfhost-env-reference.ts(npm run selfhost:env-reference) — picked up unrelated line-number drift from a recently-merged PR, included here since the check requires it to be current.src/**files touched; the changed/extended shell script and test live underscripts/**/test/**, both Codecov-ignored percodecov.yml, but the extended test suite still gives real regression coverage for every new behavior.