@astrofoundry/pi-astro 0.37.3 → 0.37.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/skills/arcane/SKILL.md +3 -3
- package/specialists/arcane/run.ts +74 -21
- package/specialists/lib/arcane-host.test.ts +4 -1
- package/specialists/lib/arcane-manager.ts +8 -0
- package/specialists/lib/image-updates.test.ts +3 -1
- package/specialists/lib/image-updates.ts +11 -0
- package/specialists/lib/stack-update.test.ts +11 -2
- package/specialists/lib/stack-update.ts +9 -0
package/package.json
CHANGED
package/skills/arcane/SKILL.md
CHANGED
|
@@ -44,9 +44,9 @@ Messages that start with "Arcane Daily Report:" are the bridge's scheduled repor
|
|
|
44
44
|
|
|
45
45
|
Apply updates only when asked, one stack at a time, with `["stack-update", "<stack>"]`. It applies every pending update of the stack in one call, without judgment:
|
|
46
46
|
|
|
47
|
-
- Pinned tags (`edit tag`) and digests (`edit digest`) move in the stack's Compose file through the GitOps checkout: commit, push, then a wait of up to 20 minutes for
|
|
48
|
-
- `projects redeploy <stack> --yes` then pulls and restarts the stack (up to 35 minutes for large pulls).
|
|
49
|
-
- Checks: every service has a container that runs (a one-shot job may have exited 0), none is unhealthy or still starting after 5 minutes, and a fresh check finds every updated image current.
|
|
47
|
+
- Pinned tags (`edit tag`) and digests (`edit digest`) move in the stack's Compose file through the GitOps checkout: commit, push, start the stack's GitOps sync at once (`gitops sync`, so a long sync interval does not matter), then a wait of up to 20 minutes for it to report success at that commit. Only `image:` lines that name exactly the old reference change.
|
|
48
|
+
- `projects redeploy <stack> --yes` then pulls and restarts the stack (up to 35 minutes for large pulls). Arcane can leave a running container on its old image although the pull moved its tag (Docker then lists it by image id); each such container is recreated with `containers redeploy <id>` and named in `recreated`.
|
|
49
|
+
- Checks: every service has a container that runs (a one-shot job may have exited 0), found through its Compose project, none still runs an older image than its tag, none is unhealthy or still starting after 5 minutes, and a fresh check finds every updated image current.
|
|
50
50
|
- A failed check after a Compose change reverts the commit, pushes, waits for the sync, and redeploys the previous file. A pull alone cannot be undone; say so when it fails.
|
|
51
51
|
|
|
52
52
|
The answer is JSON with `status`: `updated`, `rolled back`, `failed` (with `reason`), or `nothing to do`, plus `services` (`service`, `from`, `to`, `applied`: `pull` or the new reference, `result`: `current`, `behind`, `unchecked`) and `commit`/`revert` when the Compose file changed. Report it in plain words.
|
|
@@ -4,21 +4,21 @@ import { tmpdir } from "node:os";
|
|
|
4
4
|
import { dirname, join } from "node:path";
|
|
5
5
|
import { buildHostRemote, compareAudit, HOST_COMMANDS, type AuditFile } from "../lib/arcane-host.ts";
|
|
6
6
|
import { type CommitVersion, coveringOperation, judgeChange, parseChangeQuery, readTail } from "../lib/change-origin.ts";
|
|
7
|
-
import { failedChecks, MANAGER_COMPOSE, MANAGER_IMAGE, normalizeVersion, olderThan, pinCompose, projectSync, syncReady, utcStamp, type VerifyCheck } from "../lib/arcane-manager.ts";
|
|
7
|
+
import { failedChecks, MANAGER_COMPOSE, MANAGER_IMAGE, normalizeVersion, olderThan, pinCompose, projectSync, syncId, syncReady, utcStamp, type VerifyCheck } from "../lib/arcane-manager.ts";
|
|
8
8
|
import { readConfig } from "../lib/config.ts";
|
|
9
9
|
import { isRecent, listContainer, type WatchedContainer, withDetail } from "../lib/container-watch.ts";
|
|
10
10
|
import { containerFacts, deploymentChecks, listRows, parseDeploymentArgs, syncFacts, type DeploymentExpectation } from "../lib/deployment.ts";
|
|
11
11
|
import { ServiceError, UsageError } from "../lib/errors.ts";
|
|
12
12
|
import { withLock } from "../lib/lock.ts";
|
|
13
13
|
import { main } from "../lib/main.ts";
|
|
14
|
-
import { buildUpdateReport, parseTag, resolveRef, stackServices, type CheckEntry, type UpdateRow } from "../lib/image-updates.ts";
|
|
14
|
+
import { buildUpdateReport, checkEntries, parseTag, rateLimited, resolveRef, stackServices, type CheckEntry, type UpdateRow } from "../lib/image-updates.ts";
|
|
15
15
|
import { printJson, printRaw } from "../lib/output.ts";
|
|
16
16
|
import { auditLogPath, specialistsHome } from "../lib/paths.ts";
|
|
17
17
|
import { run, type RunResult } from "../lib/proc.ts";
|
|
18
18
|
import { HttpRegistry, parseImageRef } from "../lib/registry.ts";
|
|
19
19
|
import { releaseNotesFor } from "../lib/releases.ts";
|
|
20
20
|
import { ensureCheckout, git, REPO_HELP, repoCommand, repoStatus, safeRepoPath, type RepoSpec } from "../lib/repo.ts";
|
|
21
|
-
import { commitMessage, containersProblem, crossesMajor, HOLDS_FILE, nextImageRef, parseHolds, pendingRows, replaceImageRef, type ServiceResult, type StackContainer, type StackStatus } from "../lib/stack-update.ts";
|
|
21
|
+
import { commitMessage, containersProblem, crossesMajor, HOLDS_FILE, isStaleImage, nextImageRef, parseHolds, pendingRows, replaceImageRef, type ServiceResult, type StackContainer, type StackStatus } from "../lib/stack-update.ts";
|
|
22
22
|
import { ARCANE_DENIED_KEYS, filterJsonText, stripKeys } from "../lib/sanitize.ts";
|
|
23
23
|
import { readSecret, secretPath } from "../lib/secrets.ts";
|
|
24
24
|
import { sshFixed } from "../lib/ssh.ts";
|
|
@@ -104,11 +104,13 @@ ${Object.entries(HOST_COMMANDS)
|
|
|
104
104
|
.join("\n")}
|
|
105
105
|
update-report [--all] fresh image update check for every stack, with running and latest release versions
|
|
106
106
|
from the registries; JSON with a ready table (--all also lists up-to-date services) and
|
|
107
|
-
the held stacks of ${HOLDS_FILE}.
|
|
107
|
+
the held stacks of ${HOLDS_FILE}. Images the registry throttled (toomanyrequests) are
|
|
108
|
+
checked again after 5 and 20 seconds. Checks only: never pulls images or redeploys.
|
|
108
109
|
stack-update <stack> [--confirm]
|
|
109
110
|
apply every pending update of one stack: pinned tags and digests move in the stack's
|
|
110
|
-
Compose file (commit, push, wait for
|
|
111
|
-
|
|
111
|
+
Compose file (commit, push, start the sync and wait for it), then the stack is redeployed
|
|
112
|
+
with a pull, containers the redeploy left on an old image are recreated one by one, and
|
|
113
|
+
the stack is checked (containers running and healthy, images current). A failed check after a
|
|
112
114
|
Compose change reverts it and redeploys; a pull alone cannot be undone. Refuses held
|
|
113
115
|
stacks, stopped stacks, and arcane (manager-upgrade). An update across a major version
|
|
114
116
|
needs --confirm, which asks an owner for approval.
|
|
@@ -216,6 +218,9 @@ async function cliJson(cli: Cli, args: string[]): Promise<unknown> {
|
|
|
216
218
|
}
|
|
217
219
|
}
|
|
218
220
|
|
|
221
|
+
/** Pauses before each new check of the images the registry throttled. */
|
|
222
|
+
const THROTTLE_RETRY_WAITS_MS = [5000, 20000];
|
|
223
|
+
|
|
219
224
|
/** A fresh registry check first, then the stack list, so every result the report uses is from this run. */
|
|
220
225
|
async function updateReport(config: ArcaneConfig, args: string[]): Promise<number> {
|
|
221
226
|
const extra = args.filter((a) => a !== "--all");
|
|
@@ -223,7 +228,17 @@ async function updateReport(config: ArcaneConfig, args: string[]): Promise<numbe
|
|
|
223
228
|
const startedAt = Date.now();
|
|
224
229
|
const holds = await holdsFromOrigin(config);
|
|
225
230
|
return withCli(config, async (cli) => {
|
|
226
|
-
const check = await cliJson(cli, ["images", "updates", "check", "--all"]);
|
|
231
|
+
const check = checkEntries(await cliJson(cli, ["images", "updates", "check", "--all"]));
|
|
232
|
+
for (const wait of THROTTLE_RETRY_WAITS_MS) {
|
|
233
|
+
const limited = rateLimited(check);
|
|
234
|
+
if (limited.length === 0) break;
|
|
235
|
+
await new Promise((r) => setTimeout(r, wait));
|
|
236
|
+
for (const ref of limited) {
|
|
237
|
+
// A retry that fails again keeps the throttled entry for the next round or the report.
|
|
238
|
+
const again = await cliJson(cli, ["images", "updates", "check", ref]).catch(() => null);
|
|
239
|
+
if (again && typeof again === "object" && "hasUpdate" in again) check[ref] = again as CheckEntry;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
227
242
|
const projects = await cliJson(cli, ["projects", "list", "--all"]);
|
|
228
243
|
const report = await buildUpdateReport({ check, projects, registry: new HttpRegistry(), startedAt, all: args.includes("--all") });
|
|
229
244
|
printJson({ ...report, holds: holds.holds, ...(holds.error ? { holdsError: holds.error } : {}) });
|
|
@@ -588,6 +603,8 @@ async function managerRollback(args: string[]): Promise<number> {
|
|
|
588
603
|
const STACK_SYNC_WAIT_MS = 20 * MINUTE;
|
|
589
604
|
/** arcane-cli allows a project redeploy up to 30 minutes for large pulls. */
|
|
590
605
|
const REDEPLOY_TIMEOUT_MS = 35 * MINUTE;
|
|
606
|
+
/** `gitops sync` answers once the files are copied, about a minute even with a pre-deploy hook. */
|
|
607
|
+
const SYNC_START_TIMEOUT_MS = 10 * MINUTE;
|
|
591
608
|
/** Containers with a health check get this long to leave "starting". */
|
|
592
609
|
const HEALTH_WAIT_MS = 5 * MINUTE;
|
|
593
610
|
|
|
@@ -620,22 +637,58 @@ async function stackState(cli: Cli, stack: string, startedAt: number): Promise<S
|
|
|
620
637
|
return { rows, services: services.length, stopped: services.some((s) => s.stopped), composePath };
|
|
621
638
|
}
|
|
622
639
|
|
|
623
|
-
/**
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
640
|
+
/**
|
|
641
|
+
* The stack's containers as `containers get` reports them, kept when Compose
|
|
642
|
+
* says they belong to it. Candidates are the containers listed with one of the
|
|
643
|
+
* stack's image references, or with a bare image id: Docker shows that once a
|
|
644
|
+
* pull moved the container's tag to a newer image it does not run.
|
|
645
|
+
*/
|
|
646
|
+
async function stackContainers(cli: Cli, stack: string, refs: readonly string[]): Promise<(StackContainer & { id: string })[]> {
|
|
647
|
+
const listed = listRows(await cliJson(cli, ["containers", "list", "--all"])).filter((c) => (typeof c.image === "string" && refs.includes(c.image)) || isStaleImage(c.image));
|
|
648
|
+
const out: (StackContainer & { id: string })[] = [];
|
|
627
649
|
for (const c of listed) {
|
|
628
650
|
if (typeof c.id !== "string") continue;
|
|
629
651
|
const name = Array.isArray(c.names) && typeof c.names[0] === "string" ? c.names[0].replace(/^\//, "") : c.id.slice(0, 12);
|
|
630
652
|
const facts = containerFacts(await cliJson(cli, ["containers", "get", c.id]), name);
|
|
631
|
-
if (facts.project === stack) out.push({ name, running: facts.running, state: facts.state, exitCode: facts.exitCode, health: facts.health });
|
|
653
|
+
if (facts.project === stack) out.push({ id: c.id, name, running: facts.running, state: facts.state, exitCode: facts.exitCode, health: facts.health, stale: isStaleImage(c.image) });
|
|
632
654
|
}
|
|
633
655
|
return out;
|
|
634
656
|
}
|
|
635
657
|
|
|
636
|
-
|
|
658
|
+
async function stackRefs(cli: Cli, stack: string): Promise<string[]> {
|
|
659
|
+
return stackServices(await cliJson(cli, ["projects", "list", "--all"]))
|
|
660
|
+
.filter((s) => s.stack === stack)
|
|
661
|
+
.map((s) => s.ref)
|
|
662
|
+
.filter((r): r is string => r !== null);
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
/**
|
|
666
|
+
* Arcane's project redeploy can leave a running container on its old image
|
|
667
|
+
* although the pull moved its tag (paperless-db and paperless-redis on
|
|
668
|
+
* 2026-10-22). Arcane's container redeploy pulls and recreates that one
|
|
669
|
+
* container through Compose; returns the names it recreated, or the error.
|
|
670
|
+
*/
|
|
671
|
+
async function recreateStale(config: ArcaneConfig, stack: string): Promise<{ recreated: string[]; problem: string | null }> {
|
|
672
|
+
return withCli(config, async (cli) => {
|
|
673
|
+
const stale = (await stackContainers(cli, stack, await stackRefs(cli, stack))).filter((c) => c.running === true && c.stale);
|
|
674
|
+
const recreated: string[] = [];
|
|
675
|
+
for (const c of stale) {
|
|
676
|
+
const result = await cli(["containers", "redeploy", c.id], REDEPLOY_TIMEOUT_MS);
|
|
677
|
+
if (result.code !== 0) return { recreated, problem: `redeploy of ${c.name} failed: ${(result.stderr.trim().split("\n").pop() ?? "").slice(0, 200) || `exited ${result.code}`}` };
|
|
678
|
+
recreated.push(c.name);
|
|
679
|
+
}
|
|
680
|
+
return { recreated, problem: null };
|
|
681
|
+
});
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
/**
|
|
685
|
+
* Starts the stack's sync at once, so its interval (hourly for profiles) does
|
|
686
|
+
* not matter, then waits until it reports success at `commit`; false when it
|
|
687
|
+
* does not within the limit. A failed start leaves the scheduled sync to it.
|
|
688
|
+
*/
|
|
637
689
|
async function waitForSync(config: ArcaneConfig, stack: string, commit: string): Promise<{ ok: boolean; last: string }> {
|
|
638
690
|
const deadline = Date.now() + STACK_SYNC_WAIT_MS;
|
|
691
|
+
await withCli(config, async (cli) => cli(["gitops", "sync", syncId(await cliJson(cli, ["projects", "list", "--all"]), await cliJson(cli, ["gitops", "list", "--all"]), stack)], SYNC_START_TIMEOUT_MS)).catch(() => undefined);
|
|
639
692
|
for (;;) {
|
|
640
693
|
const sync = await withCli(config, async (cli) => projectSync(await cliJson(cli, ["projects", "list", "--all"]), await cliJson(cli, ["gitops", "list", "--all"]), stack));
|
|
641
694
|
const sameCommit = sync.commit !== null && (commit.startsWith(sync.commit) || sync.commit.startsWith(commit));
|
|
@@ -654,13 +707,7 @@ async function redeploy(config: ArcaneConfig, stack: string): Promise<string | n
|
|
|
654
707
|
async function settle(config: ArcaneConfig, stack: string, services: number): Promise<string | null> {
|
|
655
708
|
const deadline = Date.now() + HEALTH_WAIT_MS;
|
|
656
709
|
for (;;) {
|
|
657
|
-
const problem = await withCli(config, async (cli) =>
|
|
658
|
-
const refs = stackServices(await cliJson(cli, ["projects", "list", "--all"]))
|
|
659
|
-
.filter((s) => s.stack === stack)
|
|
660
|
-
.map((s) => s.ref)
|
|
661
|
-
.filter((r): r is string => r !== null);
|
|
662
|
-
return containersProblem(await stackContainers(cli, stack, refs), services);
|
|
663
|
-
});
|
|
710
|
+
const problem = await withCli(config, async (cli) => containersProblem(await stackContainers(cli, stack, await stackRefs(cli, stack)), services));
|
|
664
711
|
if (problem === null || Date.now() > deadline) return problem;
|
|
665
712
|
await new Promise((r) => setTimeout(r, 15_000));
|
|
666
713
|
}
|
|
@@ -726,6 +773,12 @@ async function stackUpdate(config: ArcaneConfig, args: string[]): Promise<number
|
|
|
726
773
|
}
|
|
727
774
|
|
|
728
775
|
let problem = await redeploy(config, stack);
|
|
776
|
+
let recreated: string[] = [];
|
|
777
|
+
if (problem === null) {
|
|
778
|
+
const stale = await recreateStale(config, stack);
|
|
779
|
+
recreated = stale.recreated;
|
|
780
|
+
problem = stale.problem;
|
|
781
|
+
}
|
|
729
782
|
if (problem === null) problem = await settle(config, stack, before.services);
|
|
730
783
|
if (problem === null) {
|
|
731
784
|
const after = await withCli(config, (cli) => stackState(cli, stack, Date.now()));
|
|
@@ -738,7 +791,7 @@ async function stackUpdate(config: ArcaneConfig, args: string[]): Promise<number
|
|
|
738
791
|
if (behind.length > 0) problem = `still behind after the redeploy: ${behind.join(", ")}`;
|
|
739
792
|
}
|
|
740
793
|
if (problem === null) {
|
|
741
|
-
answer("updated", { services: results, ...(commit ? { commit } : {}) });
|
|
794
|
+
answer("updated", { services: results, ...(commit ? { commit } : {}), ...(recreated.length > 0 ? { recreated } : {}) });
|
|
742
795
|
return 0;
|
|
743
796
|
}
|
|
744
797
|
if (commit === null) {
|
|
@@ -4,7 +4,7 @@ import { tmpdir } from "node:os";
|
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import { afterEach, describe, expect, it } from "vitest";
|
|
6
6
|
import { buildHostRemote, compareAudit, HOST_COMMANDS } from "./arcane-host.ts";
|
|
7
|
-
import { failedChecks, normalizeVersion, olderThan, pinCompose, pinnedDigest, projectSync, syncReady, utcStamp } from "./arcane-manager.ts";
|
|
7
|
+
import { failedChecks, normalizeVersion, olderThan, pinCompose, pinnedDigest, projectSync, syncId, syncReady, utcStamp } from "./arcane-manager.ts";
|
|
8
8
|
import { containerFacts, deploymentChecks, listRows, parseDeploymentArgs, syncFacts } from "./deployment.ts";
|
|
9
9
|
import { UsageError } from "./errors.ts";
|
|
10
10
|
|
|
@@ -130,6 +130,9 @@ describe("manager upgrade helpers", () => {
|
|
|
130
130
|
expect(syncReady({ ...sync, status: "success" }, "abc1234def", "x", "y")).toBe(false);
|
|
131
131
|
expect(syncReady({ ...sync, status: "success", commit: "fff0000" }, "abc1234def", "x", "x")).toBe(false);
|
|
132
132
|
expect(() => projectSync(projects, { data: [] }, "arcane")).toThrow(UsageError);
|
|
133
|
+
expect(syncId(projects, { data: [{ id: "s1", projectId: "p1" }] }, "arcane")).toBe("s1");
|
|
134
|
+
expect(() => syncId(projects, { data: [{ id: "s1", projectId: "p1" }, { id: "s2", projectId: "p1" }] }, "arcane")).toThrow(UsageError);
|
|
135
|
+
expect(() => syncId(projects, syncs, "other")).toThrow(UsageError);
|
|
133
136
|
expect(failedChecks([{ check: "version", ok: false, observed: "2.16.1" }, { check: "digest", ok: true }])).toBe('version ("2.16.1")');
|
|
134
137
|
});
|
|
135
138
|
});
|
|
@@ -56,6 +56,14 @@ export function projectSync(projects: unknown, syncs: unknown, name: string): Sy
|
|
|
56
56
|
return { status: text(s.lastSyncStatus), commit: text(s.lastSyncCommit), at: text(s.lastSyncAt) };
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
/** The id of the project's one GitOps sync, for `gitops sync <id>`. */
|
|
60
|
+
export function syncId(projects: unknown, syncs: unknown, name: string): string {
|
|
61
|
+
const project = listRows(projects).filter((p) => p.name === name);
|
|
62
|
+
const mine = project.length === 1 ? listRows(syncs).filter((s) => s.projectId === project[0].id) : [];
|
|
63
|
+
if (mine.length !== 1 || typeof mine[0].id !== "string") throw new UsageError(`project ${name} needs exactly one GitOps sync`);
|
|
64
|
+
return mine[0].id;
|
|
65
|
+
}
|
|
66
|
+
|
|
59
67
|
/**
|
|
60
68
|
* Ready for the host step when the sync reports success at the pin commit and
|
|
61
69
|
* the deployed Compose file is the committed one. A sync that copied the file
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { buildUpdateReport, cachingRegistry, checkEntries, classify, compareVersions, parseTag, releaseCandidates, resolveRef, stackServices, type CheckEntry } from "./image-updates.ts";
|
|
2
|
+
import { buildUpdateReport, cachingRegistry, checkEntries, classify, compareVersions, parseTag, rateLimited, releaseCandidates, resolveRef, stackServices, type CheckEntry } from "./image-updates.ts";
|
|
3
3
|
import { HttpRegistry, nextLink, parseChallenge, parseImageRef, RegistryError, type ImageRef, type Registry } from "./registry.ts";
|
|
4
4
|
import { capTotal, condenseNotes, githubRepo, releaseNotesFor, releasesBetween, type GithubRelease } from "./releases.ts";
|
|
5
5
|
|
|
@@ -160,6 +160,8 @@ describe("buildUpdateReport", () => {
|
|
|
160
160
|
it("reads Arcane's envelopes", () => {
|
|
161
161
|
expect(Object.keys(checkEntries({ data: { "a:1": { hasUpdate: false } } }))).toEqual(["a:1"]);
|
|
162
162
|
expect(Object.keys(checkEntries({ "a:1": { hasUpdate: true }, success: true }))).toEqual(["a:1"]);
|
|
163
|
+
const throttled = "distribution inspect of lscr.io/linuxserver/sonarr:latest failed: Error response from daemon: toomanyrequests: retry-after: 1.24222ms, allowed: 44000/minute";
|
|
164
|
+
expect(rateLimited({ "lscr.io/linuxserver/sonarr:latest": { hasUpdate: false, error: throttled }, "b:1": { hasUpdate: false, error: "manifest unknown" }, "c:1": { hasUpdate: true } })).toEqual(["lscr.io/linuxserver/sonarr:latest"]);
|
|
163
165
|
expect(stackServices({ data: "nope" })).toEqual([]);
|
|
164
166
|
});
|
|
165
167
|
});
|
|
@@ -276,6 +276,17 @@ export function checkEntries(raw: unknown): Record<string, CheckEntry> {
|
|
|
276
276
|
return out;
|
|
277
277
|
}
|
|
278
278
|
|
|
279
|
+
/**
|
|
280
|
+
* Images whose check the registry throttled. lscr.io answers bursts with
|
|
281
|
+
* `toomanyrequests` and a retry-after of a millisecond or two, more often when
|
|
282
|
+
* our check overlaps Arcane's hourly one; a single check a little later passes.
|
|
283
|
+
*/
|
|
284
|
+
export function rateLimited(entries: Record<string, CheckEntry>): string[] {
|
|
285
|
+
return Object.entries(entries)
|
|
286
|
+
.filter(([, e]) => typeof e.error === "string" && /toomanyrequests/i.test(e.error))
|
|
287
|
+
.map(([ref]) => ref);
|
|
288
|
+
}
|
|
289
|
+
|
|
279
290
|
interface StackService {
|
|
280
291
|
stack: string;
|
|
281
292
|
service: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
2
|
import type { UpdateRow } from "./image-updates.ts";
|
|
3
|
-
import { commitMessage, containersProblem, crossesMajor, nextImageRef, parseHolds, pendingRows, replaceImageRef, type StackContainer } from "./stack-update.ts";
|
|
3
|
+
import { commitMessage, containersProblem, crossesMajor, isStaleImage, nextImageRef, parseHolds, pendingRows, replaceImageRef, type StackContainer } from "./stack-update.ts";
|
|
4
4
|
|
|
5
5
|
const A = `sha256:${"a".repeat(64)}`;
|
|
6
6
|
const B = `sha256:${"b".repeat(64)}`;
|
|
@@ -80,7 +80,7 @@ describe("Compose rewrite", () => {
|
|
|
80
80
|
});
|
|
81
81
|
|
|
82
82
|
describe("stack health after a redeploy", () => {
|
|
83
|
-
const up = (name: string, over: Partial<StackContainer> = {}): StackContainer => ({ name, running: true, state: "running", exitCode: null, health: "healthy", ...over });
|
|
83
|
+
const up = (name: string, over: Partial<StackContainer> = {}): StackContainer => ({ name, running: true, state: "running", exitCode: null, health: "healthy", stale: false, ...over });
|
|
84
84
|
|
|
85
85
|
it("passes running containers and finished one-shot jobs", () => {
|
|
86
86
|
expect(containersProblem([up("db"), up("app", { health: "none" }), up("init", { running: false, state: "exited", exitCode: 0 })], 3)).toBeNull();
|
|
@@ -91,6 +91,15 @@ describe("stack health after a redeploy", () => {
|
|
|
91
91
|
expect(containersProblem([up("db"), up("init", { running: false, state: "exited", exitCode: 1 })], 2)).toBe("not running: init");
|
|
92
92
|
expect(containersProblem([up("db", { health: "unhealthy" }), up("app", { health: "starting" })], 2)).toBe("health: db (unhealthy), app (starting)");
|
|
93
93
|
});
|
|
94
|
+
|
|
95
|
+
it("names running containers left on an older image than their tag, not finished jobs", () => {
|
|
96
|
+
expect(containersProblem([up("db", { stale: true }), up("redis", { stale: true }), up("app")], 3)).toBe("still on an older image than its tag: db, redis");
|
|
97
|
+
expect(containersProblem([up("init", { running: false, state: "exited", exitCode: 0, stale: true })], 1)).toBeNull();
|
|
98
|
+
expect(isStaleImage(A)).toBe(true);
|
|
99
|
+
expect(isStaleImage("postgres:18")).toBe(false);
|
|
100
|
+
expect(isStaleImage(`postgres@${A}`)).toBe(false);
|
|
101
|
+
expect(isStaleImage(undefined)).toBe(false);
|
|
102
|
+
});
|
|
94
103
|
});
|
|
95
104
|
|
|
96
105
|
describe("commit message", () => {
|
|
@@ -95,6 +95,13 @@ export interface StackContainer {
|
|
|
95
95
|
state: string | null;
|
|
96
96
|
exitCode: number | null;
|
|
97
97
|
health: string;
|
|
98
|
+
/** Docker lists the container by image id: its Compose tag now names a newer image that it does not run. */
|
|
99
|
+
stale: boolean;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** A container's listed image is a bare id once its tag moved to another image. */
|
|
103
|
+
export function isStaleImage(image: unknown): boolean {
|
|
104
|
+
return typeof image === "string" && /^sha256:[0-9a-f]{64}$/.test(image);
|
|
98
105
|
}
|
|
99
106
|
|
|
100
107
|
/**
|
|
@@ -105,6 +112,8 @@ export function containersProblem(containers: readonly StackContainer[], expecte
|
|
|
105
112
|
if (containers.length < expected) return `${containers.length} of ${expected} services have a container`;
|
|
106
113
|
const down = containers.filter((c) => c.running !== true && !(c.state === "exited" && c.exitCode === 0)).map((c) => c.name);
|
|
107
114
|
if (down.length > 0) return `not running: ${down.join(", ")}`;
|
|
115
|
+
const old = containers.filter((c) => c.running === true && c.stale).map((c) => c.name);
|
|
116
|
+
if (old.length > 0) return `still on an older image than its tag: ${old.join(", ")}`;
|
|
108
117
|
const sick = containers.filter((c) => c.health === "unhealthy" || c.health === "starting").map((c) => `${c.name} (${c.health})`);
|
|
109
118
|
return sick.length > 0 ? `health: ${sick.join(", ")}` : null;
|
|
110
119
|
}
|