@specific.dev/spectest 0.92.1 → 0.93.1
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/README.md +7 -0
- package/dist/components/email.js +14 -39
- package/dist/components/index.d.ts +1 -1
- package/dist/components/k3s.d.ts +26 -4
- package/dist/components/k3s.js +105 -61
- package/dist/components/s3.js +2 -1
- package/dist/components/supabase.js +2 -1
- package/dist/daemon.js +3 -0
- package/dist/harness/built-image.d.ts +16 -0
- package/dist/harness/built-image.js +57 -0
- package/dist/harness/k3s-image-loader.js +2 -53
- package/dist/harness/registry-seed.d.ts +12 -0
- package/dist/harness/registry-seed.js +61 -0
- package/dist/index.d.ts +2 -1
- package/package.json +1 -1
- package/src/components/email.ts +12 -20
- package/src/components/index.ts +1 -0
- package/src/components/internal-fetch.test.ts +109 -0
- package/src/components/k3s-registry.test.ts +50 -0
- package/src/components/k3s.ts +114 -52
- package/src/components/s3.ts +2 -1
- package/src/components/supabase.ts +2 -1
- package/src/daemon.ts +3 -0
- package/src/harness/built-image.ts +53 -0
- package/src/harness/k3s-image-loader.ts +2 -47
- package/src/harness/registry-seed.test.ts +60 -0
- package/src/harness/registry-seed.ts +61 -0
- package/src/index.ts +2 -1
package/README.md
CHANGED
|
@@ -106,3 +106,10 @@ renderer DOM from acquisition onward, not native OS surfaces.
|
|
|
106
106
|
|
|
107
107
|
Run `spectest docs /components/electron` for the full configuration reference,
|
|
108
108
|
backend setup, session behavior, and replay scope (CLI 0.2.124 or later).
|
|
109
|
+
|
|
110
|
+
`k3s({ registry: { host: "registry.test" }, images: [...] })` exposes the
|
|
111
|
+
component's writable registry over verified HTTPS through the VM proxy.
|
|
112
|
+
Dockerfile builds in `images` targeting `registry.test/...` are published and
|
|
113
|
+
preloaded from the same cached build, preserving digests without an export/push
|
|
114
|
+
step. Other images keep direct preloading. Registry writes stay isolated across
|
|
115
|
+
test forks; client and containerd CA trust are configured automatically.
|
package/dist/components/email.js
CHANGED
|
@@ -1,22 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
// would in production; every message is captured instead of delivered.
|
|
4
|
-
// Tests read the mailbox through typed helpers on `ctx.svc.<key>`
|
|
5
|
-
// (`lastEmail`, `emails`, `clear`), each recorded as an `email` event on
|
|
6
|
-
// the test timeline — single-message ops embed the full captured message
|
|
7
|
-
// (HTML body included) so the dashboard renders the actual email the test
|
|
8
|
-
// asserted against, and returns come back inspect-wrapped so
|
|
9
|
-
// `expect(mail.subject)` links under the step. To wait for a message to
|
|
10
|
-
// *arrive*, use the standard `ctx.poll` with `lastEmail` as the predicate
|
|
11
|
-
// (it returns `undefined` while the mailbox is empty); the winning
|
|
12
|
-
// iteration's `email` event survives poll truncation, so the message still
|
|
13
|
-
// renders nested under the wait step.
|
|
14
|
-
//
|
|
15
|
-
// Captured mail lives in the server's process memory, so it snapshots and
|
|
16
|
-
// forks with the rest of the environment: a `dependsOn` child inherits the
|
|
17
|
-
// parent's mailbox, sibling forks never see each other's messages — the
|
|
18
|
-
// same isolation contract as fake state.
|
|
19
|
-
import { pauseRecording, recordEmail, reserveEvent, resumeRecording, truncateUtf8, } from "../recorder.js";
|
|
1
|
+
import { rawFetch } from "../harness/raw-fetch.js";
|
|
2
|
+
import { recordEmail, reserveEvent, truncateUtf8, } from "../recorder.js";
|
|
20
3
|
import { wrap } from "../inspect.js";
|
|
21
4
|
const DEFAULT_IMAGE = "axllent/mailpit:v1.30";
|
|
22
5
|
const SMTP_PORT = 1025;
|
|
@@ -140,29 +123,21 @@ async function instrumented(service, op, query, body) {
|
|
|
140
123
|
throw err;
|
|
141
124
|
}
|
|
142
125
|
}
|
|
143
|
-
/**
|
|
144
|
-
* so these internal polls don't land as `http` events on the timeline —
|
|
145
|
-
* the helper records one consolidated `email` event instead. */
|
|
126
|
+
/** Internal HTTP stays native; the public helper records one email event. */
|
|
146
127
|
async function api(base, path, init) {
|
|
147
|
-
|
|
128
|
+
const res = await rawFetch(`${base}${path}`, init);
|
|
129
|
+
if (!res.ok) {
|
|
130
|
+
throw new Error(`email server API ${path} failed: HTTP ${res.status}`);
|
|
131
|
+
}
|
|
132
|
+
const text = await res.text();
|
|
133
|
+
if (text === "")
|
|
134
|
+
return undefined;
|
|
148
135
|
try {
|
|
149
|
-
|
|
150
|
-
if (!res.ok) {
|
|
151
|
-
throw new Error(`email server API ${path} failed: HTTP ${res.status}`);
|
|
152
|
-
}
|
|
153
|
-
const text = await res.text();
|
|
154
|
-
if (text === "")
|
|
155
|
-
return undefined;
|
|
156
|
-
try {
|
|
157
|
-
return JSON.parse(text);
|
|
158
|
-
}
|
|
159
|
-
catch {
|
|
160
|
-
// Mutating endpoints reply with a plain-text acknowledgement.
|
|
161
|
-
return text;
|
|
162
|
-
}
|
|
136
|
+
return JSON.parse(text);
|
|
163
137
|
}
|
|
164
|
-
|
|
165
|
-
|
|
138
|
+
catch {
|
|
139
|
+
// Mutating endpoints reply with a plain-text acknowledgement.
|
|
140
|
+
return text;
|
|
166
141
|
}
|
|
167
142
|
}
|
|
168
143
|
function addresses(v) {
|
|
@@ -2,7 +2,7 @@ export { temporal, temporalClient, type TemporalOptions, type TemporalClient, ty
|
|
|
2
2
|
export { postgres, type PostgresOptions, type PostgresHelpers, } from "./postgres.js";
|
|
3
3
|
export { s3, type S3Options, type S3Helpers, } from "./s3.js";
|
|
4
4
|
export { SQL, type SqlClient, type SqlOptions } from "../sql.js";
|
|
5
|
-
export { k3s, type K3sOptions, type KubernetesImage, type K3sHelpers, type K3sClient, type TaggedObjectApi, type KubernetesObjectRef, type ApplyOptions, type RolloutTarget, type WaitOptions, type LogsOptions, type KubernetesObject, type KubernetesListObject, } from "./k3s.js";
|
|
5
|
+
export { k3s, type K3sOptions, type K3sRegistryOptions, type KubernetesImage, type K3sHelpers, type K3sClient, type TaggedObjectApi, type KubernetesObjectRef, type ApplyOptions, type RolloutTarget, type WaitOptions, type LogsOptions, type KubernetesObject, type KubernetesListObject, } from "./k3s.js";
|
|
6
6
|
export { expo, type ExpoOptions, type ExpoHelpers, type ExpoPackageManager, } from "./expo.js";
|
|
7
7
|
export { supabase, type SupabaseOptions, type SupabaseHelpers, type SupabaseStack, } from "./supabase.js";
|
|
8
8
|
export { email, type EmailOptions, type EmailHelpers, type EmailMessage, type EmailSummary, type EmailMatch, type EmailAttachment, } from "./email.js";
|
package/dist/components/k3s.d.ts
CHANGED
|
@@ -4,6 +4,14 @@ import { type KubernetesImage } from "../harness/component-images.js";
|
|
|
4
4
|
export type { KubernetesImage } from "../harness/component-images.js";
|
|
5
5
|
import type { Wrapped } from "../inspect.js";
|
|
6
6
|
export type { KubernetesObject, KubernetesListObject, } from "@kubernetes/client-node";
|
|
7
|
+
/** HTTPS exposure and publication for the component's writable registry. */
|
|
8
|
+
export interface K3sRegistryOptions {
|
|
9
|
+
/** Exact DNS hostname exposed through Spectest's VM HTTPS proxy on port 443.
|
|
10
|
+
* Clients and Kubernetes's containerd trust the environment CA automatically.
|
|
11
|
+
* Builds in `images` whose reference starts with this host are also published
|
|
12
|
+
* here, using their original cached blobs and manifest digests. */
|
|
13
|
+
host: string;
|
|
14
|
+
}
|
|
7
15
|
/** Kubernetes pods receive read-only environment CA mounts during admission.
|
|
8
16
|
* Image bytes and digests stay unchanged; explicit pod trust settings win. */
|
|
9
17
|
export interface K3sOptions {
|
|
@@ -11,6 +19,9 @@ export interface K3sOptions {
|
|
|
11
19
|
* or Dockerfile builds with a full `reference` matching your manifests. Builds
|
|
12
20
|
* support path/content, context, exclude, target and buildArgs, and run in
|
|
13
21
|
* parallel with service builds through the standard BuildKit pipeline.
|
|
22
|
+
* With `registry: { host }`, builds targeting that host are also published
|
|
23
|
+
* to the writable registry before setup completes. Other images remain
|
|
24
|
+
* direct preloads; no external registry receives pushes.
|
|
14
25
|
* Setup waits for every pull and fails if a requested image cannot be pulled.
|
|
15
26
|
* Sticky-enabled projects retain image content and unpacked layers between
|
|
16
27
|
* fresh builds automatically. Digest references can reuse the cache offline;
|
|
@@ -85,10 +96,15 @@ export interface K3sOptions {
|
|
|
85
96
|
* into your platform, e.g. `env: { REGISTRY_URL: "cluster.internal:5000" }`.
|
|
86
97
|
* Plain HTTP, so configure your push client for an insecure registry.
|
|
87
98
|
*
|
|
99
|
+
* Set `{ host: "registry.test" }` for verified HTTPS on port 443 through
|
|
100
|
+
* the built-in VM proxy, including containerd trust and relative upload URLs.
|
|
101
|
+
* This does not require Traefik. Builds targeting that host in `images` are
|
|
102
|
+
* published automatically; tags and test uploads remain isolated per fork.
|
|
103
|
+
*
|
|
88
104
|
* On by default. Set `false` for clusters that only ever run public
|
|
89
105
|
* images — that skips the extra pod.
|
|
90
106
|
*/
|
|
91
|
-
registry?: boolean;
|
|
107
|
+
registry?: boolean | K3sRegistryOptions;
|
|
92
108
|
/**
|
|
93
109
|
* Domains to route into this cluster's ingress via **wildcard DNS**. For
|
|
94
110
|
* each `"example.com"`, spectest-resolver answers any `*.example.com`
|
|
@@ -336,6 +352,10 @@ export declare function k3s(opts?: K3sOptions): {
|
|
|
336
352
|
reference: string;
|
|
337
353
|
};
|
|
338
354
|
imageBuilds: import("../index.js").ComponentImageBuild[];
|
|
355
|
+
tls: {
|
|
356
|
+
hostname: string;
|
|
357
|
+
port: number;
|
|
358
|
+
}[];
|
|
339
359
|
command: string;
|
|
340
360
|
privileged: true;
|
|
341
361
|
tmpfs: string[];
|
|
@@ -348,10 +368,12 @@ export declare function k3s(opts?: K3sOptions): {
|
|
|
348
368
|
} | {
|
|
349
369
|
source: string;
|
|
350
370
|
target: string;
|
|
351
|
-
readOnly:
|
|
352
|
-
}
|
|
371
|
+
readOnly: boolean;
|
|
372
|
+
} | {
|
|
353
373
|
target: string;
|
|
354
|
-
|
|
374
|
+
source?: undefined;
|
|
375
|
+
readOnly?: undefined;
|
|
376
|
+
})[];
|
|
355
377
|
files: {
|
|
356
378
|
path: string;
|
|
357
379
|
content: string;
|
package/dist/components/k3s.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { isIP } from "node:net";
|
|
2
2
|
import { installPodTrust } from "./k3s-trust.js";
|
|
3
3
|
import { waitForAll } from "../harness/concurrency.js";
|
|
4
|
+
import { CONTENT_BLOBS, REGISTRY_CONTENT, REGISTRY_DATA, REGISTRY_IMAGE, registryDirectory, seedRegistry } from "../harness/registry-seed.js";
|
|
4
5
|
import { loadK3sBuildImages } from "../harness/k3s-image-loader.js";
|
|
5
6
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
6
7
|
import { spawn as nodeSpawn } from "node:child_process";
|
|
@@ -792,7 +793,7 @@ const HUB_MIRROR = { registry: "docker.io", mirror: "https://mirror.gcr.io", ups
|
|
|
792
793
|
* shares the node's netns, so this needs no in-container DNS and
|
|
793
794
|
* can't be broken by a clobbered `hostnames`.
|
|
794
795
|
*/
|
|
795
|
-
function buildRegistriesYaml(registryEnabled) {
|
|
796
|
+
function buildRegistriesYaml(registryEnabled, host) {
|
|
796
797
|
const lines = [
|
|
797
798
|
"mirrors:",
|
|
798
799
|
` "${HUB_MIRROR.registry}":`,
|
|
@@ -807,6 +808,11 @@ function buildRegistriesYaml(registryEnabled) {
|
|
|
807
808
|
// makes that explicit and disables any TLS attempt against it.
|
|
808
809
|
` "127.0.0.1:${K3S_REGISTRY_PORT}":`, ` tls:`, ` insecure_skip_verify: true`);
|
|
809
810
|
}
|
|
811
|
+
if (host) {
|
|
812
|
+
// This names the verified HTTPS endpoint itself; do not mirror it to HTTP.
|
|
813
|
+
// container-run mounts the environment CA before k3s/containerd starts.
|
|
814
|
+
lines.push(` "${host}":`, " tls:", ` ca_file: ${JSON.stringify(CA_PATH)}`);
|
|
815
|
+
}
|
|
810
816
|
return lines.join("\n") + "\n";
|
|
811
817
|
}
|
|
812
818
|
/**
|
|
@@ -814,11 +820,13 @@ function buildRegistriesYaml(registryEnabled) {
|
|
|
814
820
|
* binds the cluster container's `:5000` directly — the same trick
|
|
815
821
|
* Traefik uses — so peer services reach it at `<cluster-key>.internal:5000`
|
|
816
822
|
* (the cluster service's own alias) and the node's own containerd reaches
|
|
817
|
-
* it at `127.0.0.1:5000`. Storage is an `emptyDir
|
|
818
|
-
*
|
|
819
|
-
*
|
|
823
|
+
* it at `127.0.0.1:5000`. Storage is an `emptyDir` by default. Declared
|
|
824
|
+
* publications use a rootfs directory plus a read-only content mount; both
|
|
825
|
+
* variants keep writable registry state outside persistent image caches and
|
|
826
|
+
* capture it with the VM snapshot, isolated per test fork.
|
|
820
827
|
*/
|
|
821
|
-
|
|
828
|
+
function registryManifest(seeded) {
|
|
829
|
+
return `apiVersion: apps/v1
|
|
822
830
|
kind: Deployment
|
|
823
831
|
metadata:
|
|
824
832
|
name: spectest-registry
|
|
@@ -841,11 +849,13 @@ spec:
|
|
|
841
849
|
- operator: Exists
|
|
842
850
|
containers:
|
|
843
851
|
- name: registry
|
|
844
|
-
image: registry:2
|
|
852
|
+
image: ${seeded ? REGISTRY_IMAGE : "registry:2"}
|
|
845
853
|
imagePullPolicy: IfNotPresent
|
|
846
854
|
env:
|
|
847
855
|
- name: REGISTRY_HTTP_ADDR
|
|
848
856
|
value: ":${K3S_REGISTRY_PORT}"
|
|
857
|
+
- name: REGISTRY_HTTP_RELATIVEURLS
|
|
858
|
+
value: "true"
|
|
849
859
|
- name: REGISTRY_STORAGE_DELETE_ENABLED
|
|
850
860
|
value: "true"
|
|
851
861
|
ports:
|
|
@@ -854,10 +864,20 @@ spec:
|
|
|
854
864
|
volumeMounts:
|
|
855
865
|
- name: data
|
|
856
866
|
mountPath: /var/lib/registry
|
|
857
|
-
|
|
867
|
+
${seeded ? ` - name: content
|
|
868
|
+
mountPath: ${REGISTRY_CONTENT}
|
|
869
|
+
readOnly: true
|
|
870
|
+
` : ""} volumes:
|
|
858
871
|
- name: data
|
|
859
|
-
|
|
872
|
+
${seeded ? ` hostPath:
|
|
873
|
+
path: ${REGISTRY_DATA}
|
|
874
|
+
type: Directory
|
|
875
|
+
- name: content
|
|
876
|
+
hostPath:
|
|
877
|
+
path: ${REGISTRY_CONTENT}
|
|
878
|
+
type: Directory` : " emptyDir: {}"}
|
|
860
879
|
`;
|
|
880
|
+
}
|
|
861
881
|
// ────────────────────────────────────────────────────────────────────────
|
|
862
882
|
// Apply — server-side, converging
|
|
863
883
|
//
|
|
@@ -1310,7 +1330,8 @@ async function setupK3sCluster(name, helpers, opts) {
|
|
|
1310
1330
|
(async () => {
|
|
1311
1331
|
if (!opts.registry)
|
|
1312
1332
|
return;
|
|
1313
|
-
await
|
|
1333
|
+
await opts.seed?.();
|
|
1334
|
+
await helpers.apply(registryManifest(!!opts.seed));
|
|
1314
1335
|
await wait("spectest-registry");
|
|
1315
1336
|
})(),
|
|
1316
1337
|
]);
|
|
@@ -1438,6 +1459,16 @@ export function k3s(opts = {}) {
|
|
|
1438
1459
|
const extra = opts.extraArgs ?? [];
|
|
1439
1460
|
assertUsableExtraArgs(extra);
|
|
1440
1461
|
const registryEnabled = opts.registry !== false;
|
|
1462
|
+
let registryHost;
|
|
1463
|
+
if (opts.registry !== undefined && typeof opts.registry !== "boolean") {
|
|
1464
|
+
if (!opts.registry || typeof opts.registry.host !== "string" || opts.registry.host.startsWith("*.")) {
|
|
1465
|
+
throw new Error("k3s(): registry must be a boolean or { host: an exact DNS hostname }");
|
|
1466
|
+
}
|
|
1467
|
+
// Reuse ingress validation (no scheme, port, path, or reserved .internal).
|
|
1468
|
+
registryHost = dnsName(opts.registry.host, { ingress: true }).hostname;
|
|
1469
|
+
}
|
|
1470
|
+
const isPublished = (reference) => !!registryHost && reference.startsWith(`${registryHost}/`);
|
|
1471
|
+
const publishBuilds = images.builds.filter(image => isPublished(image.reference));
|
|
1441
1472
|
const traefikEnabled = opts.traefik !== false;
|
|
1442
1473
|
const loadBalancerEnabled = opts.loadBalancer !== false;
|
|
1443
1474
|
// Wildcard ingress domains. Drives both the `provides(... dnsName)`
|
|
@@ -1447,12 +1478,13 @@ export function k3s(opts = {}) {
|
|
|
1447
1478
|
// `/etc/rancher/k3s/registries.yaml` (host-cache mirrors + trust for
|
|
1448
1479
|
// the in-cluster registry). Seeded via `files` because k3s reads it
|
|
1449
1480
|
// only at startup, before any setup hook could run.
|
|
1450
|
-
const registriesYaml = buildRegistriesYaml(registryEnabled);
|
|
1481
|
+
const registriesYaml = buildRegistriesYaml(registryEnabled, registryHost);
|
|
1451
1482
|
// The environment's image cache, when this VM carries one: the
|
|
1452
1483
|
// cluster's store goes on its root disk and its layers come off the
|
|
1453
1484
|
// shared layers disk (see the store section above).
|
|
1454
1485
|
const sticky = stickyDiskPathSync();
|
|
1455
1486
|
const cache = sticky ? null : imageCachePathsSync();
|
|
1487
|
+
const contentDirectory = `${sticky ? `${sticky}/containerd` : cache?.root ?? "/var/lib/containerd"}/${CONTENT_BLOBS}`;
|
|
1456
1488
|
const serverArgs = [
|
|
1457
1489
|
"k3s",
|
|
1458
1490
|
"server",
|
|
@@ -1551,6 +1583,7 @@ export function k3s(opts = {}) {
|
|
|
1551
1583
|
const def = {
|
|
1552
1584
|
image: { type: "registry", reference: `rancher/k3s:${version}` },
|
|
1553
1585
|
imageBuilds: images.builds,
|
|
1586
|
+
tls: registryHost ? [{ hostname: registryHost, port: K3S_REGISTRY_PORT }] : [],
|
|
1554
1587
|
command: cmd,
|
|
1555
1588
|
privileged: true,
|
|
1556
1589
|
tmpfs: ["/run", "/var/run"],
|
|
@@ -1572,15 +1605,20 @@ export function k3s(opts = {}) {
|
|
|
1572
1605
|
// in one environment get separate roots either way (the service
|
|
1573
1606
|
// token names the directory), because two containerd daemons cannot
|
|
1574
1607
|
// share a store: bolt takes an exclusive lock.
|
|
1575
|
-
volumes: sticky
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1608
|
+
volumes: [...(sticky
|
|
1609
|
+
? [{ source: `${stickyKubernetesDirectory(SELF_SERVICE_TOKEN, version)}/containerd`, target: CLUSTER_STORE_TARGET }]
|
|
1610
|
+
: cache ? [
|
|
1611
|
+
{ source: nestedStoreDir(cache, SELF_SERVICE_TOKEN), target: CLUSTER_STORE_TARGET },
|
|
1612
|
+
{ source: cache.layers, target: cache.layers, readOnly: true },
|
|
1613
|
+
{ source: MKFS_EROFS_PATH, target: MKFS_EROFS_PATH, readOnly: true },
|
|
1614
|
+
{ source: STORE_ADOPT_PATH, target: STORE_ADOPT_PATH, readOnly: true },
|
|
1615
|
+
]
|
|
1616
|
+
: [{ target: CLUSTER_STORE_TARGET }]),
|
|
1617
|
+
...(publishBuilds.length ? [
|
|
1618
|
+
{ source: registryDirectory(SELF_SERVICE_TOKEN), target: REGISTRY_DATA },
|
|
1619
|
+
{ source: contentDirectory, target: REGISTRY_CONTENT, readOnly: true },
|
|
1620
|
+
] : []),
|
|
1621
|
+
],
|
|
1584
1622
|
files: [
|
|
1585
1623
|
...(registriesYaml ? [{ path: "/etc/rancher/k3s/registries.yaml", content: registriesYaml }] : []),
|
|
1586
1624
|
...(cache
|
|
@@ -1600,55 +1638,61 @@ export function k3s(opts = {}) {
|
|
|
1600
1638
|
const runtime = componentRuntime(ctx);
|
|
1601
1639
|
if (images.builds.length && !runtime)
|
|
1602
1640
|
throw new Error(`k3s(${name}): prepared image inputs are missing`);
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
}, {
|
|
1612
|
-
apply: async (configuration) => { await helpers.apply(JSON.stringify(configuration)); },
|
|
1613
|
-
ensureBundle: async (namespace, configMap, bundle) => {
|
|
1614
|
-
try {
|
|
1615
|
-
await helpers.client.core.createNamespacedConfigMap({ namespace, body: {
|
|
1616
|
-
metadata: { name: configMap, namespace }, immutable: true, data: { "ca-bundle.crt": bundle },
|
|
1617
|
-
} });
|
|
1618
|
-
}
|
|
1619
|
-
catch (err) {
|
|
1620
|
-
// A simultaneous Pod may have created the same namespace's bundle.
|
|
1621
|
-
const existing = (await helpers.client.core.readNamespacedConfigMap({ namespace, name: configMap })).unwrap();
|
|
1622
|
-
if (existing.data?.["ca-bundle.crt"] !== bundle || existing.immutable !== true)
|
|
1623
|
-
throw err;
|
|
1624
|
-
}
|
|
1625
|
-
},
|
|
1626
|
-
});
|
|
1627
|
-
// The API server observes webhook registration asynchronously. A dry-run
|
|
1628
|
-
// Pod proves TLS reachability and admission before any project workload.
|
|
1629
|
-
const deadline = Date.now() + 30_000;
|
|
1630
|
-
for (;;) {
|
|
1641
|
+
const infrastructure = (async () => {
|
|
1642
|
+
if (runtime?.caBundle && caPresent()) {
|
|
1643
|
+
const { cert, key } = await issueIngressCert([runtime.gateway]);
|
|
1644
|
+
await installPodTrust({ name, gateway: runtime.gateway, cert, key,
|
|
1645
|
+
ca: await readFile(CA_PATH, "utf8"), bundle: await readFile(runtime.caBundle, "utf8"),
|
|
1646
|
+
}, {
|
|
1647
|
+
apply: async (configuration) => { await helpers.apply(JSON.stringify(configuration)); },
|
|
1648
|
+
ensureBundle: async (namespace, configMap, bundle) => {
|
|
1631
1649
|
try {
|
|
1632
|
-
|
|
1633
|
-
metadata: {
|
|
1634
|
-
} })
|
|
1635
|
-
if (pod.spec?.containers[0].env?.some(e => e.name === "SSL_CERT_FILE" && e.value === "/spectest/ca-bundle.crt"))
|
|
1636
|
-
break;
|
|
1637
|
-
if (Date.now() >= deadline)
|
|
1638
|
-
throw new Error(`k3s(${name}): Pod CA mounts did not become ready`);
|
|
1650
|
+
await helpers.client.core.createNamespacedConfigMap({ namespace, body: {
|
|
1651
|
+
metadata: { name: configMap, namespace }, immutable: true, data: { "ca-bundle.crt": bundle },
|
|
1652
|
+
} });
|
|
1639
1653
|
}
|
|
1640
1654
|
catch (err) {
|
|
1641
|
-
|
|
1655
|
+
// A simultaneous Pod may have created the same namespace's bundle.
|
|
1656
|
+
const existing = (await helpers.client.core.readNamespacedConfigMap({ namespace, name: configMap })).unwrap();
|
|
1657
|
+
if (existing.data?.["ca-bundle.crt"] !== bundle || existing.immutable !== true)
|
|
1642
1658
|
throw err;
|
|
1643
1659
|
}
|
|
1644
|
-
|
|
1660
|
+
},
|
|
1661
|
+
});
|
|
1662
|
+
// The API server observes webhook registration asynchronously. A dry-run
|
|
1663
|
+
// Pod proves TLS reachability and admission before any project workload.
|
|
1664
|
+
const deadline = Date.now() + 30_000;
|
|
1665
|
+
for (;;) {
|
|
1666
|
+
try {
|
|
1667
|
+
const pod = (await helpers.client.core.createNamespacedPod({ namespace: "default", dryRun: "All", body: {
|
|
1668
|
+
metadata: { generateName: "spectest-trust-probe-" }, spec: { containers: [{ name: "probe", image: "registry.k8s.io/pause:3.10" }] },
|
|
1669
|
+
} })).unwrap();
|
|
1670
|
+
if (pod.spec?.containers[0].env?.some(e => e.name === "SSL_CERT_FILE" && e.value === "/spectest/ca-bundle.crt"))
|
|
1671
|
+
break;
|
|
1672
|
+
if (Date.now() >= deadline)
|
|
1673
|
+
throw new Error(`k3s(${name}): Pod CA mounts did not become ready`);
|
|
1674
|
+
}
|
|
1675
|
+
catch (err) {
|
|
1676
|
+
if (Date.now() >= deadline)
|
|
1677
|
+
throw err;
|
|
1645
1678
|
}
|
|
1679
|
+
await new Promise(resolve => setTimeout(resolve, 100));
|
|
1646
1680
|
}
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1681
|
+
}
|
|
1682
|
+
await setupK3sCluster(name, helpers, {
|
|
1683
|
+
registry: registryEnabled,
|
|
1684
|
+
seed: publishBuilds.length ? () => seedRegistry(name, contentDirectory, runtime.images.filter(image => isPublished(image.reference))) : undefined,
|
|
1685
|
+
ingressDomains,
|
|
1686
|
+
traefik: traefikEnabled,
|
|
1687
|
+
});
|
|
1688
|
+
})();
|
|
1689
|
+
await waitForAll([
|
|
1690
|
+
runtime ? loadK3sBuildImages(name, runtime.images, runtime.gateway, exec) : Promise.resolve(),
|
|
1691
|
+
prePullK3sImages(name, images.pulls.filter(ref => !isPublished(ref)), exec),
|
|
1692
|
+
(async () => {
|
|
1693
|
+
// Registry-local references must not race registry startup/publication.
|
|
1694
|
+
await infrastructure;
|
|
1695
|
+
await prePullK3sImages(name, images.pulls.filter(isPublished), exec);
|
|
1652
1696
|
})(),
|
|
1653
1697
|
]);
|
|
1654
1698
|
if (sticky)
|
package/dist/components/s3.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { rawFetch } from "../harness/raw-fetch.js";
|
|
1
2
|
import { S3Client } from "../s3.js";
|
|
2
3
|
// Backing image, pinned internally (not user-configurable). adobe/s3mock 5.1.0
|
|
3
4
|
// is the current release; avoid exactly 5.0.0, which crashed at startup on
|
|
@@ -75,7 +76,7 @@ export function s3(opts = {}) {
|
|
|
75
76
|
// CreateBucket is a plain `PUT` on the bucket root; the store
|
|
76
77
|
// returns 200 (or 409 if it already exists — idempotent enough to
|
|
77
78
|
// ignore).
|
|
78
|
-
const res = await
|
|
79
|
+
const res = await rawFetch(`http://${name}:${S3_PORT}/${bucket}`, {
|
|
79
80
|
method: "PUT",
|
|
80
81
|
});
|
|
81
82
|
if (!res.ok && res.status !== 409) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { rawFetch } from "../harness/raw-fetch.js";
|
|
1
2
|
// A ready-to-use, self-hosted **Supabase** stack, expressed as a set of
|
|
2
3
|
// spectest services (one container each) wired together on spectest-net.
|
|
3
4
|
//
|
|
@@ -1807,7 +1808,7 @@ export function supabase(opts = {}) {
|
|
|
1807
1808
|
// snapshot and a test's diff is what its requests mutate.
|
|
1808
1809
|
setup: async () => {
|
|
1809
1810
|
const t0 = Date.now();
|
|
1810
|
-
const res = await
|
|
1811
|
+
const res = await rawFetch(`http://${g.key("functions")}:9000/_spectest/warm`);
|
|
1811
1812
|
if (!res.ok) {
|
|
1812
1813
|
console.warn(`supabase(): edge functions warm-up answered ${res.status}; functions boot on first call instead.`);
|
|
1813
1814
|
return;
|
package/dist/daemon.js
CHANGED
|
@@ -1958,6 +1958,9 @@ serve = { proto: "http" }) {
|
|
|
1958
1958
|
// {@link stopIngressServers} depends on: a half-alive listener shares
|
|
1959
1959
|
// the port silently instead of colliding loudly.
|
|
1960
1960
|
reusePort: true,
|
|
1961
|
+
// OCI layer uploads can exceed Bun's default 128 MiB request limit.
|
|
1962
|
+
// Large proxy bodies stream through; this limit does not allocate a buffer.
|
|
1963
|
+
maxRequestBodySize: 1024 ** 4,
|
|
1961
1964
|
// Bun.serve defaults to a 10s idleTimeout, which kills any proxied
|
|
1962
1965
|
// request whose upstream takes >10s to produce bytes — under parallel
|
|
1963
1966
|
// test load that surfaced as "fetch failed"/"other side closed" on
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface Descriptor {
|
|
2
|
+
digest: string;
|
|
3
|
+
size: number;
|
|
4
|
+
mediaType: string;
|
|
5
|
+
platform?: {
|
|
6
|
+
os: string;
|
|
7
|
+
architecture: string;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
/** Preserve the original index/manifest bytes and all application descriptors. */
|
|
11
|
+
export declare function hostImage(source: string): Promise<{
|
|
12
|
+
target: Descriptor;
|
|
13
|
+
metadata: Map<string, Buffer<ArrayBufferLike>>;
|
|
14
|
+
allowed: Map<string, Descriptor>;
|
|
15
|
+
configDigest: string;
|
|
16
|
+
}>;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/** Read build results without reserializing manifests or exporting layers. */
|
|
2
|
+
import { execFile } from "node:child_process";
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
import { promisify } from "node:util";
|
|
5
|
+
import { canonicalImageReference } from "./component-images.js";
|
|
6
|
+
const digest = (bytes) => `sha256:${createHash("sha256").update(bytes).digest("hex")}`;
|
|
7
|
+
const descriptor = (bytes, mediaType) => ({ digest: digest(bytes), size: bytes.length, mediaType });
|
|
8
|
+
const run = promisify(execFile);
|
|
9
|
+
const HOST_CTR = ["--address", "/run/containerd/containerd.sock", "--namespace", "moby"];
|
|
10
|
+
async function hostContent(id) {
|
|
11
|
+
if (!/^sha256:[a-f0-9]{64}$/.test(id))
|
|
12
|
+
throw new Error(`invalid content digest ${id}`);
|
|
13
|
+
const result = await run("ctr", [...HOST_CTR, "content", "get", id], { encoding: "buffer", maxBuffer: 16 * 1024 * 1024, timeout: 30_000 });
|
|
14
|
+
if (digest(result.stdout) !== id)
|
|
15
|
+
throw new Error(`corrupt image metadata ${id}`);
|
|
16
|
+
return result.stdout;
|
|
17
|
+
}
|
|
18
|
+
/** Preserve the original index/manifest bytes and all application descriptors. */
|
|
19
|
+
export async function hostImage(source) {
|
|
20
|
+
const name = canonicalImageReference(source);
|
|
21
|
+
const { stdout } = await run("ctr", [...HOST_CTR, "images", "ls", `name==${name}`], { timeout: 30_000 });
|
|
22
|
+
const found = stdout.split("\n").map(line => line.trim().split(/\s+/)).find(row => row[0] === name)?.[2];
|
|
23
|
+
if (!found)
|
|
24
|
+
throw new Error(`built image ${name} is missing from the VM container store`);
|
|
25
|
+
const metadata = new Map();
|
|
26
|
+
const allowed = new Map();
|
|
27
|
+
let configDigest;
|
|
28
|
+
async function visit(id, selected, depth = 0) {
|
|
29
|
+
if (depth > 4)
|
|
30
|
+
throw new Error(`built image ${name} has a recursive manifest index`);
|
|
31
|
+
const bytes = await hostContent(id);
|
|
32
|
+
const obj = JSON.parse(bytes.toString());
|
|
33
|
+
const desc = descriptor(bytes, obj.mediaType);
|
|
34
|
+
metadata.set(id, bytes);
|
|
35
|
+
allowed.set(id, desc);
|
|
36
|
+
if (obj.config && Array.isArray(obj.layers)) {
|
|
37
|
+
const manifest = obj;
|
|
38
|
+
for (const blob of [manifest.config, ...manifest.layers])
|
|
39
|
+
allowed.set(blob.digest, blob);
|
|
40
|
+
if (selected)
|
|
41
|
+
configDigest = manifest.config.digest;
|
|
42
|
+
}
|
|
43
|
+
else if (Array.isArray(obj.manifests)) {
|
|
44
|
+
for (const entry of obj.manifests) {
|
|
45
|
+
const matches = !entry.platform || (entry.platform.os === "linux" && entry.platform.architecture === (process.arch === "arm64" ? "arm64" : "amd64"));
|
|
46
|
+
await visit(entry.digest, selected && matches, depth + 1);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
else
|
|
50
|
+
throw new Error(`built image ${name} has invalid image metadata`);
|
|
51
|
+
return desc;
|
|
52
|
+
}
|
|
53
|
+
const target = await visit(found, true);
|
|
54
|
+
if (!configDigest)
|
|
55
|
+
throw new Error(`built image ${name} has no image for this VM's platform`);
|
|
56
|
+
return { target, metadata, allowed, configDigest };
|
|
57
|
+
}
|
|
@@ -1,65 +1,14 @@
|
|
|
1
1
|
/** A short-lived, read-only OCI endpoint over the host containerd content store.
|
|
2
2
|
* k3s fetches only missing blobs and unpacks only missing snapshots. No Docker
|
|
3
3
|
* archive, staging registry, or second persistent copy of application blobs. */
|
|
4
|
-
import {
|
|
4
|
+
import { spawn } from "node:child_process";
|
|
5
5
|
import { createHash } from "node:crypto";
|
|
6
6
|
import { createServer } from "node:http";
|
|
7
|
-
import { promisify } from "node:util";
|
|
8
7
|
import { canonicalImageReference } from "./component-images.js";
|
|
9
8
|
import { waitForK3sRuntime } from "./k3s-prepull.js";
|
|
9
|
+
import { hostImage } from "./built-image.js";
|
|
10
10
|
import { waitForAll } from "./concurrency.js";
|
|
11
|
-
const digest = (bytes) => `sha256:${createHash("sha256").update(bytes).digest("hex")}`;
|
|
12
|
-
const descriptor = (bytes, mediaType) => ({ digest: digest(bytes), size: bytes.length, mediaType });
|
|
13
|
-
const run = promisify(execFile);
|
|
14
11
|
const HOST_CTR = ["--address", "/run/containerd/containerd.sock", "--namespace", "moby"];
|
|
15
|
-
async function hostContent(id) {
|
|
16
|
-
if (!/^sha256:[a-f0-9]{64}$/.test(id))
|
|
17
|
-
throw new Error(`invalid content digest ${id}`);
|
|
18
|
-
const result = await run("ctr", [...HOST_CTR, "content", "get", id], { encoding: "buffer", maxBuffer: 16 * 1024 * 1024, timeout: 30_000 });
|
|
19
|
-
if (digest(result.stdout) !== id)
|
|
20
|
-
throw new Error(`corrupt image metadata ${id}`);
|
|
21
|
-
return result.stdout;
|
|
22
|
-
}
|
|
23
|
-
/** Preserve the original index/manifest bytes and all application descriptors. */
|
|
24
|
-
async function hostImage(source) {
|
|
25
|
-
const name = canonicalImageReference(source);
|
|
26
|
-
const { stdout } = await run("ctr", [...HOST_CTR, "images", "ls", `name==${name}`], { timeout: 30_000 });
|
|
27
|
-
const found = stdout.split("\n").map(line => line.trim().split(/\s+/)).find(row => row[0] === name)?.[2];
|
|
28
|
-
if (!found)
|
|
29
|
-
throw new Error(`built image ${name} is missing from the VM container store`);
|
|
30
|
-
const metadata = new Map();
|
|
31
|
-
const allowed = new Map();
|
|
32
|
-
let configDigest;
|
|
33
|
-
async function visit(id, selected, depth = 0) {
|
|
34
|
-
if (depth > 4)
|
|
35
|
-
throw new Error(`built image ${name} has a recursive manifest index`);
|
|
36
|
-
const bytes = await hostContent(id);
|
|
37
|
-
const obj = JSON.parse(bytes.toString());
|
|
38
|
-
const desc = descriptor(bytes, obj.mediaType);
|
|
39
|
-
metadata.set(id, bytes);
|
|
40
|
-
allowed.set(id, desc);
|
|
41
|
-
if (obj.config && Array.isArray(obj.layers)) {
|
|
42
|
-
const manifest = obj;
|
|
43
|
-
for (const blob of [manifest.config, ...manifest.layers])
|
|
44
|
-
allowed.set(blob.digest, blob);
|
|
45
|
-
if (selected)
|
|
46
|
-
configDigest = manifest.config.digest;
|
|
47
|
-
}
|
|
48
|
-
else if (Array.isArray(obj.manifests)) {
|
|
49
|
-
for (const entry of obj.manifests) {
|
|
50
|
-
const matches = !entry.platform || (entry.platform.os === "linux" && entry.platform.architecture === (process.arch === "arm64" ? "arm64" : "amd64"));
|
|
51
|
-
await visit(entry.digest, selected && matches, depth + 1);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
else
|
|
55
|
-
throw new Error(`built image ${name} has invalid image metadata`);
|
|
56
|
-
return desc;
|
|
57
|
-
}
|
|
58
|
-
const target = await visit(found, true);
|
|
59
|
-
if (!configDigest)
|
|
60
|
-
throw new Error(`built image ${name} has no image for this VM's platform`);
|
|
61
|
-
return { target, metadata, allowed, configDigest };
|
|
62
|
-
}
|
|
63
12
|
export async function loadK3sBuildImages(service, images, gateway, exec) {
|
|
64
13
|
if (!images.length)
|
|
65
14
|
return;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { hostImage } from "./built-image.js";
|
|
2
|
+
import { type PreparedComponentImage } from "./component-images.js";
|
|
3
|
+
export declare const REGISTRY_DATA = "/var/lib/spectest-registry";
|
|
4
|
+
export declare const REGISTRY_CONTENT = "/spectest-registry-content";
|
|
5
|
+
export declare const CONTENT_BLOBS = "io.containerd.content.v1.content/blobs/sha256";
|
|
6
|
+
export declare const REGISTRY_IMAGE = "registry:2.8.3";
|
|
7
|
+
export declare const registryDirectory: (service: string) => string;
|
|
8
|
+
/** Distribution 2.8 registry/storage/paths.go defines this layout. Seed
|
|
9
|
+
* before starting the registry so it cannot cache partial publication.
|
|
10
|
+
* The prepared build's containerd image record retains the referenced blobs. */
|
|
11
|
+
export declare function seedRegistryImage(directory: string, contentDirectory: string, reference: string, image: Awaited<ReturnType<typeof hostImage>>, mountedContent?: string): Promise<void>;
|
|
12
|
+
export declare function seedRegistry(service: string, contentDirectory: string, images: readonly PreparedComponentImage[]): Promise<void>;
|