@lunora/container 1.0.0-alpha.11 → 1.0.0-alpha.13

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/otel.d.ts CHANGED
@@ -1,12 +1,16 @@
1
- /** An attribute value carried on a span or log. */
1
+ /**
2
+ * An attribute value carried on a span or log.
3
+ * @experimental
4
+ */
2
5
  type ContainerAttributeValue = boolean | number | string;
3
6
  /**
4
- * A `fetch` implementation — defaults to the runtime global. The exporter passes
5
- * an abort `signal` (for the per-request timeout) and, once the promise settles,
6
- * cancels the response `body` so Node/undici can release the socket for
7
- * keep-alive reuse instead of leaving it occupied by an unread stream. It reads
8
- * `ok`/`status` to detect a rejected export and nothing else from the response.
9
- */
7
+ * A `fetch` implementation — defaults to the runtime global. The exporter passes
8
+ * an abort `signal` (for the per-request timeout) and, once the promise settles,
9
+ * cancels the response `body` so Node/undici can release the socket for
10
+ * keep-alive reuse instead of leaving it occupied by an unread stream. It reads
11
+ * `ok`/`status` to detect a rejected export and nothing else from the response.
12
+ * @experimental
13
+ */
10
14
  type OtelFetchLike = (input: string, init: {
11
15
  body: string;
12
16
  headers: Record<string, string>;
@@ -19,7 +23,10 @@ type OtelFetchLike = (input: string, init: {
19
23
  ok: boolean;
20
24
  status: number;
21
25
  }>;
22
- /** A single span the container process asks the exporter to record. */
26
+ /**
27
+ * A single span the container process asks the exporter to record.
28
+ * @experimental
29
+ */
23
30
  interface ContainerSpanInput {
24
31
  /** Attributes attached to the span (rendered under the OTLP `attributes` list). */
25
32
  attributes?: Record<string, ContainerAttributeValue>;
@@ -35,7 +42,10 @@ interface ContainerSpanInput {
35
42
  /** Wall-clock millis when the operation started. */
36
43
  startMs: number;
37
44
  }
38
- /** A single log line the container process asks the exporter to record. */
45
+ /**
46
+ * A single log line the container process asks the exporter to record.
47
+ * @experimental
48
+ */
39
49
  interface ContainerLogInput {
40
50
  /** Attributes attached to the log record. */
41
51
  attributes?: Record<string, ContainerAttributeValue>;
@@ -46,7 +56,10 @@ interface ContainerLogInput {
46
56
  /** Wall-clock millis the line was emitted; defaults to now. */
47
57
  ts?: number;
48
58
  }
49
- /** Options for {@link createContainerTelemetry}. */
59
+ /**
60
+ * Options for {@link createContainerTelemetry}.
61
+ * @experimental
62
+ */
50
63
  interface ContainerTelemetryOptions {
51
64
  /** Base OTLP collector endpoint; defaults to the `LUNORA_OTLP_ENDPOINT` env var. */
52
65
  endpoint?: string;
@@ -63,30 +76,33 @@ interface ContainerTelemetryOptions {
63
76
  /** Bearer token sent as an `Authorization: Bearer` header; defaults to the `LUNORA_OTLP_TOKEN` env var. */
64
77
  token?: string;
65
78
  /**
66
- * W3C `traceparent` of the Worker RPC that invoked this container; defaults to
67
- * the `LUNORA_TRACEPARENT` env var. When present (and well-formed) every span
68
- * inherits its trace id and hangs off its span id, so container spans stitch
69
- * under the Worker's trace instead of forming a fresh, disconnected trace.
70
- *
71
- * `@lunora/container` stamps this trace context as the **`traceparent` request
72
- * header** on every proxied fetch (`ctx.containers.&lt;name>.…`), so a container
73
- * that serves many requests should read it per request and create a telemetry
74
- * instance scoped to that request — the trace context differs each call, so a
75
- * single process-lifetime instance can't carry it:
76
- *
77
- * ```ts
78
- * // inside the container's request handler
79
- * const telemetry = createContainerTelemetry({ traceparent: request.headers.get("traceparent") ?? undefined });
80
- * await telemetry.trace("transcode", () => transcode(job));
81
- * await telemetry.flush();
82
- * ```
83
- *
84
- * The `LUNORA_TRACEPARENT` env fallback fits a one-shot container that
85
- * processes a single job per start (the value is fixed for the process).
86
- */
79
+ * W3C `traceparent` of the Worker RPC that invoked this container; defaults to
80
+ * the `LUNORA_TRACEPARENT` env var. When present (and well-formed) every span
81
+ * inherits its trace id and hangs off its span id, so container spans stitch
82
+ * under the Worker's trace instead of forming a fresh, disconnected trace.
83
+ *
84
+ * `@lunora/container` stamps this trace context as the **`traceparent` request
85
+ * header** on every proxied fetch (`ctx.containers.&lt;name>.…`), so a container
86
+ * that serves many requests should read it per request and create a telemetry
87
+ * instance scoped to that request — the trace context differs each call, so a
88
+ * single process-lifetime instance can't carry it:
89
+ *
90
+ * ```ts
91
+ * // inside the container's request handler
92
+ * const telemetry = createContainerTelemetry({ traceparent: request.headers.get("traceparent") ?? undefined });
93
+ * await telemetry.trace("transcode", () => transcode(job));
94
+ * await telemetry.flush();
95
+ * ```
96
+ *
97
+ * The `LUNORA_TRACEPARENT` env fallback fits a one-shot container that
98
+ * processes a single job per start (the value is fixed for the process).
99
+ */
87
100
  traceparent?: string;
88
101
  }
89
- /** The exporter handle {@link createContainerTelemetry} returns. */
102
+ /**
103
+ * The exporter handle {@link createContainerTelemetry} returns.
104
+ * @experimental
105
+ */
90
106
  interface ContainerTelemetry {
91
107
  /** Record one log line (no-op when disabled). */
92
108
  emitLog: (log: ContainerLogInput) => void;
@@ -100,19 +116,20 @@ interface ContainerTelemetry {
100
116
  trace: <T>(name: string, run: () => Promise<T>, attributes?: Record<string, ContainerAttributeValue>) => Promise<T>;
101
117
  }
102
118
  /**
103
- * Create a zero-config OTLP exporter for the container process.
104
- *
105
- * ```ts
106
- * const telemetry = createContainerTelemetry(); // reads LUNORA_OTLP_ENDPOINT / _TOKEN
107
- * await telemetry.trace("transcode", () => transcode(job), { jobId: job.id });
108
- * telemetry.emitLog({ level: "info", message: "done", attributes: { jobId: job.id } });
109
- * await telemetry.flush(); // before the process exits
110
- * ```
111
- *
112
- * With no endpoint resolvable the returned exporter is disabled (`enabled ===
113
- * false`): `emitSpan`/`emitLog` no-op and `trace` still runs its work but records
114
- * nothing — so the same code runs unchanged locally and in the cloud.
115
- * @param options Exporter options; every field falls back to a `LUNORA_*` env var.
116
- */
119
+ * Create a zero-config OTLP exporter for the container process.
120
+ *
121
+ * ```ts
122
+ * const telemetry = createContainerTelemetry(); // reads LUNORA_OTLP_ENDPOINT / _TOKEN
123
+ * await telemetry.trace("transcode", () => transcode(job), { jobId: job.id });
124
+ * telemetry.emitLog({ level: "info", message: "done", attributes: { jobId: job.id } });
125
+ * await telemetry.flush(); // before the process exits
126
+ * ```
127
+ *
128
+ * With no endpoint resolvable the returned exporter is disabled (`enabled ===
129
+ * false`): `emitSpan`/`emitLog` no-op and `trace` still runs its work but records
130
+ * nothing — so the same code runs unchanged locally and in the cloud.
131
+ * @param options Exporter options; every field falls back to a `LUNORA_*` env var.
132
+ * @experimental
133
+ */
117
134
  declare const createContainerTelemetry: (options?: ContainerTelemetryOptions) => ContainerTelemetry;
118
135
  export { type ContainerAttributeValue, type ContainerLogInput, type ContainerSpanInput, type ContainerTelemetry, type ContainerTelemetryOptions, type OtelFetchLike, createContainerTelemetry };
package/dist/otel.mjs CHANGED
@@ -3,10 +3,14 @@ const OTLP_SEVERITY = {
3
3
  // DEBUG
4
4
  error: 17,
5
5
  // ERROR
6
+ fatal: 21,
7
+ // FATAL
6
8
  info: 9,
7
9
  // INFO
8
10
  log: 9,
9
11
  // INFO
12
+ trace: 1,
13
+ // TRACE
10
14
  warn: 13
11
15
  // WARN
12
16
  };
@@ -0,0 +1,281 @@
1
+ /**
2
+ * Public configuration types for `@lunora/container`.
3
+ *
4
+ * Everything in this module is pure data — no Cloudflare runtime imports — so
5
+ * it is safe to import from Node tooling (codegen, the config layer) as well
6
+ * as from worker code.
7
+ */
8
+ /**
9
+ * Named instance types Cloudflare Containers provides.
10
+ * @experimental
11
+ */
12
+ type NamedContainerInstanceType = "basic" | "lite" | "standard-1" | "standard-2" | "standard-3" | "standard-4";
13
+ /**
14
+ * A custom instance type. Cloudflare's bounds at the time of writing: up to
15
+ * 4 vCPU, 12 GiB memory, 20 GB disk, ≥ 3 GiB memory per vCPU and ≤ 2 GB disk
16
+ * per GiB memory. The config-layer validator enforces the documented ranges.
17
+ * @experimental
18
+ */
19
+ interface CustomContainerInstanceType {
20
+ /** Disk in MB. Cloudflare's default is 2000 (2 GB). */
21
+ diskMb?: number;
22
+ /** Memory in MiB. Cloudflare's default is 256. */
23
+ memoryMib?: number;
24
+ /** vCPU count. Cloudflare's default is 0.0625 (1/16 vCPU). */
25
+ vcpu?: number;
26
+ }
27
+ /**
28
+ * `ContainerInstanceType` is part of the experimental `@lunora/container` API and may change without a major version bump.
29
+ * @experimental
30
+ */
31
+ type ContainerInstanceType = CustomContainerInstanceType | NamedContainerInstanceType;
32
+ /**
33
+ * Rolling-deploy tuning for a container.
34
+ * @experimental
35
+ */
36
+ interface ContainerRollout {
37
+ /** Seconds an active instance runs before it's eligible for update (wrangler `rollout_active_grace_period`). */
38
+ gracePeriodSeconds?: number;
39
+ /** Percentage of instances updated per rollout step, 1–100 (wrangler `rollout_step_percentage`). */
40
+ stepPercentage?: number;
41
+ }
42
+ /**
43
+ * A pre-built image pulled from a registry — the Cloudflare Registry, Docker
44
+ * Hub, or Amazon ECR (the registries `wrangler deploy` supports). The
45
+ * reference must be fully qualified, e.g. `docker.io/acme/transcoder:1.4`.
46
+ * @experimental
47
+ */
48
+ interface RegistryImageSource {
49
+ registry: string;
50
+ }
51
+ /**
52
+ * A Dockerfile-less build via [Railpack](https://railpack.com): point at a
53
+ * source directory and `lunora deploy` builds an OCI image with Railpack
54
+ * (needs a BuildKit instance) and pushes it to the Cloudflare Registry before
55
+ * wrangler runs. Opt-in — the Dockerfile path is the zero-extra-deps default.
56
+ * @experimental
57
+ */
58
+ interface BuildImageSource {
59
+ build: string;
60
+ }
61
+ /**
62
+ * Where the container image comes from. A `string` is a **local path** —
63
+ * either a directory containing a `Dockerfile` (normalized to
64
+ * `&lt;dir>/Dockerfile` with the directory as the build context) or a path to
65
+ * the Dockerfile itself — while `{ registry }` is a pre-built image reference.
66
+ * @experimental
67
+ */
68
+ type ContainerImageSource = BuildImageSource | RegistryImageSource | string;
69
+ /**
70
+ * An application-level readiness probe that gates request proxying. Layered on
71
+ * top of the platform's own port/`pingEndpoint` health wait, it lets you hold
72
+ * traffic back until the app inside the container is *functionally* ready —
73
+ * migrations applied, caches warmed — which an open-port check can't see.
74
+ *
75
+ * Declarative on purpose: a `defineContainer` value stays pure data (no handler
76
+ * functions), so codegen and the config layer can read it without evaluating
77
+ * code. (Upstream cloudflare/containers#188 expresses the same idea as handler
78
+ * functions; the Lunora config is data-only, so it's modelled as descriptors.)
79
+ * @experimental
80
+ */
81
+ interface ContainerReadinessCheck {
82
+ /** HTTP path probed on the container, e.g. `"/ready"` (a leading slash is optional). */
83
+ path: string;
84
+ /** Port to probe. Defaults to {@link ContainerConfig.defaultPort}. */
85
+ port?: number;
86
+ /** HTTP status that means "ready". Defaults to `200`. */
87
+ status?: number;
88
+ }
89
+ /**
90
+ * `ContainerConfig` is part of the experimental `@lunora/container` API and may change without a major version bump.
91
+ * @experimental
92
+ */
93
+ interface ContainerConfig {
94
+ /**
95
+ * Hostnames the container may reach **even when {@link ContainerConfig.enableInternet}
96
+ * is `false`** — an egress allow-list (Cloudflare's `allowedHosts`). Glob
97
+ * patterns like `*.stripe.com` are supported. Pair with `enableInternet:
98
+ * false` to deny all egress except these hosts (the firewall pattern
99
+ * upstream issue cloudflare/containers#30 asked for). The interception path
100
+ * needs the `ContainerProxy` worker entrypoint, which codegen re-exports
101
+ * from the generated container file automatically; the named-instance
102
+ * handle's `egress` controls adjust the lists at runtime.
103
+ */
104
+ allowedHosts?: ReadonlyArray<string>;
105
+ /**
106
+ * Build-time variables for a Dockerfile/Railpack image — wrangler's
107
+ * `image_vars` (equivalent to `docker build --build-arg`). For *runtime*
108
+ * values use {@link ContainerConfig.env} / {@link ContainerConfig.secrets}.
109
+ * Ignored for a pre-built `{ registry }` image.
110
+ */
111
+ buildArgs?: Readonly<Record<string, string>>;
112
+ /**
113
+ * The port the container listens on. Worker → container requests target
114
+ * this port. Locally the Dockerfile must also `EXPOSE` it. For a
115
+ * multi-port container also declare {@link ContainerConfig.requiredPorts}
116
+ * and route per request with the handle's `.port(n)`.
117
+ */
118
+ defaultPort?: number;
119
+ /**
120
+ * Hostnames the container may **never** reach — an egress deny-list
121
+ * (Cloudflare's `deniedHosts`). Overrides everything else, including
122
+ * `enableInternet: true` and {@link ContainerConfig.allowedHosts}. Glob
123
+ * patterns like `*.evil.com` are supported.
124
+ */
125
+ deniedHosts?: ReadonlyArray<string>;
126
+ /**
127
+ * Whether the container may open outbound internet connections. Defaults
128
+ * to `true` — the platform default. Note that container egress is billed
129
+ * per GB by Cloudflare. Combine with {@link ContainerConfig.allowedHosts} /
130
+ * {@link ContainerConfig.deniedHosts} for a precise egress firewall.
131
+ */
132
+ enableInternet?: boolean;
133
+ /**
134
+ * Default command to run inside the container, overriding the image's
135
+ * `ENTRYPOINT`/`CMD` (Cloudflare's `entrypoint`). A per-start override is
136
+ * still available via the named-instance handle's `start({ entrypoint })`.
137
+ */
138
+ entrypoint?: ReadonlyArray<string>;
139
+ /**
140
+ * Static environment variables passed to the container on every start.
141
+ * For secret values use {@link ContainerConfig.secrets} instead so they
142
+ * flow through Worker Secrets rather than source code.
143
+ */
144
+ env?: Readonly<Record<string, string>>;
145
+ /**
146
+ * Hard cap on how long an instance may run, measured from start regardless
147
+ * of activity — a runaway-cost backstop on top of the idle
148
+ * {@link ContainerConfig.sleepAfter}. Same grammar as `sleepAfter`
149
+ * (`"30s"`, `"5m"`, `"1h"`, or a plain number of seconds). When it elapses,
150
+ * the `LunoraContainer.onHardTimeoutExpired` hook runs (default: `stop()`).
151
+ * (Upstream cloudflare/containers#85.)
152
+ */
153
+ hardTimeout?: number | string;
154
+ /** Image source — a local Dockerfile path/directory or a registry reference. */
155
+ image: ContainerImageSource;
156
+ /**
157
+ * Resource class for each instance: a named Cloudflare instance type or a
158
+ * custom `{ vcpu, memoryMib, diskMb }` object.
159
+ */
160
+ instanceType?: ContainerInstanceType;
161
+ /**
162
+ * Intercept the container's outbound **HTTPS** traffic so the egress
163
+ * allow/deny lists apply to TLS connections too (Cloudflare's
164
+ * `interceptHttps`). Requires the image to trust the Cloudflare CA at
165
+ * `/etc/cloudflare/certs/cloudflare-containers-ca.crt`. Defaults to `false`
166
+ * (HTTP egress is gated regardless).
167
+ */
168
+ interceptHttps?: boolean;
169
+ /**
170
+ * Key-value metadata attached to every instance for metrics/observability
171
+ * (Cloudflare's container `labels`), e.g. `{ tenant: "acme", env: "prod" }`.
172
+ * A per-start override is available via the named-instance handle's
173
+ * `start({ labels })`.
174
+ */
175
+ labels?: Readonly<Record<string, string>>;
176
+ /**
177
+ * Maximum number of concurrently *running* instances. Stopped (slept)
178
+ * containers don't count. Also the default pool size for `.any()`.
179
+ */
180
+ maxInstances?: number;
181
+ /**
182
+ * Override for the wrangler `containers[].name` identifier. Defaults to
183
+ * wrangler's own default (worker name + class name + environment).
184
+ */
185
+ name?: string;
186
+ /**
187
+ * HTTP path Cloudflare polls to decide an instance is healthy
188
+ * (Cloudflare's `pingEndpoint`). Defaults to upstream's slash-less `"ping"`;
189
+ * either `"ping"` or `"/healthz"`-style paths are accepted. Set this when
190
+ * the container exposes its readiness check under a different route.
191
+ */
192
+ pingEndpoint?: string;
193
+ /**
194
+ * Application-level readiness probes that gate request proxying: a
195
+ * `ctx.containers.&lt;name>` fetch waits until every probe responds with its
196
+ * expected status before the request reaches the container — on top of the
197
+ * platform's port/`pingEndpoint` health wait. All probes run in parallel.
198
+ * Use these for readiness an open-port check can't see (migrations applied,
199
+ * caches warm). (Upstream cloudflare/containers#188.)
200
+ */
201
+ readyOn?: ReadonlyArray<ContainerReadinessCheck>;
202
+ /**
203
+ * Ports the container must be listening on before it's considered ready
204
+ * (Cloudflare's `requiredPorts`) — for multi-port containers. Start-up
205
+ * waits for every listed port, and the handle's `.port(n)` routes a request
206
+ * to any of them; {@link ContainerConfig.defaultPort} is the target when a
207
+ * request doesn't pick one.
208
+ */
209
+ requiredPorts?: ReadonlyArray<number>;
210
+ /**
211
+ * Rolling-deploy tuning. `stepPercentage` is the share of instances updated
212
+ * per rollout step (wrangler `rollout_step_percentage`); `gracePeriodSeconds`
213
+ * is how long an active instance is left running before it's eligible for
214
+ * update (wrangler `rollout_active_grace_period`).
215
+ */
216
+ rollout?: ContainerRollout;
217
+ /**
218
+ * Names of Worker secrets (from `wrangler secret` / `.dev.vars`) forwarded
219
+ * into the container's environment at instance start. Each declared name
220
+ * must exist on the Worker `env` — a missing one fails fast with a
221
+ * directed error instead of starting the container without it.
222
+ */
223
+ secrets?: ReadonlyArray<string>;
224
+ /**
225
+ * Cloudflare **Secrets Store** secrets forwarded into the container's
226
+ * environment, as a map of *container env-var name → Worker Secrets Store
227
+ * binding name*. Each binding is resolved with its async `.get()` the first
228
+ * time the instance starts, then injected as that env var — e.g.
229
+ * `{ STRIPE_KEY: "STRIPE_SECRET" }` runs `env.STRIPE_SECRET.get()` and sets
230
+ * `STRIPE_KEY` inside the container. Unlike {@link ContainerConfig.secrets}
231
+ * (plain Worker text secrets), this pulls from a `secrets_store_secrets`
232
+ * binding. A name already used by `env`/`secrets` is rejected at authoring
233
+ * time; a missing binding or unreadable value fails the start. Applies
234
+ * to the default start (the `ctx.containers` proxy path and a bare
235
+ * `start()`); a per-instance `start({ envVars })` replaces the env set
236
+ * wholesale, as it does for `env`/`secrets`. (Upstream
237
+ * cloudflare/containers#96.)
238
+ */
239
+ secretsStore?: Readonly<Record<string, string>>;
240
+ /**
241
+ * Idle timeout after which the instance is put to sleep, e.g. `"5m"`,
242
+ * `"30s"`, or a number of seconds. Cloudflare's default is `"10m"`.
243
+ */
244
+ sleepAfter?: number | string;
245
+ }
246
+ /**
247
+ * The value `defineContainer` returns: the validated config plus a brand the
248
+ * codegen discovery and the generated Container DO class key on.
249
+ * @experimental
250
+ */
251
+ interface ContainerDefinition extends ContainerConfig {
252
+ /** Brand marking a value as a Lunora container definition. */
253
+ readonly isLunoraContainer: true;
254
+ }
255
+ /**
256
+ * A normalized image source, as written into `wrangler.jsonc`.
257
+ * @experimental
258
+ */
259
+ type NormalizedContainerImage = {
260
+ /** Build context directory (wrangler `image_build_context`). */
261
+ buildContext: string;
262
+ /** Path to the Dockerfile (wrangler `image`). */
263
+ dockerfilePath: string;
264
+ kind: "dockerfile";
265
+ } | {
266
+ /** Railpack source directory built + pushed at deploy time. */
267
+ buildDir: string;
268
+ kind: "build";
269
+ } | {
270
+ kind: "registry";
271
+ /** Fully-qualified image reference (wrangler `image`). */
272
+ reference: string;
273
+ };
274
+ /**
275
+ * Cloudflare Durable Object data-residency jurisdiction. Widening union —
276
+ * Cloudflare adds values over time.
277
+ * @see https://developers.cloudflare.com/durable-objects/reference/data-location/
278
+ * @experimental
279
+ */
280
+ type DurableObjectJurisdiction = "eu" | "fedramp" | "us";
281
+ export { BuildImageSource as B, ContainerConfig as C, DurableObjectJurisdiction as D, NormalizedContainerImage as N, RegistryImageSource as R, ContainerDefinition as a, ContainerImageSource as b, ContainerInstanceType as c, ContainerReadinessCheck as d, ContainerRollout as e, CustomContainerInstanceType as f, NamedContainerInstanceType as g };