@celilo/cli 0.11.0-alpha.0 → 0.12.0
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/AGENTS.md +7 -4
- package/CELILO_CORE_MODULES.md +7 -6
- package/CELILO_SUBSYSTEMS.md +47 -5
- package/MODULE_PRIMITIVES.md +164 -0
- package/README.md +5 -5
- package/drizzle/0015_port_forwards.sql +12 -0
- package/drizzle/meta/_journal.json +7 -0
- package/package.json +8 -8
- package/schemas/system_config.json +1 -1
- package/src/ansible/inventory.test.ts +1 -1
- package/src/ansible/inventory.ts +3 -3
- package/src/capabilities/public-web-publish.test.ts +209 -0
- package/src/capabilities/validation.test.ts +1 -1
- package/src/capabilities/well-known.test.ts +1 -1
- package/src/capabilities/well-known.ts +2 -2
- package/src/cli/commands/api.ts +1 -1
- package/src/cli/commands/backup-pull.ts +1 -1
- package/src/cli/commands/events.ts +1 -1
- package/src/cli/commands/module-changeset.ts +1 -1
- package/src/cli/commands/module-import.ts +1 -1
- package/src/cli/commands/module-publish.ts +1 -1
- package/src/cli/commands/module-remove.ts +26 -1
- package/src/cli/commands/module-types.ts +1 -1
- package/src/cli/commands/module-upgrade.ts +1 -1
- package/src/cli/commands/module-version.ts +1 -1
- package/src/cli/commands/module-where.test.ts +26 -0
- package/src/cli/commands/module-where.ts +130 -0
- package/src/cli/commands/proxmox-node-list.ts +1 -1
- package/src/cli/commands/publish/alpha.test.ts +1 -1
- package/src/cli/commands/publish/alpha.ts +3 -3
- package/src/cli/commands/publish/changesets.ts +1 -1
- package/src/cli/commands/publish/global-install.ts +6 -2
- package/src/cli/commands/publish/helpers.ts +21 -14
- package/src/cli/commands/publish/index.ts +4 -4
- package/src/cli/commands/publish/plan.ts +3 -3
- package/src/cli/commands/publish/preflight.ts +2 -2
- package/src/cli/commands/publish/types.ts +2 -2
- package/src/cli/commands/publish/workspace.test.ts +1 -1
- package/src/cli/commands/publish/workspace.ts +2 -2
- package/src/cli/commands/registry-owner.test.ts +166 -0
- package/src/cli/commands/registry-owner.ts +124 -0
- package/src/cli/commands/registry-token.test.ts +109 -0
- package/src/cli/commands/registry-token.ts +194 -0
- package/src/cli/commands/restore.ts +1 -1
- package/src/cli/commands/service-add-proxmox.ts +1 -1
- package/src/cli/commands/subscribers-list.ts +1 -1
- package/src/cli/commands/system-apply-config-equivalence.test.ts +1 -1
- package/src/cli/commands/system-apply-config.ts +1 -1
- package/src/cli/commands/system-init-deprecation.test.ts +1 -1
- package/src/cli/commands/system-init.ts +2 -2
- package/src/cli/commands/token.test.ts +26 -0
- package/src/cli/commands/token.ts +160 -0
- package/src/cli/completion.ts +19 -0
- package/src/cli/index.ts +155 -4
- package/src/cli/restore-command.test.ts +1 -1
- package/src/db/client.ts +1 -1
- package/src/db/schema.ts +50 -7
- package/src/hooks/capability-loader-firewall.test.ts +4 -3
- package/src/hooks/capability-loader.ts +100 -10
- package/src/hooks/define-hook.test.ts +24 -0
- package/src/hooks/executor.test.ts +1 -1
- package/src/hooks/executor.ts +2 -2
- package/src/hooks/types.ts +1 -1
- package/src/manifest/contracts/v1.ts +2 -2
- package/src/manifest/schema.ts +13 -13
- package/src/manifest/template-validator.ts +1 -1
- package/src/module/packaging/build.ts +19 -0
- package/src/module/packaging/workspace-deps.test.ts +94 -0
- package/src/module/packaging/workspace-deps.ts +185 -0
- package/src/module/versioning/changeset-version.ts +1 -1
- package/src/policy/no-hand-built-ssh.test.ts +90 -0
- package/src/registry/client.test.ts +86 -0
- package/src/registry/client.ts +67 -1
- package/src/services/api-access.ts +1 -1
- package/src/services/aspect-approvals.ts +1 -1
- package/src/services/aspect-runner.ts +3 -3
- package/src/services/aspect-template-resolver.test.ts +1 -1
- package/src/services/aspect-template-resolver.ts +1 -1
- package/src/services/build-bus/delivery-events.ts +1 -1
- package/src/services/build-bus/fan-out.ts +1 -1
- package/src/services/build-bus/hook-dispatch.ts +1 -1
- package/src/services/build-bus/receiver-server.ts +1 -1
- package/src/services/build-bus/status.test.ts +1 -1
- package/src/services/build-bus/status.ts +1 -1
- package/src/services/build-bus/subscriber-store.ts +1 -1
- package/src/services/bus-interview.ts +1 -1
- package/src/services/celilo-events.ts +1 -1
- package/src/services/celilo-mgmt-hooks.test.ts +1 -1
- package/src/services/cross-module-read.ts +1 -1
- package/src/services/deploy-posture.ts +1 -1
- package/src/services/deployed-systems.test.ts +1 -1
- package/src/services/deployed-systems.ts +4 -4
- package/src/services/dns-provider-backfill.ts +2 -2
- package/src/services/events-daemon.ts +1 -1
- package/src/services/machine-pool.ts +3 -3
- package/src/services/module-deploy.ts +93 -8
- package/src/services/module-subscriptions.ts +1 -1
- package/src/services/module-types-generator.ts +1 -1
- package/src/services/module-validator/git-hygiene.ts +1 -1
- package/src/services/port-forwards.test.ts +92 -0
- package/src/services/port-forwards.ts +86 -0
- package/src/services/proxmox-reconcile.ts +2 -2
- package/src/services/public-web-republish.test.ts +189 -0
- package/src/services/public-web-republish.ts +84 -0
- package/src/services/restore-from-file.ts +1 -1
- package/src/services/restore-preflight.ts +1 -1
- package/src/services/system-identity.ts +1 -1
- package/src/services/system-init.test.ts +2 -2
- package/src/services/system-init.ts +2 -2
- package/src/services/web-route-cleanup.test.ts +250 -0
- package/src/services/web-route-cleanup.ts +144 -0
- package/src/templates/generator.ts +2 -2
- package/src/types/infrastructure.ts +1 -1
- package/src/variables/computed/computed-integration.test.ts +1 -1
- package/src/variables/computed/evaluate.ts +1 -1
- package/src/variables/computed/parse.ts +1 -1
- package/src/variables/context.test.ts +1 -1
- package/src/variables/context.ts +5 -5
- package/src/variables/lxc-nameserver.test.ts +1 -1
- package/src/variables/resolver.ts +2 -2
- package/src/variables/types.ts +1 -1
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it } from 'bun:test';
|
|
2
|
+
import { mkdtempSync, rmSync } from 'node:fs';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import type { PortForwardStore } from '@celilo/capabilities';
|
|
6
|
+
import type { DbClient } from '../db/client';
|
|
7
|
+
import { setupTestDatabase } from '../test-utils/setup-test-db';
|
|
8
|
+
import { buildPortForwardStore } from './port-forwards';
|
|
9
|
+
|
|
10
|
+
const FW = '192.168.0.254';
|
|
11
|
+
|
|
12
|
+
describe('port-forward store', () => {
|
|
13
|
+
let dir: string;
|
|
14
|
+
let db: DbClient;
|
|
15
|
+
let store: PortForwardStore;
|
|
16
|
+
|
|
17
|
+
beforeEach(async () => {
|
|
18
|
+
dir = mkdtempSync(join(tmpdir(), 'pf-'));
|
|
19
|
+
const dbPath = join(dir, 'celilo.db');
|
|
20
|
+
process.env.CELILO_DB_PATH = dbPath;
|
|
21
|
+
db = await setupTestDatabase(dbPath);
|
|
22
|
+
store = buildPortForwardStore(db);
|
|
23
|
+
});
|
|
24
|
+
afterEach(() => {
|
|
25
|
+
db.$client.close();
|
|
26
|
+
process.env.CELILO_DB_PATH = undefined;
|
|
27
|
+
try {
|
|
28
|
+
rmSync(dir, { recursive: true, force: true });
|
|
29
|
+
} catch {
|
|
30
|
+
/* ignore */
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('adds and lists forwards for a firewall', () => {
|
|
35
|
+
store.add(FW, { internalIp: '10.0.20.5', port: 443, protocol: 'TCP', description: 'caddy' });
|
|
36
|
+
store.add(FW, {
|
|
37
|
+
internalIp: '10.0.20.42',
|
|
38
|
+
port: 2222,
|
|
39
|
+
protocol: 'TCP',
|
|
40
|
+
description: 'forgejo',
|
|
41
|
+
});
|
|
42
|
+
const forwards = store.list(FW);
|
|
43
|
+
expect(forwards).toHaveLength(2);
|
|
44
|
+
expect(forwards.map((f) => f.port).sort((a, b) => a - b)).toEqual([443, 2222]);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('add is an idempotent upsert — same tuple → one row, description updated', () => {
|
|
48
|
+
store.add(FW, { internalIp: '10.0.20.5', port: 443, protocol: 'TCP', description: 'v1' });
|
|
49
|
+
store.add(FW, { internalIp: '10.0.20.5', port: 443, protocol: 'TCP', description: 'v2' });
|
|
50
|
+
const forwards = store.list(FW);
|
|
51
|
+
expect(forwards).toHaveLength(1);
|
|
52
|
+
expect(forwards[0].description).toBe('v2');
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('scopes forwards by firewallIp', () => {
|
|
56
|
+
store.add(FW, { internalIp: '10.0.20.5', port: 443, protocol: 'TCP', description: 'a' });
|
|
57
|
+
store.add('10.0.30.254', {
|
|
58
|
+
internalIp: '10.0.30.5',
|
|
59
|
+
port: 53,
|
|
60
|
+
protocol: 'UDP',
|
|
61
|
+
description: 'b',
|
|
62
|
+
});
|
|
63
|
+
expect(store.list(FW)).toHaveLength(1);
|
|
64
|
+
expect(store.list('10.0.30.254')).toHaveLength(1);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('remove deletes exactly the tuple and leaves others', () => {
|
|
68
|
+
store.add(FW, { internalIp: '10.0.20.5', port: 443, protocol: 'TCP', description: 'x' });
|
|
69
|
+
store.add(FW, { internalIp: '10.0.20.5', port: 80, protocol: 'TCP', description: 'y' });
|
|
70
|
+
store.remove(FW, '10.0.20.5', 443, 'TCP');
|
|
71
|
+
const forwards = store.list(FW);
|
|
72
|
+
expect(forwards).toHaveLength(1);
|
|
73
|
+
expect(forwards[0].port).toBe(80);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('ingressIp forwards are distinct from the public (NULL) ones', () => {
|
|
77
|
+
store.add(FW, { internalIp: '10.0.20.5', port: 53, protocol: 'UDP', description: 'public' });
|
|
78
|
+
store.add(FW, {
|
|
79
|
+
internalIp: '10.0.20.5',
|
|
80
|
+
port: 53,
|
|
81
|
+
protocol: 'UDP',
|
|
82
|
+
ingressIp: '10.0.10.53',
|
|
83
|
+
description: 'ingress',
|
|
84
|
+
});
|
|
85
|
+
expect(store.list(FW)).toHaveLength(2);
|
|
86
|
+
// removing the public (NULL-ingress) one leaves the ingress one intact
|
|
87
|
+
store.remove(FW, '10.0.20.5', 53, 'UDP');
|
|
88
|
+
const forwards = store.list(FW);
|
|
89
|
+
expect(forwards).toHaveLength(1);
|
|
90
|
+
expect(forwards[0].ingressIp).toBe('10.0.10.53');
|
|
91
|
+
});
|
|
92
|
+
});
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Port-forward registry — the DB-backed `PortForwardStore` (openspec/changes/unified-management-no-ssh/proposal.md).
|
|
3
|
+
*
|
|
4
|
+
* The shared-core desired-state store for the `firewall` capability. The
|
|
5
|
+
* capability-loader constructs one of these and injects it into the firewall
|
|
6
|
+
* provider factory, so `exposeService`/`unexposeService` become register/
|
|
7
|
+
* unregister and the provider's converge renders the complete ruleset from
|
|
8
|
+
* `list(firewallIp)` and applies it atomically (`iptables-restore`). Replaces
|
|
9
|
+
* "read the box back with `iptables -L`" as the source of truth.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import type { PortForward, PortForwardStore, Protocol } from '@celilo/capabilities';
|
|
13
|
+
import { and, eq, isNull } from 'drizzle-orm';
|
|
14
|
+
import type { DbClient } from '../db/client';
|
|
15
|
+
import { portForwards } from '../db/schema';
|
|
16
|
+
|
|
17
|
+
/** NULL-aware match on the optional ingress IP (SQLite treats NULL as distinct). */
|
|
18
|
+
function ingressMatch(ingressIp: string | undefined) {
|
|
19
|
+
return ingressIp ? eq(portForwards.ingressIp, ingressIp) : isNull(portForwards.ingressIp);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function buildPortForwardStore(db: DbClient): PortForwardStore {
|
|
23
|
+
return {
|
|
24
|
+
list(firewallIp: string): PortForward[] {
|
|
25
|
+
return db
|
|
26
|
+
.select()
|
|
27
|
+
.from(portForwards)
|
|
28
|
+
.where(eq(portForwards.firewallIp, firewallIp))
|
|
29
|
+
.all()
|
|
30
|
+
.map((r) => ({
|
|
31
|
+
internalIp: r.internalIp,
|
|
32
|
+
port: r.port,
|
|
33
|
+
protocol: r.protocol,
|
|
34
|
+
ingressIp: r.ingressIp ?? undefined,
|
|
35
|
+
description: r.description,
|
|
36
|
+
}));
|
|
37
|
+
},
|
|
38
|
+
|
|
39
|
+
add(firewallIp: string, forward: PortForward): void {
|
|
40
|
+
// Idempotent upsert: delete any existing row for this exact tuple, then
|
|
41
|
+
// insert. Matches buildRouteOps' delete-then-insert (keeps the operation
|
|
42
|
+
// atomic w.r.t. the unique index, and NULL-aware on ingress_ip).
|
|
43
|
+
db.delete(portForwards)
|
|
44
|
+
.where(
|
|
45
|
+
and(
|
|
46
|
+
eq(portForwards.firewallIp, firewallIp),
|
|
47
|
+
eq(portForwards.internalIp, forward.internalIp),
|
|
48
|
+
eq(portForwards.port, forward.port),
|
|
49
|
+
eq(portForwards.protocol, forward.protocol),
|
|
50
|
+
ingressMatch(forward.ingressIp),
|
|
51
|
+
),
|
|
52
|
+
)
|
|
53
|
+
.run();
|
|
54
|
+
db.insert(portForwards)
|
|
55
|
+
.values({
|
|
56
|
+
firewallIp,
|
|
57
|
+
internalIp: forward.internalIp,
|
|
58
|
+
port: forward.port,
|
|
59
|
+
protocol: forward.protocol,
|
|
60
|
+
ingressIp: forward.ingressIp ?? null,
|
|
61
|
+
description: forward.description,
|
|
62
|
+
})
|
|
63
|
+
.run();
|
|
64
|
+
},
|
|
65
|
+
|
|
66
|
+
remove(
|
|
67
|
+
firewallIp: string,
|
|
68
|
+
internalIp: string,
|
|
69
|
+
port: number,
|
|
70
|
+
protocol: Protocol,
|
|
71
|
+
ingressIp?: string,
|
|
72
|
+
): void {
|
|
73
|
+
db.delete(portForwards)
|
|
74
|
+
.where(
|
|
75
|
+
and(
|
|
76
|
+
eq(portForwards.firewallIp, firewallIp),
|
|
77
|
+
eq(portForwards.internalIp, internalIp),
|
|
78
|
+
eq(portForwards.port, port),
|
|
79
|
+
eq(portForwards.protocol, protocol),
|
|
80
|
+
ingressMatch(ingressIp),
|
|
81
|
+
),
|
|
82
|
+
)
|
|
83
|
+
.run();
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Proxmox reconciliation (
|
|
2
|
+
* Proxmox reconciliation (openspec/specs/base-module-aspects/spec.md D5).
|
|
3
3
|
*
|
|
4
4
|
* When a base-module aspect declares `proxmox_reconcile.tfvars` and
|
|
5
5
|
* its fan-out plan touches Proxmox-provisioned LXCs, the running
|
|
@@ -151,6 +151,6 @@ export function executeProxmoxReconcile(plan: ProxmoxReconcilePlan): void {
|
|
|
151
151
|
);
|
|
152
152
|
}
|
|
153
153
|
log.warn(
|
|
154
|
-
'To persist these values, re-deploy the owning modules after the underlying celilo state catches up. Tracked as Phase 1c in
|
|
154
|
+
'To persist these values, re-deploy the owning modules after the underlying celilo state catches up. Tracked as Phase 1c in openspec/specs/base-module-aspects/spec.md.',
|
|
155
155
|
);
|
|
156
156
|
}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, test } from 'bun:test';
|
|
2
|
+
import { mkdtempSync, rmSync } from 'node:fs';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import type { DbClient } from '../db/client';
|
|
6
|
+
import { modules, webRoutes } from '../db/schema';
|
|
7
|
+
import type { ModuleManifest } from '../manifest/schema';
|
|
8
|
+
import { setupTestDatabase } from '../test-utils/setup-test-db';
|
|
9
|
+
import { providesPublicWeb, republishStaticWebConsumers } from './public-web-republish';
|
|
10
|
+
|
|
11
|
+
const caddyManifest = {
|
|
12
|
+
provides: { capabilities: [{ name: 'public_web', version: '3.0.0' }] },
|
|
13
|
+
} as unknown as ModuleManifest;
|
|
14
|
+
|
|
15
|
+
const plainManifest = { provides: { capabilities: [] } } as unknown as ModuleManifest;
|
|
16
|
+
|
|
17
|
+
describe('republishStaticWebConsumers', () => {
|
|
18
|
+
let dir: string;
|
|
19
|
+
let db: DbClient;
|
|
20
|
+
|
|
21
|
+
function seedModule(id: string) {
|
|
22
|
+
db.insert(modules)
|
|
23
|
+
.values({ id, name: id, version: '1.0.0', manifestData: {}, sourcePath: `/tmp/${id}` })
|
|
24
|
+
.run();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function seedRoute(
|
|
28
|
+
moduleId: string,
|
|
29
|
+
slug: string,
|
|
30
|
+
path: string,
|
|
31
|
+
type: 'static' | 'reverse_proxy',
|
|
32
|
+
) {
|
|
33
|
+
db.insert(webRoutes)
|
|
34
|
+
.values({
|
|
35
|
+
slug,
|
|
36
|
+
moduleId,
|
|
37
|
+
type,
|
|
38
|
+
path,
|
|
39
|
+
hostname: 'iamtheinternet.org',
|
|
40
|
+
targetHost: type === 'reverse_proxy' ? '10.0.20.5' : null,
|
|
41
|
+
targetPort: type === 'reverse_proxy' ? 8080 : null,
|
|
42
|
+
})
|
|
43
|
+
.run();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function recordingHook(failFor: string[] = []) {
|
|
47
|
+
const calls: string[] = [];
|
|
48
|
+
const runHook = (async (moduleId: string) => {
|
|
49
|
+
calls.push(moduleId);
|
|
50
|
+
return failFor.includes(moduleId)
|
|
51
|
+
? { success: false, outputs: {}, error: 'boom', duration: 1 }
|
|
52
|
+
: { success: true, outputs: {}, duration: 1 };
|
|
53
|
+
}) as unknown as Parameters<typeof republishStaticWebConsumers>[0]['runHook'];
|
|
54
|
+
return { runHook, calls };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
beforeEach(async () => {
|
|
58
|
+
dir = mkdtempSync(join(tmpdir(), 'pwr-'));
|
|
59
|
+
const dbPath = join(dir, 'celilo.db');
|
|
60
|
+
process.env.CELILO_DB_PATH = dbPath;
|
|
61
|
+
db = await setupTestDatabase(dbPath);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
afterEach(() => {
|
|
65
|
+
db.$client.close();
|
|
66
|
+
process.env.CELILO_DB_PATH = undefined;
|
|
67
|
+
try {
|
|
68
|
+
rmSync(dir, { recursive: true, force: true });
|
|
69
|
+
} catch {
|
|
70
|
+
/* ignore */
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test('providesPublicWeb reads the manifest', () => {
|
|
75
|
+
expect(providesPublicWeb(caddyManifest)).toBe(true);
|
|
76
|
+
expect(providesPublicWeb(plainManifest)).toBe(false);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test('does not run for a module that is not a public_web provider', async () => {
|
|
80
|
+
seedModule('hello-foo');
|
|
81
|
+
seedRoute('hello-foo', 'foo', '/foo', 'static');
|
|
82
|
+
const { runHook, calls } = recordingHook();
|
|
83
|
+
|
|
84
|
+
const result = await republishStaticWebConsumers({
|
|
85
|
+
providerModuleId: 'namecheap',
|
|
86
|
+
manifest: plainManifest,
|
|
87
|
+
db,
|
|
88
|
+
runHook,
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
expect(result).toEqual({ ran: false, republished: [], failures: [] });
|
|
92
|
+
expect(calls).toEqual([]);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
test('re-runs on_install for every static consumer', async () => {
|
|
96
|
+
seedModule('caddy');
|
|
97
|
+
seedModule('hello-foo');
|
|
98
|
+
seedModule('hello-bar');
|
|
99
|
+
seedModule('celilo-website');
|
|
100
|
+
seedRoute('hello-foo', 'foo', '/foo', 'static');
|
|
101
|
+
seedRoute('hello-bar', 'bar', '/bar', 'static');
|
|
102
|
+
seedRoute('celilo-website', 'celilo-website', '/', 'static');
|
|
103
|
+
const { runHook, calls } = recordingHook();
|
|
104
|
+
|
|
105
|
+
const result = await republishStaticWebConsumers({
|
|
106
|
+
providerModuleId: 'caddy',
|
|
107
|
+
manifest: caddyManifest,
|
|
108
|
+
db,
|
|
109
|
+
runHook,
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
expect(result.ran).toBe(true);
|
|
113
|
+
expect(calls.sort()).toEqual(['celilo-website', 'hello-bar', 'hello-foo']);
|
|
114
|
+
expect(result.republished.sort()).toEqual(['celilo-website', 'hello-bar', 'hello-foo']);
|
|
115
|
+
expect(result.failures).toEqual([]);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test('skips reverse-proxy-only consumers (no assets on the provider host)', async () => {
|
|
119
|
+
seedModule('caddy');
|
|
120
|
+
seedModule('forgejo');
|
|
121
|
+
seedModule('hello-foo');
|
|
122
|
+
seedRoute('forgejo', 'git', '/git', 'reverse_proxy');
|
|
123
|
+
seedRoute('hello-foo', 'foo', '/foo', 'static');
|
|
124
|
+
const { runHook, calls } = recordingHook();
|
|
125
|
+
|
|
126
|
+
await republishStaticWebConsumers({
|
|
127
|
+
providerModuleId: 'caddy',
|
|
128
|
+
manifest: caddyManifest,
|
|
129
|
+
db,
|
|
130
|
+
runHook,
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
expect(calls).toEqual(['hello-foo']);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
test('never re-runs the provider itself', async () => {
|
|
137
|
+
seedModule('caddy');
|
|
138
|
+
// A provider that also owns a static route (a landing page of its own).
|
|
139
|
+
seedRoute('caddy', 'caddy', '/', 'static');
|
|
140
|
+
const { runHook, calls } = recordingHook();
|
|
141
|
+
|
|
142
|
+
const result = await republishStaticWebConsumers({
|
|
143
|
+
providerModuleId: 'caddy',
|
|
144
|
+
manifest: caddyManifest,
|
|
145
|
+
db,
|
|
146
|
+
runHook,
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
expect(calls).toEqual([]);
|
|
150
|
+
expect(result.republished).toEqual([]);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
test('de-duplicates a consumer that owns several static routes', async () => {
|
|
154
|
+
seedModule('caddy');
|
|
155
|
+
seedModule('hello-foo');
|
|
156
|
+
seedRoute('hello-foo', 'foo', '/foo', 'static');
|
|
157
|
+
seedRoute('hello-foo', 'foo-docs', '/foo/docs', 'static');
|
|
158
|
+
const { runHook, calls } = recordingHook();
|
|
159
|
+
|
|
160
|
+
await republishStaticWebConsumers({
|
|
161
|
+
providerModuleId: 'caddy',
|
|
162
|
+
manifest: caddyManifest,
|
|
163
|
+
db,
|
|
164
|
+
runHook,
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
expect(calls).toEqual(['hello-foo']);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
test('one consumer failing does not stop the others', async () => {
|
|
171
|
+
seedModule('caddy');
|
|
172
|
+
seedModule('hello-foo');
|
|
173
|
+
seedModule('hello-bar');
|
|
174
|
+
seedRoute('hello-foo', 'foo', '/foo', 'static');
|
|
175
|
+
seedRoute('hello-bar', 'bar', '/bar', 'static');
|
|
176
|
+
const { runHook, calls } = recordingHook(['hello-foo']);
|
|
177
|
+
|
|
178
|
+
const result = await republishStaticWebConsumers({
|
|
179
|
+
providerModuleId: 'caddy',
|
|
180
|
+
manifest: caddyManifest,
|
|
181
|
+
db,
|
|
182
|
+
runHook,
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
expect(calls.sort()).toEqual(['hello-bar', 'hello-foo']);
|
|
186
|
+
expect(result.republished).toEqual(['hello-bar']);
|
|
187
|
+
expect(result.failures).toEqual([{ moduleId: 'hello-foo', error: 'boom' }]);
|
|
188
|
+
});
|
|
189
|
+
});
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Restore consumer content after a public_web provider redeploy.
|
|
3
|
+
*
|
|
4
|
+
* A provider redeploy destroys the provider's host and rebuilds it, taking
|
|
5
|
+
* `/srv/www` with it. The consumers' `web_routes` rows survive — they belong to
|
|
6
|
+
* the consumer modules, not the provider — so the rebuilt provider renders
|
|
7
|
+
* `root * /srv/www/<slug>` for directories that no longer exist and every
|
|
8
|
+
* static site 404s. Nothing re-uploaded the assets; an operator had to redeploy
|
|
9
|
+
* each consumer by hand and there was no signal telling them to.
|
|
10
|
+
*
|
|
11
|
+
* The fix is to do exactly what that operator did: after a provider deploy
|
|
12
|
+
* lands, re-run `on_install` for every module holding a STATIC route.
|
|
13
|
+
* `publishStaticSite` is idempotent (it upserts the route and re-tars the
|
|
14
|
+
* source dir), so the re-run re-registers the route and refills the fresh
|
|
15
|
+
* `/srv/www/<slug>`.
|
|
16
|
+
*
|
|
17
|
+
* Reverse-proxy consumers are skipped: they keep no state on the provider host,
|
|
18
|
+
* so re-running them buys nothing and only widens the blast radius.
|
|
19
|
+
*
|
|
20
|
+
* ponytail: re-runs every static consumer unconditionally rather than probing
|
|
21
|
+
* which /srv/www/<slug> directories are actually missing — O(static consumers)
|
|
22
|
+
* per provider deploy, currently a handful. If a large fleet makes provider
|
|
23
|
+
* deploys slow, probe the provider host first and re-run only the misses.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import { eq } from 'drizzle-orm';
|
|
27
|
+
import type { DbClient } from '../db/client';
|
|
28
|
+
import { webRoutes } from '../db/schema';
|
|
29
|
+
import { createConsoleLogger } from '../hooks/logger';
|
|
30
|
+
import { runNamedHook } from '../hooks/run-named-hook';
|
|
31
|
+
import type { ModuleManifest } from '../manifest/schema';
|
|
32
|
+
|
|
33
|
+
export interface RepublishFailure {
|
|
34
|
+
moduleId: string;
|
|
35
|
+
error: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface RepublishResult {
|
|
39
|
+
/** False when the deployed module isn't a public_web provider. */
|
|
40
|
+
ran: boolean;
|
|
41
|
+
/** Consumer modules whose on_install was re-run successfully. */
|
|
42
|
+
republished: string[];
|
|
43
|
+
failures: RepublishFailure[];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function providesPublicWeb(manifest: ModuleManifest): boolean {
|
|
47
|
+
return (manifest.provides?.capabilities ?? []).some((c) => c.name === 'public_web');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface RepublishDeps {
|
|
51
|
+
providerModuleId: string;
|
|
52
|
+
manifest: ModuleManifest;
|
|
53
|
+
db: DbClient;
|
|
54
|
+
/** Injectable for tests. */
|
|
55
|
+
runHook?: typeof runNamedHook;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export async function republishStaticWebConsumers(deps: RepublishDeps): Promise<RepublishResult> {
|
|
59
|
+
const { providerModuleId, manifest, db, runHook = runNamedHook } = deps;
|
|
60
|
+
|
|
61
|
+
if (!providesPublicWeb(manifest)) {
|
|
62
|
+
return { ran: false, republished: [], failures: [] };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const staticRoutes = db.select().from(webRoutes).where(eq(webRoutes.type, 'static')).all();
|
|
66
|
+
const consumerIds = [
|
|
67
|
+
...new Set(staticRoutes.map((r) => r.moduleId).filter((id) => id !== providerModuleId)),
|
|
68
|
+
];
|
|
69
|
+
|
|
70
|
+
const republished: string[] = [];
|
|
71
|
+
const failures: RepublishFailure[] = [];
|
|
72
|
+
|
|
73
|
+
for (const moduleId of consumerIds) {
|
|
74
|
+
const logger = createConsoleLogger(moduleId, 'on_install');
|
|
75
|
+
const result = await runHook(moduleId, 'on_install', db, logger, {});
|
|
76
|
+
if (result.success) {
|
|
77
|
+
republished.push(moduleId);
|
|
78
|
+
} else {
|
|
79
|
+
failures.push({ moduleId, error: result.error ?? 'unknown error' });
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return { ran: true, republished, failures };
|
|
84
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* File-direct restore + system-file swap. Powers the `celilo restore`
|
|
3
|
-
* top-level convenience command (Phase 4 of
|
|
3
|
+
* top-level convenience command (Phase 4 of openspec/specs/management-server-backup/spec.md).
|
|
4
4
|
*
|
|
5
5
|
* The generic `restoreModuleBackup` reads from a configured storage
|
|
6
6
|
* destination — which on a fresh-bootstrap box doesn't exist yet.
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* Either signal is sufficient. Both are checked so a half-deployed
|
|
14
14
|
* target (DB cleared but disk artifacts left over) still gets caught.
|
|
15
15
|
*
|
|
16
|
-
* Phase 4 of
|
|
16
|
+
* Phase 4 of openspec/specs/management-server-backup/spec.md (Design Decision 9).
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
19
|
import { existsSync, readdirSync, statSync } from 'node:fs';
|
|
@@ -16,7 +16,7 @@ export interface SystemIdentity {
|
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Get a module's hostname and IP from its recorded deployed systems
|
|
19
|
-
* (
|
|
19
|
+
* (openspec/specs/module-systems-addressing/spec.md). Returns null for a module with no host
|
|
20
20
|
* (config-only providers like namecheap). Single-system modules have one; this
|
|
21
21
|
* returns the first (Phase C iterates all systems for per-system events).
|
|
22
22
|
*/
|
|
@@ -29,7 +29,7 @@ describe('System Init Service', () => {
|
|
|
29
29
|
// a zone address).
|
|
30
30
|
expect(defaults['network.bridge']).toBe('vmbr0');
|
|
31
31
|
// Network/DNS addressing is no longer defaulted
|
|
32
|
-
// (
|
|
32
|
+
// (openspec/specs/progressive-zone-disclosure/spec.md): internal is discovered at
|
|
33
33
|
// celilo-mgmt install; dmz/app/secure appear only when a firewall
|
|
34
34
|
// module provides them.
|
|
35
35
|
expect(defaults['network.dmz.subnet']).toBeUndefined();
|
|
@@ -184,7 +184,7 @@ describe('System Init Service', () => {
|
|
|
184
184
|
test('keys off the sentinel, not config rows', async () => {
|
|
185
185
|
// Config rows present but no sentinel → NOT initialized. Initialization
|
|
186
186
|
// is tracked by the explicit `system.initialized` marker
|
|
187
|
-
// (
|
|
187
|
+
// (openspec/specs/progressive-zone-disclosure/spec.md), not by any network row.
|
|
188
188
|
db.insert(systemConfig).values({ key: 'network.dmz.subnet', value: '10.0.0.0/24' }).run();
|
|
189
189
|
db.insert(systemConfig).values({ key: 'ssh.public_key', value: 'ssh-rsa AAAA...' }).run();
|
|
190
190
|
expect(isSystemInitialized(db)).toBe(false);
|
|
@@ -199,7 +199,7 @@ export function initializeSystem(
|
|
|
199
199
|
}
|
|
200
200
|
|
|
201
201
|
// Explicit init marker. Network/DNS addressing is no longer seeded with
|
|
202
|
-
// defaults (
|
|
202
|
+
// defaults (openspec/specs/progressive-zone-disclosure/spec.md), so we can't key
|
|
203
203
|
// "is this system initialized?" off a network row anymore. Write a
|
|
204
204
|
// dedicated sentinel instead. additionalProperties:true in the schema
|
|
205
205
|
// permits this non-schema key.
|
|
@@ -238,7 +238,7 @@ export function loadExistingConfiguration(db: DbClient): Record<string, string>
|
|
|
238
238
|
* Keys off the explicit `system.initialized` sentinel written by
|
|
239
239
|
* initializeSystem(). Earlier this checked for a seeded network zone
|
|
240
240
|
* subnet, but network/DNS addressing is no longer defaulted
|
|
241
|
-
* (
|
|
241
|
+
* (openspec/specs/progressive-zone-disclosure/spec.md), so a fresh init leaves those
|
|
242
242
|
* rows absent.
|
|
243
243
|
*
|
|
244
244
|
* @param db - Database instance
|