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

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/LICENSE.md CHANGED
@@ -103,3 +103,29 @@ Unless required by applicable law or agreed to in writing, software distributed
103
103
  under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
104
104
  CONDITIONS OF ANY KIND, either express or implied. See the License for the
105
105
  specific language governing permissions and limitations under the License.
106
+
107
+ <!-- DEPENDENCIES -->
108
+
109
+ # Licenses of bundled dependencies
110
+ The published @lunora/container artifact additionally contains code with the following licenses:
111
+ MIT OR Apache-2.0
112
+
113
+ # Bundled dependencies:
114
+ ## @cloudflare/containers
115
+ License: MIT OR Apache-2.0
116
+ Repository: git+https://github.com/cloudflare/containers.git
117
+
118
+ <!-- /DEPENDENCIES -->
119
+
120
+ <!-- TYPE_DEPENDENCIES -->
121
+
122
+ # Licenses of bundled types
123
+ The published @lunora/container artifact additionally contains code with the following licenses:
124
+ MIT OR Apache-2.0
125
+
126
+ # Bundled types:
127
+ ## @cloudflare/containers
128
+ License: MIT OR Apache-2.0
129
+ Repository: git+https://github.com/cloudflare/containers.git
130
+
131
+ <!-- /TYPE_DEPENDENCIES -->
package/README.md CHANGED
@@ -66,6 +66,7 @@ export const transcoder = defineContainer({
66
66
  maxInstances: 5,
67
67
  sleepAfter: "5m",
68
68
  secrets: ["TRANSCODER_API_KEY"], // forwarded from Worker secrets / .dev.vars
69
+ labels: { team: "media" }, // metadata attached to every instance for metrics/observability
69
70
  });
70
71
  ```
71
72
 
@@ -89,10 +90,95 @@ export const transcode = action.input({ videoId: v.id("videos") }).action(async
89
90
  });
90
91
  ```
91
92
 
92
- `ctx.containers` is action-only (container calls are external I/O, like `ctx.fetch`); `.get(name)` handles also expose `start`/`stop`/`destroy`/`getState` lifecycle control.
93
+ `.get()` and `.any()` retry the **same** instance through a cold start — when a request lands while Cloudflare is still provisioning (a `503` "no instance", `500` "Failed to start", `429`, or "not listening"), they back off and retry (default 3 attempts) so the provisioning race never reaches your handler. Genuine app `5xx`s pass straight through. Tune or disable per call with `.get(id, { attempts, backoffMs })` (a pre-built `Request` is sent once and not retried, since its body may not be replayable).
94
+
95
+ `ctx.containers` is action-only (container calls are external I/O, like `ctx.fetch`); `.get(name)` handles also expose `start`/`stop`/`destroy`/`getState` lifecycle control plus `renewActivityTimeout()` and `egress.*` (adjust the allow/deny lists at runtime). HTTP requests and WebSocket frames already keep a busy container awake automatically; `renewActivityTimeout()` is the escape hatch for non-HTTP/non-WS activity.
93
96
 
94
97
  The config layer (`lunora dev` / `lunora deploy`) reconciles the wrangler `containers[]` entry, the `CONTAINER_*` Durable Object binding, and the SQLite-class migration automatically; `wrangler deploy` builds the Dockerfile with local Docker and pushes it to the Cloudflare Registry.
95
98
 
99
+ ### Multi-port containers
100
+
101
+ Declare every port the container must be listening on with `requiredPorts` (start-up waits for all of them); `defaultPort` is the target when a request doesn't pick one. Route a single request to another port with `.port(n)` — it composes with `.get()`, `.any()`, and `.pool()`:
102
+
103
+ ```ts
104
+ export const app = defineContainer({
105
+ image: "./containers/app",
106
+ defaultPort: 8080,
107
+ requiredPorts: [8080, 9090], // app + admin
108
+ });
109
+
110
+ // in an action:
111
+ await ctx.containers.app.get(tenantId).fetch("/work"); // → 8080
112
+ await ctx.containers.app.get(tenantId).port(9090).fetch("/admin"); // → 9090
113
+ ```
114
+
115
+ ### Build-time args
116
+
117
+ `env` and `secrets` are runtime values; for build-time `docker build --build-arg` values (wrangler `image_vars`, exposed to the Dockerfile as `ARG`) use `buildArgs`. They apply only to an image Lunora builds and are ignored for a pre-built `{ registry }` image.
118
+
119
+ ```ts
120
+ export const worker = defineContainer({
121
+ image: "./containers/worker",
122
+ buildArgs: { NODE_VERSION: "22", BUILD_TARGET: "production" },
123
+ });
124
+ ```
125
+
126
+ ### Secrets and Secrets Store
127
+
128
+ `secrets` forwards plain Worker secrets into the container env; `secretsStore` maps a _container env-var name → Cloudflare [Secrets Store](https://developers.cloudflare.com/secrets-store/) binding name_ and resolves each with its async `.get()` at first start (memoised). A collision with `env`/`secrets` is rejected at authoring time; a missing binding fails the start — the same fail-closed stance as `secrets`. Like `env`/`secrets`, these injected values only apply to implicit starts or a bare `start()`; a per-instance `start({ envVars })` replaces the env set wholesale (and skips Secrets Store resolution entirely).
129
+
130
+ ```ts
131
+ export const worker = defineContainer({
132
+ image: "./containers/worker",
133
+ secrets: ["TRANSCODER_API_KEY"], // plain Worker secret → same-named env var
134
+ secretsStore: { STRIPE_KEY: "STRIPE_SECRET" }, // env.STRIPE_SECRET.get() → STRIPE_KEY
135
+ });
136
+ ```
137
+
138
+ ### Egress firewall
139
+
140
+ Pair `enableInternet: false` with an `allowedHosts` allow-list (or layer a `deniedHosts` deny-list that overrides everything) to constrain a container's outbound traffic; `interceptHttps: true` extends the lists to TLS connections (the image must trust the Cloudflare CA). Codegen re-exports the `ContainerProxy` worker entrypoint the interception path needs automatically.
141
+
142
+ ```ts
143
+ export const fetcher = defineContainer({
144
+ image: "./containers/fetcher",
145
+ enableInternet: false,
146
+ allowedHosts: ["*.stripe.com", "api.github.com"],
147
+ deniedHosts: ["*.evil.com"],
148
+ });
149
+
150
+ // tighten or relax one running instance at runtime:
151
+ await ctx.containers.fetcher.get(tenantId).egress.allow("hooks.slack.com");
152
+ ```
153
+
154
+ For advanced egress rewriting in worker code, `@lunora/container/do` re-exports Cloudflare's custom outbound-handler types (`OutboundHandler`, `OutboundHandlers`, `outboundParams`) — wire them onto a hand-authored `LunoraContainer` subclass to inject auth, route, or mock a container's outbound calls.
155
+
156
+ ### Readiness gating
157
+
158
+ The platform health check waits for an open port, not necessarily a _ready_ app. `readyOn` adds application-level probes that gate request proxying: a `ctx.containers.<name>` fetch holds until every probe responds with its expected status, so callers never hit a container still applying migrations or warming caches. Probes are declarative data (path + optional `port`/`status`), run in parallel at start, and probe the container's TCP port directly.
159
+
160
+ ```ts
161
+ export const api = defineContainer({
162
+ image: "./containers/api",
163
+ defaultPort: 8080,
164
+ readyOn: [
165
+ { path: "/ready" }, // expect 200 on defaultPort
166
+ { path: "/live", port: 9090, status: 204 }, // own port + expected status
167
+ ],
168
+ });
169
+ ```
170
+
171
+ ### Hard timeout
172
+
173
+ `sleepAfter` caps _idle_ time; `hardTimeout` caps _total_ lifetime — a runaway-cost backstop measured from start, regardless of activity (same grammar as `sleepAfter`). When it elapses the generated class's `onHardTimeoutExpired` hook runs (default: `stop()`); the timer is run-generation-stamped so a stale timer from a slept/crashed run can't kill a fresh one.
174
+
175
+ ```ts
176
+ export const job = defineContainer({
177
+ image: "./containers/job",
178
+ hardTimeout: "1h", // never run longer than an hour, busy or not
179
+ });
180
+ ```
181
+
96
182
  ### Calling Lunora from inside a container
97
183
 
98
184
  Container code calls back into your app's functions with the bridge client (any JS runtime), over the Worker's HTTP RPC endpoint:
@@ -118,6 +204,16 @@ Secure the bridge in `resolveIdentity`: read `request.headers.get("authorization
118
204
 
119
205
  > This README covers the basics. For the full API, options, and guides, see the **[documentation](https://lunora.sh/docs/addons/containers)**.
120
206
 
207
+ ### Known platform limitations
208
+
209
+ Some constraints live in Cloudflare Containers itself (open issues on [`cloudflare/containers`](https://github.com/cloudflare/containers/issues)). Lunora papers over what it can — cold-start retry and WebSocket keep-alive — and surfaces the rest:
210
+
211
+ - **No autoscaling / location-aware routing** — pools are fixed-size and pick uniformly at random ([#226](https://github.com/cloudflare/containers/issues/226)).
212
+ - **Ephemeral disk; no FUSE / tmpfs / some `node:net` modes** — persist to [`@lunora/storage`](https://www.npmjs.com/package/@lunora/storage) (R2) ([#112](https://github.com/cloudflare/containers/issues/112), [#160](https://github.com/cloudflare/containers/issues/160), [#67](https://github.com/cloudflare/containers/issues/67)).
213
+ - **Egress interception is HTTP-first** — HTTPS needs `interceptHttps`; raw gRPC isn't interceptable yet ([#195](https://github.com/cloudflare/containers/issues/195)).
214
+ - **Long jobs can be terminated on rollout** — use `hardTimeout` and make work resumable ([#138](https://github.com/cloudflare/containers/issues/138)).
215
+ - **Local dev can't pull from the Cloudflare Registry** — build from a local Dockerfile ([#155](https://github.com/cloudflare/containers/issues/155)).
216
+
121
217
  ## Related
122
218
 
123
219
  - [`@lunora/server`](https://www.npmjs.com/package/@lunora/server) — defines the actions that drive containers via `ctx.containers`.