@lunora/container 1.0.0-alpha.8 → 1.0.0-alpha.80
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 +24 -5
- package/dist/bridge.d.mts +43 -33
- package/dist/bridge.d.ts +43 -33
- package/dist/bridge.mjs +1 -79
- package/dist/do/index.d.mts +353 -91
- package/dist/do/index.d.ts +353 -91
- package/dist/do/index.mjs +1 -328
- package/dist/index.d.mts +584 -153
- package/dist/index.d.ts +584 -153
- package/dist/index.mjs +1 -2
- package/dist/otel.d.mts +217 -0
- package/dist/otel.d.ts +217 -0
- package/dist/otel.mjs +1 -0
- package/dist/packem_shared/CONTAINER_EXEC_PATH-7Hcd6-zs.mjs +1 -0
- package/dist/packem_shared/CUSTOM_INSTANCE_MIN_MEMORY_MIB_PER_VCPU-D8Hy9Rxv.mjs +1 -0
- package/dist/packem_shared/ContainerProxy-CfXjS6ZI.mjs +27 -0
- package/dist/packem_shared/DURABLE_OBJECT_POLICY_FORBIDDEN_KEYS-gYi8RBUO.mjs +1 -0
- package/dist/packem_shared/LunoraSandboxContainer-DPnhJUu1.mjs +1 -0
- package/dist/packem_shared/abort-deadline-jwbW9Ala.mjs +1 -0
- package/dist/packem_shared/createContainerContext-p6QxWjsm.mjs +1 -0
- package/dist/packem_shared/exec-BYLW70sR.mjs +1 -0
- package/dist/packem_shared/jurisdiction-DtE9s70w.mjs +1 -0
- package/dist/packem_shared/jurisdiction.d-BwpauCoI.d.mts +471 -0
- package/dist/packem_shared/jurisdiction.d-BwpauCoI.d.ts +471 -0
- package/dist/packem_shared/sampling-D21rpu_s.mjs +1 -0
- package/dist/packem_shared/sandbox-types.d-DXlHnsEg.d.mts +110 -0
- package/dist/packem_shared/sandbox-types.d-DXlHnsEg.d.ts +110 -0
- package/dist/sandbox/index.d.mts +66 -0
- package/dist/sandbox/index.d.ts +66 -0
- package/dist/sandbox/index.mjs +1 -0
- package/package.json +12 -2
- package/dist/packem_shared/ContainerProxy-DWqUX_re.mjs +0 -1474
- package/dist/packem_shared/containerBindingName-D5KTrblH.mjs +0 -218
- package/dist/packem_shared/createContainerContext-Cibbh7AE.mjs +0 -228
- package/dist/packem_shared/types.d-BlNwNY44.d.mts +0 -250
- package/dist/packem_shared/types.d-BlNwNY44.d.ts +0 -250
|
@@ -0,0 +1,471 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `handle.spawn()` contract: start a process in a named container
|
|
3
|
+
* instance and stream it, rather than buffer it the way `exec` does.
|
|
4
|
+
*
|
|
5
|
+
* Node-safe (no runtime imports): the Durable Object half lives in
|
|
6
|
+
* `do/spawn.ts`. This module owns the request shape both halves agree on and
|
|
7
|
+
* turns the RPC result into a {@link ContainerProcess}.
|
|
8
|
+
*/
|
|
9
|
+
/** Per-call options for `handle.spawn()`. */
|
|
10
|
+
interface ContainerSpawnOptions {
|
|
11
|
+
/** Arguments passed to `command`, unshelled. */
|
|
12
|
+
args?: ReadonlyArray<string>;
|
|
13
|
+
/** Working directory for the process. */
|
|
14
|
+
cwd?: string;
|
|
15
|
+
/** Extra environment for this process, merged over the container's start env. */
|
|
16
|
+
env?: Readonly<Record<string, string>>;
|
|
17
|
+
/**
|
|
18
|
+
* Run the process on a pseudo-terminal of this size (defaults `80×24`).
|
|
19
|
+
* Under a PTY, stderr is merged into `stdout` and `resize()` works — what an
|
|
20
|
+
* interactive shell or a browser terminal needs.
|
|
21
|
+
*/
|
|
22
|
+
pty?: {
|
|
23
|
+
cols?: number;
|
|
24
|
+
rows?: number;
|
|
25
|
+
};
|
|
26
|
+
/** Kill the process when this signal aborts. */
|
|
27
|
+
signal?: AbortSignal;
|
|
28
|
+
/**
|
|
29
|
+
* Give the process a stdin: `true` returns a writable `stdin` stream, a
|
|
30
|
+
* `ReadableStream` is piped in as the process's whole input. Omitted or
|
|
31
|
+
* `false` leaves stdin closed.
|
|
32
|
+
*/
|
|
33
|
+
stdin?: ReadableStream<Uint8Array> | boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Kill the process after this many ms. Unlike `exec`, a spawned process has
|
|
36
|
+
* no default deadline: it runs until it exits, is killed, or the container
|
|
37
|
+
* stops.
|
|
38
|
+
*/
|
|
39
|
+
timeoutMs?: number;
|
|
40
|
+
}
|
|
41
|
+
/** The request `lunoraSpawn` takes over RPC. An `AbortSignal` cannot cross RPC, so it stays on the caller's side. */
|
|
42
|
+
interface ContainerSpawnRequest extends Omit<ContainerSpawnOptions, "args" | "env" | "signal"> {
|
|
43
|
+
args?: string[];
|
|
44
|
+
command: string;
|
|
45
|
+
env?: Record<string, string>;
|
|
46
|
+
}
|
|
47
|
+
/** The control stub `lunoraSpawn` returns, as the caller sees it over RPC. */
|
|
48
|
+
interface ContainerProcessControlStub {
|
|
49
|
+
exitCode: () => Promise<number>;
|
|
50
|
+
kill: (signal?: number) => Promise<void> | void;
|
|
51
|
+
resize: (cols: number, rows: number) => Promise<void> | void;
|
|
52
|
+
}
|
|
53
|
+
/** `lunoraSpawn`'s RPC result. */
|
|
54
|
+
interface SpawnResult {
|
|
55
|
+
control: ContainerProcessControlStub;
|
|
56
|
+
isPty: boolean;
|
|
57
|
+
pid: number;
|
|
58
|
+
stderr: ReadableStream<Uint8Array> | null;
|
|
59
|
+
stdin: WritableStream<Uint8Array> | null;
|
|
60
|
+
stdout: ReadableStream<Uint8Array> | null;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* A running process in a container instance, returned by `handle.spawn()`.
|
|
64
|
+
*
|
|
65
|
+
* The container finishes a process's output, and settles `exitCode`, only
|
|
66
|
+
* while its output is being drained. Lunora drains `stdout` and `stderr` into
|
|
67
|
+
* a 1 MiB buffer each, so they can be read in either order, or after awaiting
|
|
68
|
+
* `exitCode`, while the stream you are not reading stays under 1 MiB. Past
|
|
69
|
+
* that the process stalls until you read it: for a process that may write more
|
|
70
|
+
* to one stream, read both concurrently, or cancel the one you do not need.
|
|
71
|
+
*/
|
|
72
|
+
interface ContainerProcess {
|
|
73
|
+
/** Resolves with the exit code once the process ends. */
|
|
74
|
+
exitCode: Promise<number>;
|
|
75
|
+
/** Whether the process runs on a PTY (`spawn({ pty })`). */
|
|
76
|
+
isPty: boolean;
|
|
77
|
+
/** Send `signal` (default `SIGTERM`). Resolves once the signal is sent, not when the process exits. */
|
|
78
|
+
kill: (signal?: number) => Promise<void>;
|
|
79
|
+
/** The process id inside the container, or `-1` when the runtime does not report one. */
|
|
80
|
+
pid: number;
|
|
81
|
+
/** Resize the PTY. Rejects for a process spawned without `pty`. */
|
|
82
|
+
resize: (cols: number, rows: number) => Promise<void>;
|
|
83
|
+
/** The process's stderr, or `null` under `pty` (merged into `stdout`). */
|
|
84
|
+
stderr: ReadableStream<Uint8Array> | null;
|
|
85
|
+
/** The process's stdin when spawned with `stdin: true`, else `null`. */
|
|
86
|
+
stdin: WritableStream<Uint8Array> | null;
|
|
87
|
+
/** The process's stdout (and, under `pty`, its stderr too). */
|
|
88
|
+
stdout: ReadableStream<Uint8Array> | null;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Public configuration types for `@lunora/container`.
|
|
92
|
+
*
|
|
93
|
+
* Everything in this module is pure data — no Cloudflare runtime imports — so
|
|
94
|
+
* it is safe to import from Node tooling (codegen, the config layer) as well
|
|
95
|
+
* as from worker code.
|
|
96
|
+
*/
|
|
97
|
+
/**
|
|
98
|
+
* Named instance types Cloudflare Containers provides.
|
|
99
|
+
*/
|
|
100
|
+
type NamedContainerInstanceType = "basic" | "lite" | "standard-1" | "standard-2" | "standard-3" | "standard-4";
|
|
101
|
+
/**
|
|
102
|
+
* A custom instance type, available to every Containers account. Cloudflare's
|
|
103
|
+
* documented bounds: 1–4 vCPU, up to 12 GiB memory, up to 20 GB disk at any
|
|
104
|
+
* memory size, and ≥ 3 GiB memory per vCPU. For less than 1 vCPU use the named
|
|
105
|
+
* `lite` or `basic` types. The bounds live in `CUSTOM_INSTANCE_TYPE_LIMITS`
|
|
106
|
+
* (`./instance-limits`), which both `defineContainer` (a `durable_object`
|
|
107
|
+
* container's runtime size) and `@lunora/config`'s wrangler validator
|
|
108
|
+
* (`containers[].instance_type`) enforce.
|
|
109
|
+
*/
|
|
110
|
+
interface CustomContainerInstanceType {
|
|
111
|
+
/** Disk in MB, up to 20000 (20 GB) at any memory size. Cloudflare's default is 2000 (2 GB). */
|
|
112
|
+
diskMb?: number;
|
|
113
|
+
/** Memory in MiB, up to 12288 (12 GiB) and ≥ 3072 MiB per vCPU. Cloudflare's default is 256. */
|
|
114
|
+
memoryMib?: number;
|
|
115
|
+
/** vCPU count, 1–4 when set. Cloudflare's default is 0.0625 (1/16 vCPU). */
|
|
116
|
+
vcpu?: number;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* `ContainerInstanceType` is part of the experimental `@lunora/container` API and may change without a major version bump.
|
|
120
|
+
*/
|
|
121
|
+
type ContainerInstanceType = CustomContainerInstanceType | NamedContainerInstanceType;
|
|
122
|
+
/**
|
|
123
|
+
* An instance size a Durable Object can pick at start under the
|
|
124
|
+
* `durable_object` scheduling policy. The runtime does not accept `basic` (or
|
|
125
|
+
* the legacy `dev`/`standard` aliases), and a custom size must set all three
|
|
126
|
+
* fields — it is passed to `ctx.container.start({ instance })` as-is.
|
|
127
|
+
*/
|
|
128
|
+
type ContainerRuntimeInstanceType = Exclude<NamedContainerInstanceType, "basic"> | Required<CustomContainerInstanceType>;
|
|
129
|
+
/**
|
|
130
|
+
* One named image under the `durable_object` scheduling policy. A `string` is
|
|
131
|
+
* a local Dockerfile path or directory, built and uploaded by `wrangler deploy`
|
|
132
|
+
* (wrangler `dockerfile` + `build_context`); `{ registry }` must be a
|
|
133
|
+
* digest-pinned (`@sha256:…`) reference under `registry.cloudflare.com/`,
|
|
134
|
+
* the Cloudflare managed registry — Cloudflare does not accept Docker Hub, ECR
|
|
135
|
+
* or Artifact Registry references here.
|
|
136
|
+
*/
|
|
137
|
+
type ContainerNamedImageSource = RegistryImageSource | string;
|
|
138
|
+
/**
|
|
139
|
+
* Rolling-deploy tuning for a container.
|
|
140
|
+
*/
|
|
141
|
+
interface ContainerRollout {
|
|
142
|
+
/** Seconds an active instance runs before it's eligible for update (wrangler `rollout_active_grace_period`). */
|
|
143
|
+
gracePeriodSeconds?: number;
|
|
144
|
+
/** Percentage of instances updated per rollout step, 1–100 (wrangler `rollout_step_percentage`). */
|
|
145
|
+
stepPercentage?: number;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* A pre-built image pulled from a registry — the Cloudflare Registry, Docker
|
|
149
|
+
* Hub, or Amazon ECR (the registries `wrangler deploy` supports). The
|
|
150
|
+
* reference must be fully qualified, e.g. `docker.io/acme/transcoder:1.4`.
|
|
151
|
+
*/
|
|
152
|
+
interface RegistryImageSource {
|
|
153
|
+
registry: string;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* A Dockerfile-less build via [Railpack](https://railpack.com): point at a
|
|
157
|
+
* source directory and `lunora deploy` builds an OCI image with Railpack
|
|
158
|
+
* (needs a BuildKit instance) and pushes it to the Cloudflare Registry before
|
|
159
|
+
* wrangler runs. Opt-in — the Dockerfile path is the zero-extra-deps default.
|
|
160
|
+
*/
|
|
161
|
+
interface BuildImageSource {
|
|
162
|
+
build: string;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Where the container image comes from. A `string` is a **local path** —
|
|
166
|
+
* either a directory containing a `Dockerfile` (normalized to
|
|
167
|
+
* `<dir>/Dockerfile` with the directory as the build context) or a path to
|
|
168
|
+
* the Dockerfile itself — while `{ registry }` is a pre-built image reference.
|
|
169
|
+
*/
|
|
170
|
+
type ContainerImageSource = BuildImageSource | RegistryImageSource | string;
|
|
171
|
+
/**
|
|
172
|
+
* An application-level readiness probe that gates request proxying. Layered on
|
|
173
|
+
* top of the platform's own port/`pingEndpoint` health wait, it lets you hold
|
|
174
|
+
* traffic back until the app inside the container is *functionally* ready —
|
|
175
|
+
* migrations applied, caches warmed — which an open-port check can't see.
|
|
176
|
+
*
|
|
177
|
+
* Declarative on purpose: a `defineContainer` value stays pure data (no handler
|
|
178
|
+
* functions), so codegen and the config layer can read it without evaluating
|
|
179
|
+
* code. (Upstream cloudflare/containers#188 expresses the same idea as handler
|
|
180
|
+
* functions; the Lunora config is data-only, so it's modelled as descriptors.)
|
|
181
|
+
*/
|
|
182
|
+
interface ContainerReadinessCheck {
|
|
183
|
+
/** HTTP path probed on the container, e.g. `"/ready"` (a leading slash is optional). */
|
|
184
|
+
path: string;
|
|
185
|
+
/** Port to probe. Defaults to {@link ContainerConfigBase.defaultPort}. */
|
|
186
|
+
port?: number;
|
|
187
|
+
/** HTTP status that means "ready". Defaults to `200`. */
|
|
188
|
+
status?: number;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* The fields every container accepts, whichever scheduling policy it uses.
|
|
192
|
+
*/
|
|
193
|
+
/**
|
|
194
|
+
* Where `handle.backup()` stores directory backups for a `sandbox: true`
|
|
195
|
+
* container: an R2 bucket binding and an optional key prefix.
|
|
196
|
+
*/
|
|
197
|
+
interface ContainerBackupStorage {
|
|
198
|
+
/** Name of an R2 bucket binding on the Worker env (`r2_buckets[].binding`). */
|
|
199
|
+
bucket: string;
|
|
200
|
+
/** Key prefix for the backup objects. A non-empty prefix ends in `/`. */
|
|
201
|
+
prefix?: string;
|
|
202
|
+
}
|
|
203
|
+
interface ContainerConfigBase {
|
|
204
|
+
/**
|
|
205
|
+
* Hostnames the container may reach **even when {@link ContainerConfigBase.enableInternet}
|
|
206
|
+
* is `false`** — an egress allow-list (Cloudflare's `allowedHosts`). Glob
|
|
207
|
+
* patterns like `*.stripe.com` are supported. Pair with `enableInternet:
|
|
208
|
+
* false` to deny all egress except these hosts (the firewall pattern
|
|
209
|
+
* upstream issue cloudflare/containers#30 asked for). The interception path
|
|
210
|
+
* needs the `ContainerProxy` worker entrypoint, which codegen re-exports
|
|
211
|
+
* from the generated container file automatically; the named-instance
|
|
212
|
+
* handle's `egress` controls adjust the lists at runtime.
|
|
213
|
+
*/
|
|
214
|
+
allowedHosts?: ReadonlyArray<string>;
|
|
215
|
+
/**
|
|
216
|
+
* Where `handle.backup()` saves directory backups (requires `sandbox: true`).
|
|
217
|
+
* The backup and restore traffic goes through the `DirectoryBackupGateway`
|
|
218
|
+
* Worker entrypoint, which hands the container a grant for one object per
|
|
219
|
+
* operation, so the container never holds bucket credentials.
|
|
220
|
+
*/
|
|
221
|
+
backups?: ContainerBackupStorage;
|
|
222
|
+
/**
|
|
223
|
+
* Build-time variables for a Dockerfile/Railpack image — wrangler's
|
|
224
|
+
* `image_vars` (equivalent to `docker build --build-arg`). For *runtime*
|
|
225
|
+
* values use {@link ContainerConfigBase.env} / {@link ContainerConfigBase.secrets}.
|
|
226
|
+
* Ignored for a pre-built `{ registry }` image.
|
|
227
|
+
*/
|
|
228
|
+
buildArgs?: Readonly<Record<string, string>>;
|
|
229
|
+
/**
|
|
230
|
+
* The port the container listens on. Worker → container requests target
|
|
231
|
+
* this port. Locally the Dockerfile must also `EXPOSE` it. For a
|
|
232
|
+
* multi-port container also declare {@link ContainerConfigBase.requiredPorts}
|
|
233
|
+
* and route per request with the handle's `.port(n)`.
|
|
234
|
+
*/
|
|
235
|
+
defaultPort?: number;
|
|
236
|
+
/**
|
|
237
|
+
* Hostnames the container may **never** reach — an egress deny-list
|
|
238
|
+
* (Cloudflare's `deniedHosts`). Overrides everything else, including
|
|
239
|
+
* `enableInternet: true` and {@link ContainerConfigBase.allowedHosts}. Glob
|
|
240
|
+
* patterns like `*.evil.com` are supported.
|
|
241
|
+
*/
|
|
242
|
+
deniedHosts?: ReadonlyArray<string>;
|
|
243
|
+
/**
|
|
244
|
+
* Whether the container may open outbound internet connections. Defaults
|
|
245
|
+
* to `true` — the platform default. Note that container egress is billed
|
|
246
|
+
* per GB by Cloudflare. Combine with {@link ContainerConfigBase.allowedHosts} /
|
|
247
|
+
* {@link ContainerConfigBase.deniedHosts} for a precise egress firewall.
|
|
248
|
+
*/
|
|
249
|
+
enableInternet?: boolean;
|
|
250
|
+
/**
|
|
251
|
+
* Default command to run inside the container, overriding the image's
|
|
252
|
+
* `ENTRYPOINT`/`CMD` (Cloudflare's `entrypoint`). A per-start override is
|
|
253
|
+
* still available via the named-instance handle's `start({ entrypoint })`.
|
|
254
|
+
*/
|
|
255
|
+
entrypoint?: ReadonlyArray<string>;
|
|
256
|
+
/**
|
|
257
|
+
* Static environment variables passed to the container on every start.
|
|
258
|
+
* For secret values use {@link ContainerConfigBase.secrets} instead so they
|
|
259
|
+
* flow through Worker Secrets rather than source code.
|
|
260
|
+
*/
|
|
261
|
+
env?: Readonly<Record<string, string>>;
|
|
262
|
+
/**
|
|
263
|
+
* Hard cap on how long an instance may run, measured from start regardless
|
|
264
|
+
* of activity — a runaway-cost backstop on top of the idle
|
|
265
|
+
* {@link ContainerConfigBase.sleepAfter}. Same grammar as `sleepAfter`
|
|
266
|
+
* (`"30s"`, `"5m"`, `"1h"`, or a plain number of seconds). When it elapses,
|
|
267
|
+
* the `LunoraContainer.onHardTimeoutExpired` hook runs (default: `stop()`,
|
|
268
|
+
* which sends SIGTERM and does not escalate — a container that ignores the
|
|
269
|
+
* signal outlives its cap unless the hook is overridden to follow up with
|
|
270
|
+
* `destroy()`). (Upstream cloudflare/containers#85.)
|
|
271
|
+
*/
|
|
272
|
+
hardTimeout?: number | string;
|
|
273
|
+
/**
|
|
274
|
+
* Intercept the container's outbound **HTTPS** traffic so the egress
|
|
275
|
+
* allow/deny lists apply to TLS connections too (Cloudflare's
|
|
276
|
+
* `interceptHttps`). Requires the image to trust the Cloudflare CA at
|
|
277
|
+
* `/etc/cloudflare/certs/cloudflare-containers-ca.crt`. Defaults to `false`
|
|
278
|
+
* (HTTP egress is gated regardless).
|
|
279
|
+
*/
|
|
280
|
+
interceptHttps?: boolean;
|
|
281
|
+
/**
|
|
282
|
+
* Key-value metadata attached to every instance for metrics/observability
|
|
283
|
+
* (Cloudflare's container `labels`), e.g. `{ tenant: "acme", env: "prod" }`.
|
|
284
|
+
* A per-start override is available via the named-instance handle's
|
|
285
|
+
* `start({ labels })`.
|
|
286
|
+
*/
|
|
287
|
+
labels?: Readonly<Record<string, string>>;
|
|
288
|
+
/**
|
|
289
|
+
* Override for the wrangler `containers[].name` identifier. Defaults to
|
|
290
|
+
* wrangler's own default (worker name + class name + environment).
|
|
291
|
+
*/
|
|
292
|
+
name?: string;
|
|
293
|
+
/**
|
|
294
|
+
* HTTP path Cloudflare polls to decide an instance is healthy
|
|
295
|
+
* (Cloudflare's `pingEndpoint`). Defaults to upstream's slash-less `"ping"`;
|
|
296
|
+
* either `"ping"` or `"/healthz"`-style paths are accepted. Set this when
|
|
297
|
+
* the container exposes its readiness check under a different route.
|
|
298
|
+
*/
|
|
299
|
+
pingEndpoint?: string;
|
|
300
|
+
/**
|
|
301
|
+
* Application-level readiness probes that gate request proxying: a
|
|
302
|
+
* `ctx.containers.<name>` fetch waits until every probe responds with its
|
|
303
|
+
* expected status before the request reaches the container — on top of the
|
|
304
|
+
* platform's port/`pingEndpoint` health wait. All probes run in parallel.
|
|
305
|
+
* Use these for readiness an open-port check can't see (migrations applied,
|
|
306
|
+
* caches warm). (Upstream cloudflare/containers#188.)
|
|
307
|
+
*/
|
|
308
|
+
readyOn?: ReadonlyArray<ContainerReadinessCheck>;
|
|
309
|
+
/**
|
|
310
|
+
* Ports the container must be listening on before it's considered ready
|
|
311
|
+
* (Cloudflare's `requiredPorts`) — for multi-port containers. Start-up
|
|
312
|
+
* waits for every listed port, and the handle's `.port(n)` routes a request
|
|
313
|
+
* to any of them; {@link ContainerConfigBase.defaultPort} is the target when a
|
|
314
|
+
* request doesn't pick one.
|
|
315
|
+
*/
|
|
316
|
+
requiredPorts?: ReadonlyArray<number>;
|
|
317
|
+
/**
|
|
318
|
+
* Opt in to the Sandbox SDK helpers (`@cloudflare/sandbox`): structured
|
|
319
|
+
* file operations, directory backups to R2 and S3-compatible bucket mounts
|
|
320
|
+
* on a named instance. The image must ship the `sandbox-shim` helper at
|
|
321
|
+
* `/usr/local/bin/sandbox-shim`, copied from Cloudflare's shim-only
|
|
322
|
+
* `cloudflare/sandbox` image (`COPY --from=…`). Turning it on also makes codegen export the `S3Gateway` and
|
|
323
|
+
* `DirectoryBackupGateway` entrypoints from the worker, which the helpers
|
|
324
|
+
* route the container's storage traffic through. Must be a `true`/`false`
|
|
325
|
+
* literal, because codegen reads it. Defaults to `false`.
|
|
326
|
+
*/
|
|
327
|
+
sandbox?: boolean;
|
|
328
|
+
/**
|
|
329
|
+
* Names of Worker secrets (from `wrangler secret` / `.dev.vars`) forwarded
|
|
330
|
+
* into the container's environment at instance start. Each declared name
|
|
331
|
+
* must exist on the Worker `env` — a missing one fails fast with a
|
|
332
|
+
* directed error instead of starting the container without it.
|
|
333
|
+
*/
|
|
334
|
+
secrets?: ReadonlyArray<string>;
|
|
335
|
+
/**
|
|
336
|
+
* Cloudflare **Secrets Store** secrets forwarded into the container's
|
|
337
|
+
* environment, as a map of *container env-var name → Worker Secrets Store
|
|
338
|
+
* binding name*. Each binding is resolved with its async `.get()` the first
|
|
339
|
+
* time the instance starts, then injected as that env var — e.g.
|
|
340
|
+
* `{ STRIPE_KEY: "STRIPE_SECRET" }` runs `env.STRIPE_SECRET.get()` and sets
|
|
341
|
+
* `STRIPE_KEY` inside the container. Unlike {@link ContainerConfigBase.secrets}
|
|
342
|
+
* (plain Worker text secrets), this pulls from a `secrets_store_secrets`
|
|
343
|
+
* binding. A name already used by `env`/`secrets` is rejected at authoring
|
|
344
|
+
* time; a missing binding or unreadable value fails the start. Applies
|
|
345
|
+
* to the default start (the `ctx.containers` proxy path and a bare
|
|
346
|
+
* `start()`); a persisted per-instance `start({ envVars })` replaces the env
|
|
347
|
+
* set wholesale, as it does for `env`/`secrets`. (Upstream
|
|
348
|
+
* cloudflare/containers#96.)
|
|
349
|
+
*/
|
|
350
|
+
secretsStore?: Readonly<Record<string, string>>;
|
|
351
|
+
/**
|
|
352
|
+
* Idle timeout after which the instance is put to sleep, e.g. `"5m"`,
|
|
353
|
+
* `"30s"`, or a number of seconds. Cloudflare's default is `"10m"`.
|
|
354
|
+
*/
|
|
355
|
+
sleepAfter?: number | string;
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* A container under the `default` scheduling policy: one application-wide
|
|
359
|
+
* image and instance size, set in wrangler and rolled out by Cloudflare on
|
|
360
|
+
* deploy.
|
|
361
|
+
*/
|
|
362
|
+
interface DefaultScheduledContainerConfig extends ContainerConfigBase {
|
|
363
|
+
/** Image source — a local Dockerfile path/directory or a registry reference. */
|
|
364
|
+
image: ContainerImageSource;
|
|
365
|
+
/**
|
|
366
|
+
* Resource class for each instance: a named Cloudflare instance type or a
|
|
367
|
+
* custom `{ vcpu, memoryMib, diskMb }` object.
|
|
368
|
+
*/
|
|
369
|
+
instanceType?: ContainerInstanceType;
|
|
370
|
+
/**
|
|
371
|
+
* Maximum number of concurrently *running* instances. Stopped (slept)
|
|
372
|
+
* containers don't count. Also the default pool size for `.any()`.
|
|
373
|
+
*/
|
|
374
|
+
maxInstances?: number;
|
|
375
|
+
/**
|
|
376
|
+
* Rolling-deploy tuning. `stepPercentage` is the share of instances updated
|
|
377
|
+
* per rollout step (wrangler `rollout_step_percentage`); `gracePeriodSeconds`
|
|
378
|
+
* is how long an active instance is left running before it's eligible for
|
|
379
|
+
* update (wrangler `rollout_active_grace_period`).
|
|
380
|
+
*/
|
|
381
|
+
rollout?: ContainerRollout;
|
|
382
|
+
/**
|
|
383
|
+
* Where the image and instance size are configured. `"default"` (the
|
|
384
|
+
* default) sets them once in wrangler; `"durable_object"` is the
|
|
385
|
+
* per-instance policy.
|
|
386
|
+
* Immutable once deployed: switching policies means a new container
|
|
387
|
+
* application, which replaces every running instance.
|
|
388
|
+
*/
|
|
389
|
+
schedulingPolicy?: "default";
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* A container under the `durable_object` scheduling policy (Cloudflare public
|
|
393
|
+
* beta): each instance picks its image and size when it starts, via
|
|
394
|
+
* `ctx.containers.<name>.get(id).start({ image, instanceType })`, and can save
|
|
395
|
+
* and restore its filesystem with `snapshot()` / `start({ snapshot })`.
|
|
396
|
+
* Instances keep the image they started with across deploys — there is no
|
|
397
|
+
* application-wide rollout, and no `maxInstances` cap (running instances count
|
|
398
|
+
* against the account limit).
|
|
399
|
+
*/
|
|
400
|
+
interface DurableObjectScheduledContainerConfig extends ContainerConfigBase {
|
|
401
|
+
/**
|
|
402
|
+
* The image a start uses when it names none — including the implicit start a
|
|
403
|
+
* `fetch`/`exec` triggers. Either a key of `images`
|
|
404
|
+
* or a Cloudflare-managed image such as `"cloudflare/debian-trixie"`.
|
|
405
|
+
* Without it, an instance must be started explicitly with an `image` (or a
|
|
406
|
+
* `snapshot`) before it can serve requests.
|
|
407
|
+
*/
|
|
408
|
+
image?: string;
|
|
409
|
+
/**
|
|
410
|
+
* Named images an instance can start from, keyed by the name `start({ image })`
|
|
411
|
+
* takes (wrangler `containers[].images`). Up to 100, each name 1–128
|
|
412
|
+
* characters. Updating the map does not restart running instances.
|
|
413
|
+
*/
|
|
414
|
+
images?: Readonly<Record<string, ContainerNamedImageSource>>;
|
|
415
|
+
/**
|
|
416
|
+
* The instance size a start uses when it names none. Cloudflare's runtime
|
|
417
|
+
* default is `"lite"`.
|
|
418
|
+
*/
|
|
419
|
+
instanceType?: ContainerRuntimeInstanceType;
|
|
420
|
+
/** Selects the per-instance policy. Immutable once deployed. */
|
|
421
|
+
schedulingPolicy: "durable_object";
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* `ContainerConfig` is part of the experimental `@lunora/container` API and may change without a major version bump.
|
|
425
|
+
*/
|
|
426
|
+
type ContainerConfig = DefaultScheduledContainerConfig | DurableObjectScheduledContainerConfig;
|
|
427
|
+
/**
|
|
428
|
+
* The value `defineContainer` returns: the validated config plus a brand the
|
|
429
|
+
* codegen discovery and the generated Container DO class key on.
|
|
430
|
+
*/
|
|
431
|
+
type ContainerDefinition = ContainerConfig & {
|
|
432
|
+
/** Brand marking a value as a Lunora container definition. */
|
|
433
|
+
readonly isLunoraContainer: true;
|
|
434
|
+
};
|
|
435
|
+
/**
|
|
436
|
+
* A saved container filesystem, as `snapshot()` returns it. Plain data: store
|
|
437
|
+
* it anywhere and pass it back to `start({ snapshot })`, from the same or
|
|
438
|
+
* another instance of the same container. Tied to the image it was taken
|
|
439
|
+
* from; Cloudflare keeps it 30 days, refreshed on each restore.
|
|
440
|
+
*/
|
|
441
|
+
interface ContainerSnapshot {
|
|
442
|
+
id: string;
|
|
443
|
+
name?: string;
|
|
444
|
+
/** Size in bytes. */
|
|
445
|
+
size: number;
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* A normalized image source, as written into `wrangler.jsonc`.
|
|
449
|
+
*/
|
|
450
|
+
type NormalizedContainerImage = {
|
|
451
|
+
/** Build context directory (wrangler `image_build_context`). */
|
|
452
|
+
buildContext: string;
|
|
453
|
+
/** Path to the Dockerfile (wrangler `image`). */
|
|
454
|
+
dockerfilePath: string;
|
|
455
|
+
kind: "dockerfile";
|
|
456
|
+
} | {
|
|
457
|
+
/** Railpack source directory built + pushed at deploy time. */
|
|
458
|
+
buildDir: string;
|
|
459
|
+
kind: "build";
|
|
460
|
+
} | {
|
|
461
|
+
kind: "registry";
|
|
462
|
+
/** Fully-qualified image reference (wrangler `image`). */
|
|
463
|
+
reference: string;
|
|
464
|
+
};
|
|
465
|
+
/**
|
|
466
|
+
* Cloudflare Durable Object data-residency jurisdiction. Widening union —
|
|
467
|
+
* Cloudflare adds values over time.
|
|
468
|
+
* @see https://developers.cloudflare.com/durable-objects/reference/data-location/
|
|
469
|
+
*/
|
|
470
|
+
type DurableObjectJurisdiction = "eu" | "fedramp" | "us";
|
|
471
|
+
export { BuildImageSource as B, ContainerDefinition as C, DurableObjectJurisdiction as D, NormalizedContainerImage as N, RegistryImageSource as R, SpawnResult as S, ContainerSpawnOptions as a, ContainerSnapshot as b, ContainerProcess as c, ContainerRuntimeInstanceType as d, ContainerSpawnRequest as e, DefaultScheduledContainerConfig as f, DurableObjectScheduledContainerConfig as g, ContainerImageSource as h, ContainerBackupStorage as i, ContainerConfig as j, ContainerConfigBase as k, ContainerInstanceType as l, ContainerNamedImageSource as m, ContainerReadinessCheck as n, ContainerRollout as o, CustomContainerInstanceType as p, NamedContainerInstanceType as q };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e="x-lunora-sample-errors",o=(r,s)=>r.isTraced||r.keepErrors&&s;export{e as S,o as s};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { SandboxDirectoryEntry, SandboxFileStat, DirectoryBackupRecord, S3MountInspection } from '@cloudflare/sandbox';
|
|
2
|
+
/** Options every file operation accepts. */
|
|
3
|
+
interface ContainerFileOptions {
|
|
4
|
+
/** Absolute directory a relative path is joined onto. */
|
|
5
|
+
cwd?: string;
|
|
6
|
+
/** Numeric `uid:gid` that opens the file. */
|
|
7
|
+
user?: string;
|
|
8
|
+
}
|
|
9
|
+
/** What `handle.files.writeFile` accepts. A stream is written as it arrives. */
|
|
10
|
+
type ContainerFileContent = ArrayBuffer | ArrayBufferView | ReadableStream<Uint8Array> | string;
|
|
11
|
+
/**
|
|
12
|
+
* Structured file operations on the instance's own disk (`handle.files`),
|
|
13
|
+
* through `@cloudflare/sandbox`'s `Files`. A filesystem failure rejects with a
|
|
14
|
+
* `LunoraError` whose `data.errno` is the Linux code (`ENOENT`, `EACCES`, …).
|
|
15
|
+
*/
|
|
16
|
+
interface ContainerFiles {
|
|
17
|
+
/** Create a directory; `recursive` creates parents and accepts an existing one. */
|
|
18
|
+
mkdir: (path: string, options?: ContainerFileOptions & {
|
|
19
|
+
recursive?: boolean;
|
|
20
|
+
}) => Promise<void>;
|
|
21
|
+
/** List a directory's immediate entries, without following symlinked entries. */
|
|
22
|
+
readDirectory: (path: string, options?: ContainerFileOptions) => Promise<SandboxDirectoryEntry[]>;
|
|
23
|
+
/**
|
|
24
|
+
* Stream a file out of the container. The body applies backpressure to the
|
|
25
|
+
* read. Read the body to the end or cancel it: the container is counted in
|
|
26
|
+
* flight until then, so an abandoned body keeps it from sleeping.
|
|
27
|
+
*/
|
|
28
|
+
readFile: (path: string, options?: ContainerFileOptions) => Promise<Response>;
|
|
29
|
+
/** Remove a file or symlink; `recursive` removes a directory tree, `force` ignores a missing target. */
|
|
30
|
+
remove: (path: string, options?: ContainerFileOptions & {
|
|
31
|
+
force?: boolean;
|
|
32
|
+
recursive?: boolean;
|
|
33
|
+
}) => Promise<void>;
|
|
34
|
+
/** Rename within one filesystem (`EXDEV` across filesystems; there is no copy fallback). */
|
|
35
|
+
rename: (source: string, destination: string, options?: ContainerFileOptions) => Promise<void>;
|
|
36
|
+
/** Metadata for a path, following a final symlink. */
|
|
37
|
+
stat: (path: string, options?: ContainerFileOptions) => Promise<SandboxFileStat>;
|
|
38
|
+
/** Create or truncate a file and write `content` into it. */
|
|
39
|
+
writeFile: (path: string, content: ContainerFileContent, options?: ContainerFileOptions) => Promise<void>;
|
|
40
|
+
}
|
|
41
|
+
/** Options for `handle.backup()`. */
|
|
42
|
+
interface ContainerBackupOptions {
|
|
43
|
+
/** gitignore-syntax patterns, relative to the directory, to leave out. */
|
|
44
|
+
exclude?: ReadonlyArray<string>;
|
|
45
|
+
/** Also apply `.gitignore` files inside the directory and `.git/info/exclude`. */
|
|
46
|
+
gitignore?: boolean;
|
|
47
|
+
/** A label stored with the backup. */
|
|
48
|
+
name?: string;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Credentials for an S3-compatible bucket mount, by **name**: each value is the
|
|
52
|
+
* name of a Worker secret (`wrangler secret put`) the container Durable Object
|
|
53
|
+
* reads at mount time. The keys themselves never appear in source, and the
|
|
54
|
+
* Worker signs every storage request, so they never enter the container either.
|
|
55
|
+
*/
|
|
56
|
+
interface ContainerMountCredentials {
|
|
57
|
+
/** Worker secret holding the access key id. */
|
|
58
|
+
accessKeyIdSecret: string;
|
|
59
|
+
/** Worker secret holding the secret access key. */
|
|
60
|
+
secretAccessKeySecret: string;
|
|
61
|
+
/** Worker secret holding a session token, for temporary credentials. */
|
|
62
|
+
sessionTokenSecret?: string;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* An S3-compatible bucket (R2, S3, GCS) to mount at `path` with
|
|
66
|
+
* `handle.mount()`. For R2 the endpoint is
|
|
67
|
+
* `https://<account-id>.r2.cloudflarestorage.com` with region `"auto"`, and the
|
|
68
|
+
* credentials are an R2 API token's S3 keys — an R2 bucket binding is not used.
|
|
69
|
+
*/
|
|
70
|
+
interface ContainerMountRequest {
|
|
71
|
+
access: "read-only" | "read-write";
|
|
72
|
+
bucket: string;
|
|
73
|
+
credentials: ContainerMountCredentials;
|
|
74
|
+
endpoint: string;
|
|
75
|
+
/** Mount only this key prefix. A non-empty prefix ends in `/`. */
|
|
76
|
+
keyPrefix?: string;
|
|
77
|
+
/** Absolute path inside the container to mount at. */
|
|
78
|
+
path: string;
|
|
79
|
+
region: string;
|
|
80
|
+
/** Extra s3fs options, passed through as-is. */
|
|
81
|
+
s3fsOptions?: Readonly<Record<string, boolean | number | string>>;
|
|
82
|
+
}
|
|
83
|
+
/** The sandbox operations on a named instance of a `defineContainer({ sandbox: true })` container. */
|
|
84
|
+
interface ContainerSandboxControls {
|
|
85
|
+
/**
|
|
86
|
+
* Save `directory` to the R2 bucket in the definition's `backups` and return its
|
|
87
|
+
* record — plain data to store and pass to `restore` later, here or on
|
|
88
|
+
* another instance, even one on a newer image. Pause writers in it first.
|
|
89
|
+
*/
|
|
90
|
+
backup: (directory: string, options?: ContainerBackupOptions) => Promise<DirectoryBackupRecord>;
|
|
91
|
+
/** Delete a backup's object. Deleting one that is already gone succeeds. */
|
|
92
|
+
deleteBackup: (backup: DirectoryBackupRecord) => Promise<void>;
|
|
93
|
+
/** Structured file operations on the instance's disk. */
|
|
94
|
+
files: ContainerFiles;
|
|
95
|
+
/** Report a mount path's state without changing it. */
|
|
96
|
+
inspectMount: (path: string) => Promise<S3MountInspection>;
|
|
97
|
+
/** Mount an S3-compatible bucket at `request.path`. Mounting the same settings again reuses the mount. */
|
|
98
|
+
mount: (request: ContainerMountRequest) => Promise<void>;
|
|
99
|
+
/**
|
|
100
|
+
* Replace `options.directory` (default: the directory it was taken from) with the
|
|
101
|
+
* backup's contents. The target is swapped in only after the download is
|
|
102
|
+
* verified; a rejection means it was not replaced.
|
|
103
|
+
*/
|
|
104
|
+
restore: (backup: DirectoryBackupRecord, options?: {
|
|
105
|
+
directory?: string;
|
|
106
|
+
}) => Promise<void>;
|
|
107
|
+
/** Stop access to a mount and unmount it. Never force-unmounts a busy path. */
|
|
108
|
+
unmount: (path: string) => Promise<void>;
|
|
109
|
+
}
|
|
110
|
+
export { ContainerFileOptions as C, ContainerFileContent as a, ContainerBackupOptions as b, ContainerMountRequest as c, ContainerSandboxControls as d, ContainerFiles as e, ContainerMountCredentials as f };
|