@lunora/container 1.0.0-alpha.3 → 1.0.0-alpha.31
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 +26 -0
- package/README.md +99 -1
- package/dist/bridge.d.mts +51 -35
- package/dist/bridge.d.ts +51 -35
- package/dist/bridge.mjs +1 -76
- package/dist/do/index.d.mts +580 -45
- package/dist/do/index.d.ts +580 -45
- package/dist/do/index.mjs +1 -138
- package/dist/index.d.mts +367 -114
- package/dist/index.d.ts +367 -114
- package/dist/index.mjs +1 -2
- package/dist/otel.d.mts +161 -0
- package/dist/otel.d.ts +161 -0
- package/dist/otel.mjs +1 -0
- package/dist/packem_shared/ContainerProxy-fTW_pXWY.mjs +27 -0
- package/dist/packem_shared/containerBindingName-D01FopQt.mjs +1 -0
- package/dist/packem_shared/createContainerContext-C8pmlFAX.mjs +1 -0
- package/dist/packem_shared/jurisdiction-DtE9s70w.mjs +1 -0
- package/dist/packem_shared/jurisdiction.d-DeQ3rtYK.d.mts +281 -0
- package/dist/packem_shared/jurisdiction.d-DeQ3rtYK.d.ts +281 -0
- package/package.json +6 -2
- package/dist/packem_shared/containerBindingName-BGdSdFNA.mjs +0 -116
- package/dist/packem_shared/createContainerContext-CTpyUQ4J.mjs +0 -133
- package/dist/packem_shared/types.d-D2l2SYol.d.mts +0 -140
- package/dist/packem_shared/types.d-D2l2SYol.d.ts +0 -140
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
const NAMED_INSTANCE_TYPES = /* @__PURE__ */ new Set(["basic", "lite", "standard-1", "standard-2", "standard-3", "standard-4"]);
|
|
2
|
-
const ENV_NAME_PATTERN = /^[A-Z_]\w*$/i;
|
|
3
|
-
const SLEEP_AFTER_PATTERN = /^\d+[smh]$/;
|
|
4
|
-
const basename = (path) => {
|
|
5
|
-
const trimmed = path.endsWith("/") ? path.slice(0, -1) : path;
|
|
6
|
-
const separatorIndex = trimmed.lastIndexOf("/");
|
|
7
|
-
return separatorIndex === -1 ? trimmed : trimmed.slice(separatorIndex + 1);
|
|
8
|
-
};
|
|
9
|
-
const dirname = (path) => {
|
|
10
|
-
const separatorIndex = path.lastIndexOf("/");
|
|
11
|
-
return separatorIndex === -1 ? "." : path.slice(0, separatorIndex) || "/";
|
|
12
|
-
};
|
|
13
|
-
const normalizeContainerImage = (image) => {
|
|
14
|
-
if (typeof image !== "string") {
|
|
15
|
-
if ("build" in image) {
|
|
16
|
-
const buildDirectory = image.build.endsWith("/") ? image.build.slice(0, -1) : image.build;
|
|
17
|
-
return { buildDir: buildDirectory, kind: "build" };
|
|
18
|
-
}
|
|
19
|
-
return { kind: "registry", reference: image.registry };
|
|
20
|
-
}
|
|
21
|
-
if (basename(image).startsWith("Dockerfile")) {
|
|
22
|
-
return { buildContext: dirname(image), dockerfilePath: image, kind: "dockerfile" };
|
|
23
|
-
}
|
|
24
|
-
const context = image.endsWith("/") ? image.slice(0, -1) : image;
|
|
25
|
-
return { buildContext: context, dockerfilePath: `${context}/Dockerfile`, kind: "dockerfile" };
|
|
26
|
-
};
|
|
27
|
-
const containerClassName = (exportName) => `${exportName.charAt(0).toUpperCase()}${exportName.slice(1)}Container`;
|
|
28
|
-
const containerBindingName = (exportName) => `CONTAINER_${exportName.replaceAll(/(?<=[a-z0-9])(?=[A-Z])/g, "_").toUpperCase()}`;
|
|
29
|
-
const containerBuildTag = (exportName) => `lunora-${exportName.replaceAll(/(?<=[a-z0-9])(?=[A-Z])/g, "-").toLowerCase()}:build`;
|
|
30
|
-
const assertValidImage = (image) => {
|
|
31
|
-
if (typeof image === "string") {
|
|
32
|
-
if (image.length === 0) {
|
|
33
|
-
throw new TypeError("defineContainer: `image` must be a non-empty path or a { registry } reference");
|
|
34
|
-
}
|
|
35
|
-
if (image.includes(":")) {
|
|
36
|
-
throw new TypeError(
|
|
37
|
-
`defineContainer: \`image\` string "${image}" looks like a registry reference — pass it as { registry: "${image}" } instead. Plain strings are local Dockerfile paths.`
|
|
38
|
-
);
|
|
39
|
-
}
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
if ("build" in image) {
|
|
43
|
-
if (typeof image.build !== "string" || image.build.length === 0) {
|
|
44
|
-
throw new TypeError("defineContainer: `image.build` must be a non-empty source directory for Railpack to build");
|
|
45
|
-
}
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
if (typeof image.registry !== "string" || image.registry.length === 0) {
|
|
49
|
-
throw new TypeError("defineContainer: `image.registry` must be a non-empty fully-qualified image reference");
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
const assertValidEnvAndSecrets = (config) => {
|
|
53
|
-
for (const name of Object.keys(config.env ?? {})) {
|
|
54
|
-
if (!ENV_NAME_PATTERN.test(name)) {
|
|
55
|
-
throw new TypeError(`defineContainer: env variable name "${name}" is not a valid environment variable name`);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
for (const name of Object.keys(config.buildArgs ?? {})) {
|
|
59
|
-
if (!ENV_NAME_PATTERN.test(name)) {
|
|
60
|
-
throw new TypeError(`defineContainer: buildArg name "${name}" is not a valid environment variable name`);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
const envNames = new Set(Object.keys(config.env ?? {}));
|
|
64
|
-
for (const secret of config.secrets ?? []) {
|
|
65
|
-
if (!ENV_NAME_PATTERN.test(secret)) {
|
|
66
|
-
throw new TypeError(`defineContainer: secret name "${secret}" is not a valid environment variable name`);
|
|
67
|
-
}
|
|
68
|
-
if (envNames.has(secret)) {
|
|
69
|
-
throw new TypeError(
|
|
70
|
-
`defineContainer: "${secret}" is declared in both \`env\` and \`secrets\` — a secret would silently overwrite the static env value; pick one`
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
const defineContainer = (config) => {
|
|
76
|
-
assertValidImage(config.image);
|
|
77
|
-
if (config.defaultPort !== void 0 && (!Number.isInteger(config.defaultPort) || config.defaultPort < 1 || config.defaultPort > 65535)) {
|
|
78
|
-
throw new TypeError(`defineContainer: \`defaultPort\` must be an integer in 1–65535 (got ${String(config.defaultPort)})`);
|
|
79
|
-
}
|
|
80
|
-
const stepPercentage = config.rollout?.stepPercentage;
|
|
81
|
-
if (stepPercentage !== void 0 && (!Number.isInteger(stepPercentage) || stepPercentage < 1 || stepPercentage > 100)) {
|
|
82
|
-
throw new TypeError(`defineContainer: \`rollout.stepPercentage\` must be an integer in 1–100 (got ${String(stepPercentage)})`);
|
|
83
|
-
}
|
|
84
|
-
if (config.maxInstances !== void 0 && (!Number.isInteger(config.maxInstances) || config.maxInstances < 1)) {
|
|
85
|
-
throw new TypeError(`defineContainer: \`maxInstances\` must be a positive integer (got ${String(config.maxInstances)})`);
|
|
86
|
-
}
|
|
87
|
-
if (typeof config.instanceType === "string" && !NAMED_INSTANCE_TYPES.has(config.instanceType)) {
|
|
88
|
-
throw new TypeError(
|
|
89
|
-
`defineContainer: unknown \`instanceType\` "${config.instanceType}" — use one of ${[...NAMED_INSTANCE_TYPES].join(", ")}, or a custom { vcpu, memoryMib, diskMb } object`
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
if (typeof config.sleepAfter === "string" && !SLEEP_AFTER_PATTERN.test(config.sleepAfter)) {
|
|
93
|
-
throw new TypeError(
|
|
94
|
-
`defineContainer: \`sleepAfter\` string "${config.sleepAfter}" must be a number of seconds followed by a unit, e.g. "30s", "5m", or "1h"`
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
assertValidEnvAndSecrets(config);
|
|
98
|
-
return { ...config, isLunoraContainer: true };
|
|
99
|
-
};
|
|
100
|
-
const isContainerDefinition = (value) => typeof value === "object" && value !== null && value.isLunoraContainer === true;
|
|
101
|
-
const resolveContainerEnvVariables = (definition, workerEnv, exportName) => {
|
|
102
|
-
const resolved = { ...definition.env };
|
|
103
|
-
for (const secret of definition.secrets ?? []) {
|
|
104
|
-
const value = workerEnv[secret];
|
|
105
|
-
if (typeof value !== "string") {
|
|
106
|
-
const label = exportName === void 0 ? "container" : `container "${exportName}"`;
|
|
107
|
-
throw new Error(
|
|
108
|
-
`${label}: declared secret "${secret}" is not set on the Worker environment. Add it to .dev.vars for local dev and run \`wrangler secret put ${secret}\` for production.`
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
|
-
resolved[secret] = value;
|
|
112
|
-
}
|
|
113
|
-
return resolved;
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
export { containerBindingName, containerBuildTag, containerClassName, defineContainer, isContainerDefinition, normalizeContainerImage, resolveContainerEnvVariables as resolveContainerEnvVars };
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
const applyJurisdiction = (namespace, jurisdiction) => {
|
|
2
|
-
if (jurisdiction === void 0) {
|
|
3
|
-
return namespace;
|
|
4
|
-
}
|
|
5
|
-
if (typeof namespace.jurisdiction !== "function") {
|
|
6
|
-
throw new TypeError(
|
|
7
|
-
`@lunora/container: Durable Object namespace does not support jurisdiction("${jurisdiction}") — update @cloudflare/workers-types or remove the jurisdiction option`
|
|
8
|
-
);
|
|
9
|
-
}
|
|
10
|
-
return namespace.jurisdiction(jurisdiction);
|
|
11
|
-
};
|
|
12
|
-
const DEFAULT_POOL_SIZE = 3;
|
|
13
|
-
const DEFAULT_MAX_BACKOFF_MS = 3e4;
|
|
14
|
-
const toRequest = (input, init) => {
|
|
15
|
-
if (typeof input === "string" && input.startsWith("/")) {
|
|
16
|
-
return new Request(`http://container${input}`, init);
|
|
17
|
-
}
|
|
18
|
-
return new Request(input, init);
|
|
19
|
-
};
|
|
20
|
-
const handleFor = (namespace, instanceName) => {
|
|
21
|
-
return {
|
|
22
|
-
fetch: async (input, init) => namespace.get(namespace.idFromName(instanceName)).fetch(toRequest(input, init))
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
const lifecycleCall = async (stub, method, binding, argument) => {
|
|
26
|
-
const rpc = stub[method];
|
|
27
|
-
if (typeof rpc !== "function") {
|
|
28
|
-
throw new TypeError(`ctx.containers: the "${binding}" container DO does not expose ${method}() — is @lunora/container/do up to date?`);
|
|
29
|
-
}
|
|
30
|
-
return rpc(argument);
|
|
31
|
-
};
|
|
32
|
-
const instanceHandleFor = (namespace, spec, instanceName) => {
|
|
33
|
-
const stub = () => namespace.get(namespace.idFromName(instanceName));
|
|
34
|
-
return {
|
|
35
|
-
destroy: async () => lifecycleCall(stub(), "destroy", spec.binding),
|
|
36
|
-
fetch: async (input, init) => stub().fetch(toRequest(input, init)),
|
|
37
|
-
getState: async () => lifecycleCall(stub(), "getState", spec.binding),
|
|
38
|
-
start: async (options) => lifecycleCall(stub(), "start", spec.binding, options),
|
|
39
|
-
stop: async (signal) => lifecycleCall(stub(), "stop", spec.binding, signal)
|
|
40
|
-
};
|
|
41
|
-
};
|
|
42
|
-
const randomPoolName = (size) => (
|
|
43
|
-
// eslint-disable-next-line sonarjs/pseudo-random -- load-balancing pick across interchangeable instances, not a security decision
|
|
44
|
-
`pool-${String(Math.floor(Math.random() * size))}`
|
|
45
|
-
);
|
|
46
|
-
const sleep = async (ms) => {
|
|
47
|
-
if (ms <= 0) {
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
await new Promise((resolve) => {
|
|
51
|
-
setTimeout(resolve, ms);
|
|
52
|
-
});
|
|
53
|
-
};
|
|
54
|
-
const retryOnServerError = (response) => response.status >= 500;
|
|
55
|
-
const poolHandleFor = (namespace, spec, options = {}) => {
|
|
56
|
-
const size = options.size ?? spec.maxInstances ?? DEFAULT_POOL_SIZE;
|
|
57
|
-
const attempts = Math.max(1, options.attempts ?? 3);
|
|
58
|
-
const baseBackoff = options.backoffMs ?? 100;
|
|
59
|
-
const maxBackoff = options.maxBackoffMs ?? DEFAULT_MAX_BACKOFF_MS;
|
|
60
|
-
const shouldRetry = options.retryOn ?? retryOnServerError;
|
|
61
|
-
return {
|
|
62
|
-
fetch: async (input, init) => {
|
|
63
|
-
let lastError;
|
|
64
|
-
for (let attempt = 0; attempt < attempts; attempt += 1) {
|
|
65
|
-
if (attempt > 0) {
|
|
66
|
-
await sleep(Math.min(baseBackoff * 2 ** (attempt - 1), maxBackoff));
|
|
67
|
-
}
|
|
68
|
-
const request = toRequest(input, init);
|
|
69
|
-
try {
|
|
70
|
-
const response = await namespace.get(namespace.idFromName(randomPoolName(size))).fetch(request);
|
|
71
|
-
if (attempt === attempts - 1 || !shouldRetry(response)) {
|
|
72
|
-
return response;
|
|
73
|
-
}
|
|
74
|
-
} catch (error) {
|
|
75
|
-
lastError = error;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
throw lastError instanceof Error ? lastError : new Error(`ctx.containers.${spec.exportName}.pool(): all ${String(attempts)} attempts failed`);
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
};
|
|
82
|
-
const accessorFor = (namespace, spec) => {
|
|
83
|
-
return {
|
|
84
|
-
any: (count) => handleFor(namespace, randomPoolName(count ?? spec.maxInstances ?? DEFAULT_POOL_SIZE)),
|
|
85
|
-
get: (name) => instanceHandleFor(namespace, spec, name),
|
|
86
|
-
pool: (options) => poolHandleFor(namespace, spec, options)
|
|
87
|
-
};
|
|
88
|
-
};
|
|
89
|
-
const missingBindingAccessor = (spec) => {
|
|
90
|
-
const fail = () => {
|
|
91
|
-
throw new Error(
|
|
92
|
-
`ctx.containers.${spec.exportName}: no "${spec.binding}" Durable Object binding found. Run \`lunora dev\` (or \`lunora deploy\`) to reconcile wrangler.jsonc, and make sure the worker entry re-exports the generated container classes.`
|
|
93
|
-
);
|
|
94
|
-
};
|
|
95
|
-
return { any: fail, get: fail, pool: fail };
|
|
96
|
-
};
|
|
97
|
-
const createContainerContext = (env, specs, jurisdiction) => {
|
|
98
|
-
const containers = {};
|
|
99
|
-
for (const spec of specs) {
|
|
100
|
-
const binding = env[spec.binding];
|
|
101
|
-
containers[spec.exportName] = binding && typeof binding.idFromName === "function" && typeof binding.get === "function" ? accessorFor(applyJurisdiction(binding, jurisdiction), spec) : missingBindingAccessor(spec);
|
|
102
|
-
}
|
|
103
|
-
return containers;
|
|
104
|
-
};
|
|
105
|
-
const createContainerTestContext = (handlers) => {
|
|
106
|
-
const containers = {};
|
|
107
|
-
for (const [exportName, handler] of Object.entries(handlers)) {
|
|
108
|
-
const testHandleFor = (instanceName) => {
|
|
109
|
-
return {
|
|
110
|
-
fetch: async (input, init) => handler(toRequest(input, init), { name: instanceName })
|
|
111
|
-
};
|
|
112
|
-
};
|
|
113
|
-
const testInstanceHandleFor = (instanceName) => {
|
|
114
|
-
return {
|
|
115
|
-
...testHandleFor(instanceName),
|
|
116
|
-
destroy: () => Promise.resolve(),
|
|
117
|
-
getState: () => Promise.resolve({ lastChange: 0 }),
|
|
118
|
-
start: () => Promise.resolve(),
|
|
119
|
-
stop: () => Promise.resolve()
|
|
120
|
-
};
|
|
121
|
-
};
|
|
122
|
-
containers[exportName] = {
|
|
123
|
-
any: () => testHandleFor("pool-0"),
|
|
124
|
-
get: (name) => testInstanceHandleFor(name),
|
|
125
|
-
// The double doesn't simulate failure/retry — pool() just routes to
|
|
126
|
-
// the handler like any other call, so tests stay deterministic.
|
|
127
|
-
pool: () => testHandleFor("pool-0")
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
return containers;
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
export { createContainerContext, createContainerTestContext };
|
|
@@ -1,140 +0,0 @@
|
|
|
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
|
-
/** Named instance types Cloudflare Containers provides. */
|
|
9
|
-
type NamedContainerInstanceType = "basic" | "lite" | "standard-1" | "standard-2" | "standard-3" | "standard-4";
|
|
10
|
-
/**
|
|
11
|
-
* A custom instance type. Cloudflare's bounds at the time of writing: up to
|
|
12
|
-
* 4 vCPU, 12 GiB memory, 20 GB disk, ≥ 3 GiB memory per vCPU and ≤ 2 GB disk
|
|
13
|
-
* per GiB memory. The config-layer validator enforces the documented ranges.
|
|
14
|
-
*/
|
|
15
|
-
interface CustomContainerInstanceType {
|
|
16
|
-
/** Disk in MB. Cloudflare's default is 2000 (2 GB). */
|
|
17
|
-
diskMb?: number;
|
|
18
|
-
/** Memory in MiB. Cloudflare's default is 256. */
|
|
19
|
-
memoryMib?: number;
|
|
20
|
-
/** vCPU count. Cloudflare's default is 0.0625 (1/16 vCPU). */
|
|
21
|
-
vcpu?: number;
|
|
22
|
-
}
|
|
23
|
-
type ContainerInstanceType = CustomContainerInstanceType | NamedContainerInstanceType;
|
|
24
|
-
/** Rolling-deploy tuning for a container. */
|
|
25
|
-
interface ContainerRollout {
|
|
26
|
-
/** Seconds an active instance runs before it's eligible for update (wrangler `rollout_active_grace_period`). */
|
|
27
|
-
gracePeriodSeconds?: number;
|
|
28
|
-
/** Percentage of instances updated per rollout step, 1–100 (wrangler `rollout_step_percentage`). */
|
|
29
|
-
stepPercentage?: number;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* A pre-built image pulled from a registry — the Cloudflare Registry, Docker
|
|
33
|
-
* Hub, or Amazon ECR (the registries `wrangler deploy` supports). The
|
|
34
|
-
* reference must be fully qualified, e.g. `docker.io/acme/transcoder:1.4`.
|
|
35
|
-
*/
|
|
36
|
-
interface RegistryImageSource {
|
|
37
|
-
registry: string;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* A Dockerfile-less build via [Railpack](https://railpack.com): point at a
|
|
41
|
-
* source directory and `lunora deploy` builds an OCI image with Railpack
|
|
42
|
-
* (needs a BuildKit instance) and pushes it to the Cloudflare Registry before
|
|
43
|
-
* wrangler runs. Opt-in — the Dockerfile path is the zero-extra-deps default.
|
|
44
|
-
*/
|
|
45
|
-
interface BuildImageSource {
|
|
46
|
-
build: string;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Where the container image comes from. A `string` is a **local path** —
|
|
50
|
-
* either a directory containing a `Dockerfile` (normalized to
|
|
51
|
-
* `<dir>/Dockerfile` with the directory as the build context) or a path to
|
|
52
|
-
* the Dockerfile itself — while `{ registry }` is a pre-built image reference.
|
|
53
|
-
*/
|
|
54
|
-
type ContainerImageSource = BuildImageSource | RegistryImageSource | string;
|
|
55
|
-
interface ContainerConfig {
|
|
56
|
-
/**
|
|
57
|
-
* Build-time variables for a Dockerfile/Railpack image — wrangler's
|
|
58
|
-
* `image_vars` (equivalent to `docker build --build-arg`). For *runtime*
|
|
59
|
-
* values use {@link ContainerConfig.env} / {@link ContainerConfig.secrets}.
|
|
60
|
-
* Ignored for a pre-built `{ registry }` image.
|
|
61
|
-
*/
|
|
62
|
-
buildArgs?: Readonly<Record<string, string>>;
|
|
63
|
-
/**
|
|
64
|
-
* The port the container listens on. Worker → container requests target
|
|
65
|
-
* this port. Locally the Dockerfile must also `EXPOSE` it.
|
|
66
|
-
*/
|
|
67
|
-
defaultPort?: number;
|
|
68
|
-
/**
|
|
69
|
-
* Whether the container may open outbound internet connections. Defaults
|
|
70
|
-
* to `true` — the platform default. Note that container egress is billed
|
|
71
|
-
* per GB by Cloudflare.
|
|
72
|
-
*/
|
|
73
|
-
enableInternet?: boolean;
|
|
74
|
-
/**
|
|
75
|
-
* Static environment variables passed to the container on every start.
|
|
76
|
-
* For secret values use {@link ContainerConfig.secrets} instead so they
|
|
77
|
-
* flow through Worker Secrets rather than source code.
|
|
78
|
-
*/
|
|
79
|
-
env?: Readonly<Record<string, string>>;
|
|
80
|
-
/** Image source — a local Dockerfile path/directory or a registry reference. */
|
|
81
|
-
image: ContainerImageSource;
|
|
82
|
-
/**
|
|
83
|
-
* Resource class for each instance: a named Cloudflare instance type or a
|
|
84
|
-
* custom `{ vcpu, memoryMib, diskMb }` object.
|
|
85
|
-
*/
|
|
86
|
-
instanceType?: ContainerInstanceType;
|
|
87
|
-
/**
|
|
88
|
-
* Maximum number of concurrently *running* instances. Stopped (slept)
|
|
89
|
-
* containers don't count. Also the default pool size for `.any()`.
|
|
90
|
-
*/
|
|
91
|
-
maxInstances?: number;
|
|
92
|
-
/**
|
|
93
|
-
* Override for the wrangler `containers[].name` identifier. Defaults to
|
|
94
|
-
* wrangler's own default (worker name + class name + environment).
|
|
95
|
-
*/
|
|
96
|
-
name?: string;
|
|
97
|
-
/**
|
|
98
|
-
* Rolling-deploy tuning. `stepPercentage` is the share of instances updated
|
|
99
|
-
* per rollout step (wrangler `rollout_step_percentage`); `gracePeriodSeconds`
|
|
100
|
-
* is how long an active instance is left running before it's eligible for
|
|
101
|
-
* update (wrangler `rollout_active_grace_period`).
|
|
102
|
-
*/
|
|
103
|
-
rollout?: ContainerRollout;
|
|
104
|
-
/**
|
|
105
|
-
* Names of Worker secrets (from `wrangler secret` / `.dev.vars`) forwarded
|
|
106
|
-
* into the container's environment at instance start. Each declared name
|
|
107
|
-
* must exist on the Worker `env` — a missing one fails fast with a
|
|
108
|
-
* directed error instead of starting the container without it.
|
|
109
|
-
*/
|
|
110
|
-
secrets?: ReadonlyArray<string>;
|
|
111
|
-
/**
|
|
112
|
-
* Idle timeout after which the instance is put to sleep, e.g. `"5m"`,
|
|
113
|
-
* `"30s"`, or a number of seconds. Cloudflare's default is `"10m"`.
|
|
114
|
-
*/
|
|
115
|
-
sleepAfter?: number | string;
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* The value `defineContainer` returns: the validated config plus a brand the
|
|
119
|
-
* codegen discovery and the generated Container DO class key on.
|
|
120
|
-
*/
|
|
121
|
-
interface ContainerDefinition extends ContainerConfig {
|
|
122
|
-
/** Brand marking a value as a Lunora container definition. */
|
|
123
|
-
readonly isLunoraContainer: true;
|
|
124
|
-
}
|
|
125
|
-
/** A normalized image source, as written into `wrangler.jsonc`. */
|
|
126
|
-
type NormalizedContainerImage = {
|
|
127
|
-
/** Build context directory (wrangler `image_build_context`). */
|
|
128
|
-
buildContext: string;
|
|
129
|
-
/** Path to the Dockerfile (wrangler `image`). */
|
|
130
|
-
dockerfilePath: string;
|
|
131
|
-
kind: "dockerfile";
|
|
132
|
-
} | {
|
|
133
|
-
/** Railpack source directory built + pushed at deploy time. */
|
|
134
|
-
buildDir: string;
|
|
135
|
-
kind: "build";
|
|
136
|
-
} | {
|
|
137
|
-
kind: "registry"; /** Fully-qualified image reference (wrangler `image`). */
|
|
138
|
-
reference: string;
|
|
139
|
-
};
|
|
140
|
-
export { BuildImageSource as B, ContainerDefinition as C, NormalizedContainerImage as N, RegistryImageSource as R, ContainerConfig as a, ContainerImageSource as b, ContainerInstanceType as c, ContainerRollout as d, CustomContainerInstanceType as e, NamedContainerInstanceType as f };
|
|
@@ -1,140 +0,0 @@
|
|
|
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
|
-
/** Named instance types Cloudflare Containers provides. */
|
|
9
|
-
type NamedContainerInstanceType = "basic" | "lite" | "standard-1" | "standard-2" | "standard-3" | "standard-4";
|
|
10
|
-
/**
|
|
11
|
-
* A custom instance type. Cloudflare's bounds at the time of writing: up to
|
|
12
|
-
* 4 vCPU, 12 GiB memory, 20 GB disk, ≥ 3 GiB memory per vCPU and ≤ 2 GB disk
|
|
13
|
-
* per GiB memory. The config-layer validator enforces the documented ranges.
|
|
14
|
-
*/
|
|
15
|
-
interface CustomContainerInstanceType {
|
|
16
|
-
/** Disk in MB. Cloudflare's default is 2000 (2 GB). */
|
|
17
|
-
diskMb?: number;
|
|
18
|
-
/** Memory in MiB. Cloudflare's default is 256. */
|
|
19
|
-
memoryMib?: number;
|
|
20
|
-
/** vCPU count. Cloudflare's default is 0.0625 (1/16 vCPU). */
|
|
21
|
-
vcpu?: number;
|
|
22
|
-
}
|
|
23
|
-
type ContainerInstanceType = CustomContainerInstanceType | NamedContainerInstanceType;
|
|
24
|
-
/** Rolling-deploy tuning for a container. */
|
|
25
|
-
interface ContainerRollout {
|
|
26
|
-
/** Seconds an active instance runs before it's eligible for update (wrangler `rollout_active_grace_period`). */
|
|
27
|
-
gracePeriodSeconds?: number;
|
|
28
|
-
/** Percentage of instances updated per rollout step, 1–100 (wrangler `rollout_step_percentage`). */
|
|
29
|
-
stepPercentage?: number;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* A pre-built image pulled from a registry — the Cloudflare Registry, Docker
|
|
33
|
-
* Hub, or Amazon ECR (the registries `wrangler deploy` supports). The
|
|
34
|
-
* reference must be fully qualified, e.g. `docker.io/acme/transcoder:1.4`.
|
|
35
|
-
*/
|
|
36
|
-
interface RegistryImageSource {
|
|
37
|
-
registry: string;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* A Dockerfile-less build via [Railpack](https://railpack.com): point at a
|
|
41
|
-
* source directory and `lunora deploy` builds an OCI image with Railpack
|
|
42
|
-
* (needs a BuildKit instance) and pushes it to the Cloudflare Registry before
|
|
43
|
-
* wrangler runs. Opt-in — the Dockerfile path is the zero-extra-deps default.
|
|
44
|
-
*/
|
|
45
|
-
interface BuildImageSource {
|
|
46
|
-
build: string;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Where the container image comes from. A `string` is a **local path** —
|
|
50
|
-
* either a directory containing a `Dockerfile` (normalized to
|
|
51
|
-
* `<dir>/Dockerfile` with the directory as the build context) or a path to
|
|
52
|
-
* the Dockerfile itself — while `{ registry }` is a pre-built image reference.
|
|
53
|
-
*/
|
|
54
|
-
type ContainerImageSource = BuildImageSource | RegistryImageSource | string;
|
|
55
|
-
interface ContainerConfig {
|
|
56
|
-
/**
|
|
57
|
-
* Build-time variables for a Dockerfile/Railpack image — wrangler's
|
|
58
|
-
* `image_vars` (equivalent to `docker build --build-arg`). For *runtime*
|
|
59
|
-
* values use {@link ContainerConfig.env} / {@link ContainerConfig.secrets}.
|
|
60
|
-
* Ignored for a pre-built `{ registry }` image.
|
|
61
|
-
*/
|
|
62
|
-
buildArgs?: Readonly<Record<string, string>>;
|
|
63
|
-
/**
|
|
64
|
-
* The port the container listens on. Worker → container requests target
|
|
65
|
-
* this port. Locally the Dockerfile must also `EXPOSE` it.
|
|
66
|
-
*/
|
|
67
|
-
defaultPort?: number;
|
|
68
|
-
/**
|
|
69
|
-
* Whether the container may open outbound internet connections. Defaults
|
|
70
|
-
* to `true` — the platform default. Note that container egress is billed
|
|
71
|
-
* per GB by Cloudflare.
|
|
72
|
-
*/
|
|
73
|
-
enableInternet?: boolean;
|
|
74
|
-
/**
|
|
75
|
-
* Static environment variables passed to the container on every start.
|
|
76
|
-
* For secret values use {@link ContainerConfig.secrets} instead so they
|
|
77
|
-
* flow through Worker Secrets rather than source code.
|
|
78
|
-
*/
|
|
79
|
-
env?: Readonly<Record<string, string>>;
|
|
80
|
-
/** Image source — a local Dockerfile path/directory or a registry reference. */
|
|
81
|
-
image: ContainerImageSource;
|
|
82
|
-
/**
|
|
83
|
-
* Resource class for each instance: a named Cloudflare instance type or a
|
|
84
|
-
* custom `{ vcpu, memoryMib, diskMb }` object.
|
|
85
|
-
*/
|
|
86
|
-
instanceType?: ContainerInstanceType;
|
|
87
|
-
/**
|
|
88
|
-
* Maximum number of concurrently *running* instances. Stopped (slept)
|
|
89
|
-
* containers don't count. Also the default pool size for `.any()`.
|
|
90
|
-
*/
|
|
91
|
-
maxInstances?: number;
|
|
92
|
-
/**
|
|
93
|
-
* Override for the wrangler `containers[].name` identifier. Defaults to
|
|
94
|
-
* wrangler's own default (worker name + class name + environment).
|
|
95
|
-
*/
|
|
96
|
-
name?: string;
|
|
97
|
-
/**
|
|
98
|
-
* Rolling-deploy tuning. `stepPercentage` is the share of instances updated
|
|
99
|
-
* per rollout step (wrangler `rollout_step_percentage`); `gracePeriodSeconds`
|
|
100
|
-
* is how long an active instance is left running before it's eligible for
|
|
101
|
-
* update (wrangler `rollout_active_grace_period`).
|
|
102
|
-
*/
|
|
103
|
-
rollout?: ContainerRollout;
|
|
104
|
-
/**
|
|
105
|
-
* Names of Worker secrets (from `wrangler secret` / `.dev.vars`) forwarded
|
|
106
|
-
* into the container's environment at instance start. Each declared name
|
|
107
|
-
* must exist on the Worker `env` — a missing one fails fast with a
|
|
108
|
-
* directed error instead of starting the container without it.
|
|
109
|
-
*/
|
|
110
|
-
secrets?: ReadonlyArray<string>;
|
|
111
|
-
/**
|
|
112
|
-
* Idle timeout after which the instance is put to sleep, e.g. `"5m"`,
|
|
113
|
-
* `"30s"`, or a number of seconds. Cloudflare's default is `"10m"`.
|
|
114
|
-
*/
|
|
115
|
-
sleepAfter?: number | string;
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* The value `defineContainer` returns: the validated config plus a brand the
|
|
119
|
-
* codegen discovery and the generated Container DO class key on.
|
|
120
|
-
*/
|
|
121
|
-
interface ContainerDefinition extends ContainerConfig {
|
|
122
|
-
/** Brand marking a value as a Lunora container definition. */
|
|
123
|
-
readonly isLunoraContainer: true;
|
|
124
|
-
}
|
|
125
|
-
/** A normalized image source, as written into `wrangler.jsonc`. */
|
|
126
|
-
type NormalizedContainerImage = {
|
|
127
|
-
/** Build context directory (wrangler `image_build_context`). */
|
|
128
|
-
buildContext: string;
|
|
129
|
-
/** Path to the Dockerfile (wrangler `image`). */
|
|
130
|
-
dockerfilePath: string;
|
|
131
|
-
kind: "dockerfile";
|
|
132
|
-
} | {
|
|
133
|
-
/** Railpack source directory built + pushed at deploy time. */
|
|
134
|
-
buildDir: string;
|
|
135
|
-
kind: "build";
|
|
136
|
-
} | {
|
|
137
|
-
kind: "registry"; /** Fully-qualified image reference (wrangler `image`). */
|
|
138
|
-
reference: string;
|
|
139
|
-
};
|
|
140
|
-
export { BuildImageSource as B, ContainerDefinition as C, NormalizedContainerImage as N, RegistryImageSource as R, ContainerConfig as a, ContainerImageSource as b, ContainerInstanceType as c, ContainerRollout as d, CustomContainerInstanceType as e, NamedContainerInstanceType as f };
|