@wtfalch/foundry 0.16.7 → 0.16.8
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/dist/bootstrap/bootstrap.d.ts +2 -0
- package/dist/bootstrap/bootstrap.js +9 -1
- package/dist/bootstrap/declare.d.ts +1 -1
- package/dist/bootstrap/declare.js +7 -2
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/migrations/0036_applied_versions.sql +45 -0
- package/dist/migrations/0037_platform_server_ipv4.sql +8 -0
- package/dist/org.d.ts +39 -0
- package/dist/org.js +46 -1
- package/dist/plan/boule.d.ts +8 -2
- package/dist/plan/boule.js +10 -1
- package/dist/plan/diff.d.ts +2 -0
- package/dist/plan/diff.js +40 -5
- package/dist/plan/executor.d.ts +30 -6
- package/dist/plan/executor.js +86 -21
- package/dist/plan/plan-apply.d.ts +21 -1
- package/dist/plan/plan-apply.js +38 -3
- package/dist/plan/platform-diff.d.ts +5 -1
- package/dist/plan/platform-diff.js +17 -5
- package/dist/plan/platform-providers.d.ts +51 -1
- package/dist/plan/platform-providers.js +327 -52
- package/dist/platform.d.ts +11 -0
- package/dist/platform.js +5 -0
- package/dist/store/postgres.d.ts +9 -1
- package/dist/store/postgres.js +36 -2
- package/dist/store/schema.d.ts +134 -0
- package/dist/store/schema.js +15 -0
- package/dist/store.d.ts +37 -0
- package/package.json +1 -1
|
@@ -3,7 +3,7 @@ import type { DeclaredOrg, OrgId } from '../org.js';
|
|
|
3
3
|
import type { Plan, PlanStep } from '../plan.js';
|
|
4
4
|
import type { DeclaredPlatform } from '../platform.js';
|
|
5
5
|
import type { AppliedState } from '../state.js';
|
|
6
|
-
import type { DeclaredOrgStore, PlatformStore } from '../store.js';
|
|
6
|
+
import type { AppliedVersionsStore, DeclaredOrgStore, PlatformStore } from '../store.js';
|
|
7
7
|
import { type AgoraHostPort } from './agora.js';
|
|
8
8
|
import { type StepAction } from './diff.js';
|
|
9
9
|
import { type LiveReaders, type LiveResource, type PlatformLiveReaders } from './live.js';
|
|
@@ -204,6 +204,8 @@ export interface PlatformStepExecutor {
|
|
|
204
204
|
driftedSteps?(platform: DeclaredPlatform, recordedIds: Readonly<Record<string, string>>): Promise<{
|
|
205
205
|
archon?: boolean;
|
|
206
206
|
auth?: boolean;
|
|
207
|
+
/** #380: see `PlanPlatformOptions.drifted.files` (`platform-diff.ts`). */
|
|
208
|
+
files?: boolean;
|
|
207
209
|
backupStorage?: boolean;
|
|
208
210
|
/** #257 fix round 4: see `PlanPlatformOptions.drifted.backupStorageBlocked` (`platform-diff.ts`). */
|
|
209
211
|
backupStorageBlocked?: string;
|
|
@@ -315,6 +317,13 @@ export interface FoundryPlanApplyOptions {
|
|
|
315
317
|
aiOrganisation?: boolean;
|
|
316
318
|
/** Overridable for tests; defaults to `() => new Date()`. */
|
|
317
319
|
now?: () => Date;
|
|
320
|
+
/**
|
|
321
|
+
* #253: appends a history row every time `runSteps` records a new
|
|
322
|
+
* version as applied, beside the single-snapshot `store.putAppliedState`
|
|
323
|
+
* write that already happens there. Optional, and a no-op without it --
|
|
324
|
+
* every existing caller of this constructor is unaffected.
|
|
325
|
+
*/
|
|
326
|
+
appliedVersions?: AppliedVersionsStore;
|
|
318
327
|
/**
|
|
319
328
|
* #167: dependencies for planning/applying the shared platform (#166)
|
|
320
329
|
* alongside an org. Optional so an org-only caller — every #19-era caller,
|
|
@@ -364,6 +373,7 @@ export declare class FoundryPlanApply implements PlanApply {
|
|
|
364
373
|
private readonly hostFiles;
|
|
365
374
|
private readonly hostAi;
|
|
366
375
|
private readonly now;
|
|
376
|
+
private readonly appliedVersions;
|
|
367
377
|
private readonly platformDeps;
|
|
368
378
|
constructor(options: FoundryPlanApplyOptions);
|
|
369
379
|
plan(id: OrgId): Promise<Plan>;
|
|
@@ -422,6 +432,16 @@ export declare class FoundryPlanApply implements PlanApply {
|
|
|
422
432
|
* (perhaps not yet wired to this platform) keeps them.
|
|
423
433
|
*/
|
|
424
434
|
private orgAgoraHost;
|
|
435
|
+
/**
|
|
436
|
+
* #374: the Archon that bills every org, written into each Boule as
|
|
437
|
+
* `ARCHON_URL` -- `https://` plus the declared platform's `archon.hostname`
|
|
438
|
+
* (today `archon.companyincluded.com`), the same `platformDeps`
|
|
439
|
+
* {@link orgAgoraHost} reads. `null` with no platform declared, Archon not
|
|
440
|
+
* enabled, or Archon not yet applied -- the same `enabled && applied` gate
|
|
441
|
+
* {@link agoraHostValuesFromPlatform} uses for `issuer`, so a Boule never
|
|
442
|
+
* points at an Archon that is not live yet.
|
|
443
|
+
*/
|
|
444
|
+
private orgArchonUrl;
|
|
425
445
|
/** #167: `FoundryPlanApplyOptions.platform`, or a plain `Error` naming what's missing. */
|
|
426
446
|
private requirePlatformDeps;
|
|
427
447
|
private computeFreshPlatformPlan;
|
package/dist/plan/plan-apply.js
CHANGED
|
@@ -8,7 +8,7 @@ import { entryAiUndeliveredScopeKey } from './entry-ai-key.js';
|
|
|
8
8
|
import { FILES_ROOT_UNDELIVERED_SCOPE_KEY, entryFilesUndeliveredScopeKey, } from './entry-files-key.js';
|
|
9
9
|
import { readLivePlatformResources, readLiveResources, } from './live.js';
|
|
10
10
|
import { lockedHostnames } from './locked-hostnames.js';
|
|
11
|
-
import { planPlatform as computePlatformPlanDetail, toPlatformPlan, } from './platform-diff.js';
|
|
11
|
+
import { PLATFORM_ARCHON_KEY, planPlatform as computePlatformPlanDetail, toPlatformPlan, } from './platform-diff.js';
|
|
12
12
|
import { DEFAULT_ORG_PLATFORM_READINESS, ORG_PLATFORM_KEY_REFS, agoraHostValuesFromPlatform, heldPlatformKeyRefs, orgPlatformReadinessFrom, } from './platform-org.js';
|
|
13
13
|
export class DeclaredOrgNotFoundError extends Error {
|
|
14
14
|
constructor(orgId) {
|
|
@@ -98,6 +98,7 @@ export class FoundryPlanApply {
|
|
|
98
98
|
hostFiles;
|
|
99
99
|
hostAi;
|
|
100
100
|
now;
|
|
101
|
+
appliedVersions;
|
|
101
102
|
platformDeps;
|
|
102
103
|
constructor(options) {
|
|
103
104
|
this.store = options.store;
|
|
@@ -114,6 +115,7 @@ export class FoundryPlanApply {
|
|
|
114
115
|
this.hostFiles = options.filesOrganisation ?? false;
|
|
115
116
|
this.hostAi = options.aiOrganisation ?? false;
|
|
116
117
|
this.now = options.now ?? (() => new Date());
|
|
118
|
+
this.appliedVersions = options.appliedVersions;
|
|
117
119
|
this.platformDeps = options.platform;
|
|
118
120
|
}
|
|
119
121
|
async plan(id) {
|
|
@@ -344,14 +346,25 @@ export class FoundryPlanApply {
|
|
|
344
346
|
});
|
|
345
347
|
throw e;
|
|
346
348
|
}
|
|
349
|
+
const lastApplied = { at: this.now().toISOString(), declaredOrgVersion: hashOrg(org) };
|
|
347
350
|
const applied = {
|
|
348
351
|
orgId,
|
|
349
352
|
serviceIds,
|
|
350
353
|
checkpoints,
|
|
351
354
|
failedFields: failedFields(org, detail, detail.plannedSteps.length, serviceIds),
|
|
352
|
-
lastApplied
|
|
355
|
+
lastApplied,
|
|
353
356
|
};
|
|
354
357
|
await this.store.putAppliedState(applied);
|
|
358
|
+
// #253: the single-snapshot write just above replaces whatever
|
|
359
|
+
// `lastApplied` this org had; this is the point in today's code where a
|
|
360
|
+
// version is recorded as applied, so it's also where the appended
|
|
361
|
+
// history row goes. Optional, and a no-op without it, like every other
|
|
362
|
+
// host-supplied dependency on `FoundryPlanApplyOptions`.
|
|
363
|
+
await this.appliedVersions?.record({
|
|
364
|
+
service: orgId,
|
|
365
|
+
ref: lastApplied.declaredOrgVersion,
|
|
366
|
+
appliedAt: lastApplied.at,
|
|
367
|
+
});
|
|
355
368
|
await this.audit.recordApply({
|
|
356
369
|
actor: this.actor,
|
|
357
370
|
orgId,
|
|
@@ -365,11 +378,12 @@ export class FoundryPlanApply {
|
|
|
365
378
|
const org = await this.store.get(id);
|
|
366
379
|
if (!org)
|
|
367
380
|
throw new DeclaredOrgNotFoundError(id);
|
|
368
|
-
const [live, applied, platformReadiness, agoraHost] = await Promise.all([
|
|
381
|
+
const [live, applied, platformReadiness, agoraHost, archonUrl] = await Promise.all([
|
|
369
382
|
readLiveResources(id, this.readers),
|
|
370
383
|
this.store.getAppliedState(id),
|
|
371
384
|
this.orgPlatformReadiness(),
|
|
372
385
|
this.orgAgoraHost(id),
|
|
386
|
+
this.orgArchonUrl(),
|
|
373
387
|
]);
|
|
374
388
|
const otherSlugs = (await this.store.list()).filter((o) => o.id !== id).map((o) => o.slug);
|
|
375
389
|
const detail = computePlanDetail(org, live, applied?.serviceIds ?? {}, agoraHost, this.jobsScheduler, platformReadiness, {
|
|
@@ -377,6 +391,7 @@ export class FoundryPlanApply {
|
|
|
377
391
|
broker: this.broker,
|
|
378
392
|
otherSlugs,
|
|
379
393
|
now: () => this.now().getTime(),
|
|
394
|
+
archonUrl,
|
|
380
395
|
});
|
|
381
396
|
const invalid = await this.invalidHosting(org);
|
|
382
397
|
if (invalid) {
|
|
@@ -448,6 +463,26 @@ export class FoundryPlanApply {
|
|
|
448
463
|
const recorded = await this.platformDeps.store.getServiceIds();
|
|
449
464
|
return agoraHostValuesFromPlatform(platform, recorded);
|
|
450
465
|
}
|
|
466
|
+
/**
|
|
467
|
+
* #374: the Archon that bills every org, written into each Boule as
|
|
468
|
+
* `ARCHON_URL` -- `https://` plus the declared platform's `archon.hostname`
|
|
469
|
+
* (today `archon.companyincluded.com`), the same `platformDeps`
|
|
470
|
+
* {@link orgAgoraHost} reads. `null` with no platform declared, Archon not
|
|
471
|
+
* enabled, or Archon not yet applied -- the same `enabled && applied` gate
|
|
472
|
+
* {@link agoraHostValuesFromPlatform} uses for `issuer`, so a Boule never
|
|
473
|
+
* points at an Archon that is not live yet.
|
|
474
|
+
*/
|
|
475
|
+
async orgArchonUrl() {
|
|
476
|
+
if (!this.platformDeps)
|
|
477
|
+
return null;
|
|
478
|
+
const platform = await this.platformDeps.store.get();
|
|
479
|
+
if (!platform || !platform.archon.enabled)
|
|
480
|
+
return null;
|
|
481
|
+
const recorded = await this.platformDeps.store.getServiceIds();
|
|
482
|
+
if (!recorded[`coolify:app:${PLATFORM_ARCHON_KEY}`])
|
|
483
|
+
return null;
|
|
484
|
+
return `https://${platform.archon.hostname}`;
|
|
485
|
+
}
|
|
451
486
|
/** #167: `FoundryPlanApplyOptions.platform`, or a plain `Error` naming what's missing. */
|
|
452
487
|
requirePlatformDeps() {
|
|
453
488
|
if (!this.platformDeps) {
|
|
@@ -579,11 +579,15 @@ export interface PlanPlatformOptions {
|
|
|
579
579
|
* check itself failed (Coolify unreachable, credentials revoked) -- the
|
|
580
580
|
* plan is never failed over it, but it is reported in `unmanaged` rather
|
|
581
581
|
* than only logged, so a persistent failure is visible instead of silently
|
|
582
|
-
* retried forever.
|
|
582
|
+
* retried forever. `files` (#380): the runner's live env is missing a
|
|
583
|
+
* setting `ensureStarted()` requires -- see `filesRunnerEnvDrifted`
|
|
584
|
+
* (`platform-providers.ts`) -- which the recorded hostname/gitRef alone
|
|
585
|
+
* could never show.
|
|
583
586
|
*/
|
|
584
587
|
drifted?: {
|
|
585
588
|
archon?: boolean;
|
|
586
589
|
auth?: boolean;
|
|
590
|
+
files?: boolean;
|
|
587
591
|
backupStorage?: boolean;
|
|
588
592
|
backupStorageBlocked?: string;
|
|
589
593
|
};
|
|
@@ -625,7 +625,7 @@ export function planPlatform(platform, live, options = {}) {
|
|
|
625
625
|
// #171: after auth, so a first apply builds the sign-in the files step
|
|
626
626
|
// creates its ZITADEL project in before that step runs.
|
|
627
627
|
const authReady = auth.step !== null || Boolean(recordedIds[resourceKey('coolify', 'app', PLATFORM_AUTH_KEY)]);
|
|
628
|
-
const files = planFiles(platform, recordedIds, blocked.files, authReady);
|
|
628
|
+
const files = planFiles(platform, recordedIds, blocked.files, authReady, drifted.files);
|
|
629
629
|
if (files.step)
|
|
630
630
|
plannedSteps.push(files.step);
|
|
631
631
|
// #169: the platform's own mail server. After auth, because its OIDC
|
|
@@ -1392,12 +1392,18 @@ function planIntegrations(platform, recordedIds, executorBlocked) {
|
|
|
1392
1392
|
* `gitRef`, for the reason {@link planAuth} gives: no platform reader reports
|
|
1393
1393
|
* these resources, so a live check would replan the step forever. A changed
|
|
1394
1394
|
* hostname or `gitRef` plans the step again (a redeploy, no new secrets).
|
|
1395
|
+
* `drifted` (#380, `FoundryPlatformStepExecutor.driftedSteps`'s own live
|
|
1396
|
+
* check on the runner's env) replans it too, with neither changed: this is
|
|
1397
|
+
* how a setting {@link provisionPlatformFiles} only started setting after
|
|
1398
|
+
* the runner was already recorded applied -- `R2_BUCKET`, `R2_ENDPOINT` and
|
|
1399
|
+
* `KEYS_VERIFY_KEYS` among them -- ever reaches a runner that deployed
|
|
1400
|
+
* before.
|
|
1395
1401
|
*
|
|
1396
1402
|
* Blocked, not planned, while the platform's sign-in is neither recorded nor
|
|
1397
1403
|
* planned in this same plan: the step creates its ZITADEL project and client
|
|
1398
1404
|
* there, so it would throw on every apply.
|
|
1399
1405
|
*/
|
|
1400
|
-
function planFiles(platform, recordedIds, executorBlocked, authReady) {
|
|
1406
|
+
function planFiles(platform, recordedIds, executorBlocked, authReady, drifted) {
|
|
1401
1407
|
if (!platform.files.enabled)
|
|
1402
1408
|
return { step: null, blocked: null };
|
|
1403
1409
|
// A secret minted but never delivered and written is lost (the private key
|
|
@@ -1423,11 +1429,17 @@ function planFiles(platform, recordedIds, executorBlocked, authReady) {
|
|
|
1423
1429
|
};
|
|
1424
1430
|
}
|
|
1425
1431
|
}
|
|
1426
|
-
|
|
1432
|
+
const applied = Boolean(recordedIds[resourceKey('coolify', 'app', PLATFORM_FILES_KEY)]) &&
|
|
1427
1433
|
recordedIds[PLATFORM_FILES_APPLIED_HOSTNAME_SCOPE_KEY] === platform.files.hostname &&
|
|
1428
|
-
recordedIds[PLATFORM_FILES_APPLIED_GIT_REF_SCOPE_KEY] === platform.files.gitRef
|
|
1434
|
+
recordedIds[PLATFORM_FILES_APPLIED_GIT_REF_SCOPE_KEY] === platform.files.gitRef;
|
|
1435
|
+
// #380: applied is not enough on its own -- the runner's live env can be
|
|
1436
|
+
// missing a setting `ensureStarted()` requires (`driftedSteps`'s own
|
|
1437
|
+
// `filesRunnerEnvDrifted`), the exact gap that left the platform's own
|
|
1438
|
+
// files host recorded applied and `running:unhealthy` at once. Drifted
|
|
1439
|
+
// replans the step so `provisionPlatformFiles` (which redeploys
|
|
1440
|
+
// unconditionally on every run) fills in whatever is still missing.
|
|
1441
|
+
if (applied && !drifted)
|
|
1429
1442
|
return { step: null, blocked: null };
|
|
1430
|
-
}
|
|
1431
1443
|
if (executorBlocked)
|
|
1432
1444
|
return { step: null, blocked: executorBlocked };
|
|
1433
1445
|
if (!authReady) {
|
|
@@ -207,6 +207,7 @@ export declare class FoundryPlatformStepExecutor implements PlatformStepExecutor
|
|
|
207
207
|
driftedSteps(platform: DeclaredPlatform, recordedIds?: Readonly<Record<string, string>>): Promise<{
|
|
208
208
|
archon?: boolean;
|
|
209
209
|
auth?: boolean;
|
|
210
|
+
files?: boolean;
|
|
210
211
|
backupStorage?: boolean;
|
|
211
212
|
backupStorageBlocked?: string;
|
|
212
213
|
}>;
|
|
@@ -645,13 +646,62 @@ export interface PlatformFilesDeps {
|
|
|
645
646
|
* The keys worker the files host verifies and seals with, from the host's
|
|
646
647
|
* held keys (`KEYS_WORKER_URL`, `KEYS_CREDENTIAL`). The `files-migrate` app
|
|
647
648
|
* never becomes healthy without them, so the step sets both on both apps,
|
|
648
|
-
* and the executor reports the step blocked while
|
|
649
|
+
* and the executor reports the step blocked while either is unset. Never
|
|
649
650
|
* recorded or logged.
|
|
651
|
+
*
|
|
652
|
+
* #380: `verifyKeys` (`KEYS_VERIFY_KEYS`) is the same kind of requirement,
|
|
653
|
+
* but only on the `files` runner, not `files-migrate` -- the runner's own
|
|
654
|
+
* `ensureStarted()` (`apps/host/src/lib/authz/files-host.ts`) requires it
|
|
655
|
+
* with `requireEnv(...)` to build its keys issuer, and the step reports
|
|
656
|
+
* the whole thing blocked while it is unset, the same as a missing
|
|
657
|
+
* `workerUrl`/`credential`. `auditToken` (`KEYS_AUDIT_TOKEN`) is not: it
|
|
658
|
+
* gates only the keys repo's own reconcile job against
|
|
659
|
+
* `GET /v1/keys/audit`, so it is set on the runner only when supplied and
|
|
660
|
+
* never blocks the step.
|
|
650
661
|
*/
|
|
651
662
|
keys?: {
|
|
652
663
|
workerUrl: string;
|
|
653
664
|
credential: string;
|
|
665
|
+
verifyKeys?: string;
|
|
666
|
+
auditToken?: string;
|
|
654
667
|
};
|
|
668
|
+
/**
|
|
669
|
+
* #380: the object storage (Cloudflare R2) the `files` runner stores
|
|
670
|
+
* objects in -- `R2_BUCKET`/`R2_ENDPOINT`, both `required(...)` by
|
|
671
|
+
* `ensureStarted()`. The actual R2 access key and secret are not here:
|
|
672
|
+
* the host reads them back through the keys worker above at runtime
|
|
673
|
+
* (files' own `.env.example`), never a plaintext env var this step would
|
|
674
|
+
* set. Absent, the step reports the runner blocked the same way a
|
|
675
|
+
* missing `keys` already does -- issue #380's "Decide" leaves open
|
|
676
|
+
* whether foundry ever mints this bucket itself (today, only a host that
|
|
677
|
+
* already has one can supply it).
|
|
678
|
+
*/
|
|
679
|
+
r2?: {
|
|
680
|
+
bucket: string;
|
|
681
|
+
endpoint: string;
|
|
682
|
+
};
|
|
683
|
+
/**
|
|
684
|
+
* #380: `FILES_CLAMD_HOST`/`FILES_CLAMD_PORT` -- a clamd daemon reachable
|
|
685
|
+
* on the Coolify network. Optional: unset keeps files' own default
|
|
686
|
+
* (`confirm()` runs unscanned), and never blocks the step. Issue #380's
|
|
687
|
+
* "Decide" leaves open which clamd this should point at.
|
|
688
|
+
*/
|
|
689
|
+
clamd?: {
|
|
690
|
+
host: string;
|
|
691
|
+
port?: string;
|
|
692
|
+
};
|
|
693
|
+
/**
|
|
694
|
+
* #380: `FILES_PUBLIC_HOSTS`, the public share hosts this deployment
|
|
695
|
+
* answers on, comma-separated bare host names. Optional; unset keeps
|
|
696
|
+
* `/s/<token>` 404 everywhere, today's behaviour.
|
|
697
|
+
*/
|
|
698
|
+
publicHosts?: string;
|
|
699
|
+
/**
|
|
700
|
+
* #380: `JOBS_SIGNING_SECRETS`, the scheduled-jobs project's own HMAC
|
|
701
|
+
* secret(s), comma-separated, current first. Optional; unset keeps every
|
|
702
|
+
* `/api/jobs/*` route answering 503 `not_configured`, today's behaviour.
|
|
703
|
+
*/
|
|
704
|
+
jobsSigningSecrets?: string;
|
|
655
705
|
/** Clock and sleep for the migration wait and delivery retries; real ones by default. */
|
|
656
706
|
runtime?: PlatformFilesRuntime;
|
|
657
707
|
}
|