@fabrika/provider-cloudflare 0.9.0-cloudflare.1 → 0.9.0-cloudflare.3
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/package.json +11 -10
- package/src/authoring.ts +56 -6
- package/src/bounds.ts +5 -2
- package/src/command.ts +22 -1
- package/src/contract-support.ts +126 -9
- package/src/control.ts +27 -7
- package/src/deploy-order.ts +35 -0
- package/src/index.ts +18 -2
- package/src/installation/templates/platform.yml +3 -0
- package/src/plan.ts +2 -0
- package/src/provider.ts +201 -33
- package/src/runner-protocol.ts +21 -3
- package/src/spa-assets.ts +176 -0
- package/types/src/authoring.d.ts +27 -5
- package/types/src/bounds.d.ts +5 -2
- package/types/src/command.d.ts +6 -1
- package/types/src/contract-support.d.ts +45 -4
- package/types/src/control.d.ts +68 -33
- package/types/src/deploy-order.d.ts +8 -0
- package/types/src/index.d.ts +2 -2
- package/types/src/provider.d.ts +36 -1
- package/types/src/runner-protocol.d.ts +23 -2
- package/types/src/spa-assets.d.ts +28 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fabrika/provider-cloudflare",
|
|
3
|
-
"version": "0.9.0-cloudflare.
|
|
3
|
+
"version": "0.9.0-cloudflare.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -43,15 +43,16 @@
|
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"zod": "^3.25.76",
|
|
46
|
-
"@fabrika/app": "0.9.0-cloudflare.
|
|
47
|
-
"@fabrika/auth": "0.9.0-cloudflare.
|
|
48
|
-
"@fabrika/auth-core": "0.9.0-cloudflare.
|
|
49
|
-
"@fabrika/check": "0.9.0-cloudflare.
|
|
50
|
-
"@fabrika/email": "0.9.0-cloudflare.
|
|
51
|
-
"@fabrika/iam-contract": "0.9.0-cloudflare.
|
|
52
|
-
"@fabrika/installation-init": "0.9.0-cloudflare.
|
|
53
|
-
"@fabrika/proxy-core": "0.9.0-cloudflare.
|
|
54
|
-
"@fabrika/provider-contract": "0.9.0-cloudflare.
|
|
46
|
+
"@fabrika/app": "0.9.0-cloudflare.3",
|
|
47
|
+
"@fabrika/auth": "0.9.0-cloudflare.3",
|
|
48
|
+
"@fabrika/auth-core": "0.9.0-cloudflare.3",
|
|
49
|
+
"@fabrika/check": "0.9.0-cloudflare.3",
|
|
50
|
+
"@fabrika/email": "0.9.0-cloudflare.3",
|
|
51
|
+
"@fabrika/iam-contract": "0.9.0-cloudflare.3",
|
|
52
|
+
"@fabrika/installation-init": "0.9.0-cloudflare.3",
|
|
53
|
+
"@fabrika/proxy-core": "0.9.0-cloudflare.3",
|
|
54
|
+
"@fabrika/provider-contract": "0.9.0-cloudflare.3",
|
|
55
|
+
"ignore": "^5.3.2",
|
|
55
56
|
"oblaka-iac": "^0.0.18"
|
|
56
57
|
}
|
|
57
58
|
}
|
package/src/authoring.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { GENERATED_ENTRY_FILE } from '@fabrika/app/build'
|
|
1
2
|
import { APP_PROVIDER, type AppConfigBase, isProviderAuthoredApp, type ProviderAuthoredApp } from '@fabrika/provider-contract'
|
|
2
|
-
import
|
|
3
|
+
import { Worker } from 'oblaka-iac'
|
|
4
|
+
import { iamServiceReference } from './proxy'
|
|
3
5
|
|
|
4
6
|
/** Inputs used to materialize one environment's Cloudflare resource graph. */
|
|
5
7
|
export interface ResourceContext {
|
|
@@ -7,20 +9,68 @@ export interface ResourceContext {
|
|
|
7
9
|
readonly domain?: string
|
|
8
10
|
}
|
|
9
11
|
|
|
12
|
+
/** What an author may set on the application Worker `defineApp` builds; everything else is fixed by the platform. */
|
|
13
|
+
export interface ApplicationWorkerOptions {
|
|
14
|
+
/** The application's own bindings, beside `IAM`, which is always the platform's. */
|
|
15
|
+
readonly bindings?: Worker['options']['bindings']
|
|
16
|
+
readonly compatibility_date?: string
|
|
17
|
+
readonly compatibility_flags?: Worker['options']['compatibility_flags']
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** A Cloudflare app config as `fabrika.config.ts` writes it. */
|
|
21
|
+
export type CloudflareAppConfigInput =
|
|
22
|
+
& AppConfigBase
|
|
23
|
+
& (
|
|
24
|
+
| {
|
|
25
|
+
/**
|
|
26
|
+
* The application Worker, for a config that composes its own. The deployer builds the proxy Worker in front of it
|
|
27
|
+
* from the contract (ADR-0048); never return one.
|
|
28
|
+
*/
|
|
29
|
+
readonly resources: (ctx: ResourceContext) => Worker
|
|
30
|
+
readonly worker?: never
|
|
31
|
+
}
|
|
32
|
+
| {
|
|
33
|
+
readonly resources?: never
|
|
34
|
+
/** Without `resources`, `defineApp` builds the application Worker from these and the platform's fixed values. */
|
|
35
|
+
readonly worker?: ApplicationWorkerOptions
|
|
36
|
+
}
|
|
37
|
+
)
|
|
38
|
+
|
|
10
39
|
/** A Cloudflare app config loaded from `fabrika.config.ts` inside the runner checkout. */
|
|
11
|
-
export interface
|
|
12
|
-
/** The application Worker. The deployer builds the proxy Worker in front of it from the contract (ADR-0048)
|
|
40
|
+
export interface CloudflareAppConfig extends AppConfigBase, ProviderAuthoredApp<'cloudflare'> {
|
|
41
|
+
/** The application Worker. The deployer builds the proxy Worker in front of it from the contract (ADR-0048). */
|
|
13
42
|
readonly resources: (ctx: ResourceContext) => Worker
|
|
14
43
|
}
|
|
15
44
|
|
|
16
|
-
|
|
45
|
+
/**
|
|
46
|
+
* The application Worker of a config without `resources`: the values the bounds require of every application Worker
|
|
47
|
+
* (the generated entry, no route, no public URL, IAM at its application entrypoint) and the Worker name `<app>`, so its
|
|
48
|
+
* remote name is the deployment's own `<env>-<app>`.
|
|
49
|
+
*/
|
|
50
|
+
const applicationWorker = (id: string, options: ApplicationWorkerOptions = {}): Worker =>
|
|
51
|
+
new Worker({
|
|
52
|
+
dir: '.',
|
|
53
|
+
name: id,
|
|
54
|
+
main: `./${GENERATED_ENTRY_FILE}`,
|
|
55
|
+
compatibility_date: options.compatibility_date ?? '2025-10-01',
|
|
56
|
+
compatibility_flags: [...(options.compatibility_flags ?? ['nodejs_compat_v2'])],
|
|
57
|
+
observability: { enabled: true },
|
|
58
|
+
workers_dev: false,
|
|
59
|
+
preview_urls: false,
|
|
60
|
+
routes: [],
|
|
61
|
+
bindings: { ...options.bindings, IAM: iamServiceReference() },
|
|
62
|
+
})
|
|
17
63
|
|
|
18
|
-
/**
|
|
64
|
+
/**
|
|
65
|
+
* Validate the app id and fill in the application Worker when the config composes none. The result always carries
|
|
66
|
+
* `resources`, because a runner narrows a loaded config with `isCloudflareAppConfig`, which requires it.
|
|
67
|
+
*/
|
|
19
68
|
export function defineApp(config: CloudflareAppConfigInput): CloudflareAppConfig {
|
|
20
69
|
if (typeof config.id !== 'string' || config.id.trim() === '') {
|
|
21
70
|
throw new Error('defineApp: `id` is required and must be a non-empty string')
|
|
22
71
|
}
|
|
23
|
-
|
|
72
|
+
const { resources, worker, ...rest } = config
|
|
73
|
+
return { ...rest, resources: resources ?? (() => applicationWorker(config.id, worker)), [APP_PROVIDER]: 'cloudflare' }
|
|
24
74
|
}
|
|
25
75
|
|
|
26
76
|
/** Narrow an imported module default without trusting code from the checkout. */
|
package/src/bounds.ts
CHANGED
|
@@ -45,11 +45,14 @@ export interface DeploymentBounds {
|
|
|
45
45
|
readonly application: ApplicationRuntime | null
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
/** The Durable Object, files bucket and
|
|
48
|
+
/** The Durable Object, files bucket and cron trigger of a contract application's Worker; the application authors none of them. */
|
|
49
49
|
export interface ApplicationRuntime {
|
|
50
50
|
/** The remote name of the environment's files bucket. */
|
|
51
51
|
readonly filesBucket: string
|
|
52
|
-
/**
|
|
52
|
+
/**
|
|
53
|
+
* The cron triggers the Worker carries when the contract has a job or a file kind, else an empty list: the hourly repair
|
|
54
|
+
* tick of a release that serves alarms, otherwise the minute tick.
|
|
55
|
+
*/
|
|
53
56
|
readonly crons: readonly string[]
|
|
54
57
|
/**
|
|
55
58
|
* The absolute path of the entry the deploy regenerates, which the Worker's `main` must name (`pinsGeneratedEntry`), or
|
package/src/command.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { type AppEnvironment, parseAppEnvironmentId, parseManagedEnvironment } from '@fabrika/auth-core'
|
|
1
|
+
import { type AppEnvironment, type ApplicationObjects, parseAppEnvironmentId, parseManagedEnvironment } from '@fabrika/auth-core'
|
|
2
2
|
import { readFile } from 'node:fs/promises'
|
|
3
3
|
import { z } from 'zod'
|
|
4
4
|
import type { CloudflareAppConfig } from './authoring'
|
|
5
5
|
import { loadCloudflareConfig } from './collaborators'
|
|
6
6
|
import { type CloudflareDeployResult, createCloudflareDeployer, type PlatformIamTarget } from './provider'
|
|
7
7
|
import {
|
|
8
|
+
APPLICATION_OBJECTS_ENV,
|
|
9
|
+
applicationObjectsSchema,
|
|
8
10
|
APPROVED_ACCESS_FILE_ENV,
|
|
9
11
|
CROSS_ORIGINS_ENV,
|
|
10
12
|
INSTALLATION_APPS_ENV,
|
|
@@ -73,6 +75,23 @@ export const parseCrossOrigins = (raw: string | undefined): readonly string[] |
|
|
|
73
75
|
return origins.data.length === 0 ? undefined : origins.data
|
|
74
76
|
}
|
|
75
77
|
|
|
78
|
+
/**
|
|
79
|
+
* Decode `FABRIKA_RUNNER_APPLICATION_OBJECTS`, the pointer Control recorded, as the runner writes it. Undefined when
|
|
80
|
+
* absent, and the deployer writes its defaults; anything malformed fails the deploy rather than move ordinary traffic.
|
|
81
|
+
*/
|
|
82
|
+
export const parseApplicationObjectsEnvironment = (raw: string | undefined): ApplicationObjects | undefined => {
|
|
83
|
+
if (raw === undefined || raw === '') return undefined
|
|
84
|
+
let decoded: unknown
|
|
85
|
+
try {
|
|
86
|
+
decoded = JSON.parse(raw)
|
|
87
|
+
} catch {
|
|
88
|
+
throw new Error(`${APPLICATION_OBJECTS_ENV} is not JSON`)
|
|
89
|
+
}
|
|
90
|
+
const objects = applicationObjectsSchema.safeParse(decoded)
|
|
91
|
+
if (!objects.success) throw new Error(`${APPLICATION_OBJECTS_ENV} is not a serving object and its object list`)
|
|
92
|
+
return objects.data
|
|
93
|
+
}
|
|
94
|
+
|
|
76
95
|
/**
|
|
77
96
|
* Decode `FABRIKA_INSTALLATION_APPS`, the Cloudflare deployments Control registered, as the runner writes it.
|
|
78
97
|
* Undefined when absent; anything malformed fails the deploy rather than dropping the refusal it feeds.
|
|
@@ -157,6 +176,7 @@ export const deployCloudflareConfig = async (options: CloudflareCommandDeployOpt
|
|
|
157
176
|
const installationApps = parseInstallationApps(environmentValue(INSTALLATION_APPS_ENV))
|
|
158
177
|
const crossOrigins = parseCrossOrigins(environmentValue(CROSS_ORIGINS_ENV))
|
|
159
178
|
const operationsOrigin = environmentValue(OPERATIONS_ORIGIN_ENV)
|
|
179
|
+
const applicationObjects = parseApplicationObjectsEnvironment(environmentValue(APPLICATION_OBJECTS_ENV))
|
|
160
180
|
return deploy({
|
|
161
181
|
appId: loaded.config.id,
|
|
162
182
|
env: options.env,
|
|
@@ -165,6 +185,7 @@ export const deployCloudflareConfig = async (options: CloudflareCommandDeployOpt
|
|
|
165
185
|
...(operationsOrigin === undefined ? {} : { operationsOrigin }),
|
|
166
186
|
...(returnOrigins === undefined ? {} : { returnOrigins }),
|
|
167
187
|
...(installationApps === undefined ? {} : { installationApps }),
|
|
188
|
+
...(applicationObjects === undefined ? {} : { applicationObjects }),
|
|
168
189
|
...approved,
|
|
169
190
|
cwd: loaded.cwd,
|
|
170
191
|
configPath: loaded.absolutePath,
|
package/src/contract-support.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CLOUDFLARE_MAX_JOB_SEGMENT_MS } from '@fabrika/app/contract'
|
|
1
2
|
import {
|
|
2
3
|
type ContractArtifact,
|
|
3
4
|
FABRIKA_TOKEN_KEYS,
|
|
@@ -16,11 +17,20 @@ import type { ProviderManagedEnvironment } from '@fabrika/provider-contract'
|
|
|
16
17
|
*/
|
|
17
18
|
export const CLOUDFLARE_MAX_HANDLER_MS = 25_000
|
|
18
19
|
|
|
20
|
+
/** What the release a caller runs a contract as decides about it; each caller reads them off that release. */
|
|
21
|
+
export interface CloudflareContractGates {
|
|
22
|
+
/** The release caps a job at one segment (`capsJobSegments`). */
|
|
23
|
+
readonly capsSegments: boolean
|
|
24
|
+
/** The release runs `ctx.sql` on the object's SQLite (`servesRawSql`). */
|
|
25
|
+
readonly servesSql: boolean
|
|
26
|
+
}
|
|
27
|
+
|
|
19
28
|
/**
|
|
20
29
|
* Refuse what a contract declares that an application on Cloudflare cannot run yet (ADR-0065): a file kind that scans
|
|
21
|
-
* its uploads,
|
|
30
|
+
* its uploads, a handler allowed to outlive the object's transaction limit, and, by the release it runs as, a job longer
|
|
31
|
+
* than one segment and raw SQL (`ctx.sql`).
|
|
22
32
|
*/
|
|
23
|
-
export const assertCloudflareContract = (contract: ContractArtifact): void => {
|
|
33
|
+
export const assertCloudflareContract = (contract: ContractArtifact, { capsSegments, servesSql }: CloudflareContractGates): void => {
|
|
24
34
|
const handlers: [string, number][] = [
|
|
25
35
|
...Object.entries(contract.procedures ?? {}).map(([id, procedure]): [string, number] => [`procedure \`${id}\``, procedure.timeoutMs]),
|
|
26
36
|
...Object.entries(contract.mounts).flatMap(([name, mount]): [string, number][] =>
|
|
@@ -34,6 +44,15 @@ export const assertCloudflareContract = (contract: ContractArtifact): void => {
|
|
|
34
44
|
)
|
|
35
45
|
}
|
|
36
46
|
}
|
|
47
|
+
if (capsSegments) {
|
|
48
|
+
for (const [name, job] of Object.entries(contract.jobs)) {
|
|
49
|
+
if (job.timeoutMs > CLOUDFLARE_MAX_JOB_SEGMENT_MS) {
|
|
50
|
+
throw new Error(
|
|
51
|
+
`cloudflare: job \`${name}\` runs up to ${job.timeoutMs} ms, and a job segment on Cloudflare runs at most ${CLOUDFLARE_MAX_JOB_SEGMENT_MS} ms: claim a bounded batch per run and let the next run take the rest; a Workflow for one longer run is planned (backlog 230)`,
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
37
56
|
for (const [name, kind] of Object.entries(contract.fileKinds ?? {})) {
|
|
38
57
|
if (kind.scan === true) {
|
|
39
58
|
throw new Error(`cloudflare: file kind \`${name}\` scans its uploads (\`scan: true\`), and no scanner runs on Cloudflare yet`)
|
|
@@ -44,18 +63,21 @@ export const assertCloudflareContract = (contract: ContractArtifact): void => {
|
|
|
44
63
|
throw new Error(`cloudflare: file collection \`${name}\` scans its uploads (\`scan: true\`), and no scanner runs on Cloudflare yet`)
|
|
45
64
|
}
|
|
46
65
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
66
|
+
if (!servesSql) {
|
|
67
|
+
for (const [site, reach] of Object.entries(contract.declared ?? {})) {
|
|
68
|
+
if (reach.sql !== null) {
|
|
69
|
+
throw new Error(
|
|
70
|
+
`cloudflare: \`${site}\` declares raw SQL (\`ctx.sql\`), which an application on Cloudflare runs from framework ${RAW_SQL_SINCE} on; upgrade its framework`,
|
|
71
|
+
)
|
|
72
|
+
}
|
|
52
73
|
}
|
|
53
74
|
}
|
|
54
75
|
}
|
|
55
76
|
|
|
56
77
|
/**
|
|
57
|
-
* The object runs due jobs and the file sweep of file kinds, a framework job,
|
|
58
|
-
*
|
|
78
|
+
* The object runs due jobs and the file sweep of file kinds, a framework job, from the Worker's cron trigger: the minute
|
|
79
|
+
* tick, or from `servesAlarms` its alarm with an hourly repair tick (ADR-0065 §5). Legacy `files` collections do not
|
|
80
|
+
* count: the object schedules no sweep of theirs.
|
|
59
81
|
*/
|
|
60
82
|
export const needsMinuteTick = (contract: ContractArtifact): boolean =>
|
|
61
83
|
Object.keys(contract.jobs).length > 0 || Object.keys(contract.fileKinds ?? {}).length > 0
|
|
@@ -92,6 +114,101 @@ const SERVES_OPS_SINCE = { major: 0, minor: 9 }
|
|
|
92
114
|
/** Whether an environment on release `release` gets the ops row, the ops key digests and the object variables. */
|
|
93
115
|
export const servesOps = (release: string): boolean => releaseAtLeast(release, SERVES_OPS_SINCE)
|
|
94
116
|
|
|
117
|
+
/** A release as semver orders it: the numeric core, then the prerelease identifiers (none sorts above any). */
|
|
118
|
+
interface ReleaseVersion {
|
|
119
|
+
readonly core: readonly number[]
|
|
120
|
+
readonly prerelease: readonly string[]
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const parseReleaseVersion = (release: string): ReleaseVersion | null => {
|
|
124
|
+
const match = /^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z.-]+)?$/.exec(release)
|
|
125
|
+
if (match === null) return null
|
|
126
|
+
return { core: [Number(match[1]), Number(match[2]), Number(match[3])], prerelease: match[4] === undefined ? [] : match[4].split('.') }
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** Semver's order of two prerelease identifiers: numerically when both are numeric, a numeric one first, else by ASCII. */
|
|
130
|
+
const compareIdentifiers = (a: string, b: string): number => {
|
|
131
|
+
const numericA = /^\d+$/.test(a)
|
|
132
|
+
const numericB = /^\d+$/.test(b)
|
|
133
|
+
if (numericA && numericB) return Number(a) - Number(b)
|
|
134
|
+
if (numericA !== numericB) return numericA ? -1 : 1
|
|
135
|
+
return a < b ? -1 : a > b ? 1 : 0
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const compareReleases = (a: ReleaseVersion, b: ReleaseVersion): number => {
|
|
139
|
+
for (const [index, part] of a.core.entries()) {
|
|
140
|
+
const other = b.core[index] ?? 0
|
|
141
|
+
if (part !== other) return part - other
|
|
142
|
+
}
|
|
143
|
+
if (a.prerelease.length === 0 || b.prerelease.length === 0) return b.prerelease.length - a.prerelease.length
|
|
144
|
+
for (const [index, identifier] of a.prerelease.entries()) {
|
|
145
|
+
const other = b.prerelease[index]
|
|
146
|
+
if (other === undefined) return 1
|
|
147
|
+
const order = compareIdentifiers(identifier, other)
|
|
148
|
+
if (order !== 0) return order
|
|
149
|
+
}
|
|
150
|
+
return a.prerelease.length - b.prerelease.length
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Whether framework release `release` is at or above the exact version `since` in semver's precedence, prerelease
|
|
155
|
+
* included; a release that is not a semver version never is (ADR-0062).
|
|
156
|
+
*/
|
|
157
|
+
export const releaseFrom = (release: string, since: string): boolean => {
|
|
158
|
+
const floor = parseReleaseVersion(since)
|
|
159
|
+
if (floor === null) throw new Error(`releaseFrom: \`${since}\` is not a semver version`)
|
|
160
|
+
const version = parseReleaseVersion(release)
|
|
161
|
+
return version !== null && compareReleases(version, floor) >= 0
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* The release a gate reads for an approved access: the application's pin, never the reader's `checker`, which is this
|
|
166
|
+
* platform's patch of the pin's minor and so passes a `releaseFrom` gate a prerelease pin does not. An access approved before Control recorded the pin is read as the oldest release of its
|
|
167
|
+
* reader's minor (`<major>.<minor>.0-0`): every `releaseAtLeast` gate answers as for that minor, and every `releaseFrom`
|
|
168
|
+
* gate of a prerelease or a patch fails closed, as for an older application, until a deploy reads its pin.
|
|
169
|
+
*/
|
|
170
|
+
export const applicationRelease = (access: { readonly checker: string; readonly framework?: string }): string => {
|
|
171
|
+
if (access.framework !== undefined) return access.framework
|
|
172
|
+
const minor = /^(\d+)\.(\d+)\./.exec(access.checker)
|
|
173
|
+
return minor === null ? access.checker : `${minor[1]}.${minor[2]}.0-0`
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* The first framework release whose application object holds the maintenance barrier (`state`, `migrate`) and serves
|
|
178
|
+
* the data operations, runs its jobs from its alarm, and whose deploy caps a job at one segment. The 0.9.0 prereleases
|
|
179
|
+
* published before it (`dev.0`–`dev.4`, `cloudflare.1`–`cloudflare.2`) run in the object without any of that and answer
|
|
180
|
+
* `state` and `migrate` 501, so these gates compare the whole version where `releaseAtLeast` counts a prerelease as
|
|
181
|
+
* its minor. A prerelease of another channel sorts by its name: every `cloudflare.<n>` keeps the older behaviour.
|
|
182
|
+
*/
|
|
183
|
+
const OBJECT_OPERATIONS_SINCE = '0.9.0-dev.5'
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Whether the object of release `release` holds the maintenance barrier and serves Control's data operations: the
|
|
187
|
+
* backups, the migration phase and the side restore (ADR-0069 §3, ADR-0070).
|
|
188
|
+
*/
|
|
189
|
+
export const servesDataOperations = (release: string): boolean => releaseFrom(release, OBJECT_OPERATIONS_SINCE)
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Whether the Worker of release `release` gets the hourly repair tick instead of the minute tick: an older object runs
|
|
193
|
+
* its jobs only from the minute tick and has no alarm.
|
|
194
|
+
*/
|
|
195
|
+
export const servesAlarms = (release: string): boolean => releaseFrom(release, OBJECT_OPERATIONS_SINCE)
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Whether the Cloudflare deploy of release `release` refuses a job whose `timeoutMs` exceeds one segment
|
|
199
|
+
* (`CLOUDFLARE_MAX_JOB_SEGMENT_MS`). An older release deploys as it did (ADR-0062).
|
|
200
|
+
*/
|
|
201
|
+
export const capsJobSegments = (release: string): boolean => releaseFrom(release, OBJECT_OPERATIONS_SINCE)
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* The first framework release whose object runs `ctx.sql` on its SQLite (ADR-0065 decision 7). An older one refuses a
|
|
205
|
+
* site that declares `sql` at boot, so the deploy refuses it first.
|
|
206
|
+
*/
|
|
207
|
+
const RAW_SQL_SINCE = '0.9.0-dev.5'
|
|
208
|
+
|
|
209
|
+
/** Whether an application on release `release` may declare `sql` on Cloudflare. */
|
|
210
|
+
export const servesRawSql = (release: string): boolean => releaseFrom(release, RAW_SQL_SINCE)
|
|
211
|
+
|
|
95
212
|
/**
|
|
96
213
|
* Refuse what a stateless Worker of an older release cannot run: a job, a webhook, a public procedure, installation
|
|
97
214
|
* mail and token purposes all need the object's database or a Worker secret it never reads.
|
package/src/control.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type AppEnvironment, appEnvironmentId, FABRIKA_PROXY_SECRET, parseAppEnvironmentId } from '@fabrika/auth-core'
|
|
1
|
+
import { type AppEnvironment, appEnvironmentId, type ApplicationObjects, FABRIKA_PROXY_SECRET, parseAppEnvironmentId } from '@fabrika/auth-core'
|
|
2
2
|
import type {
|
|
3
3
|
ControlProvider,
|
|
4
4
|
JsonValue,
|
|
@@ -20,10 +20,19 @@ import { isCrossOrigin, isPolicyOrigin, MAX_CROSS_ORIGINS } from '@fabrika/proxy
|
|
|
20
20
|
import { isProxyHost } from '@fabrika/proxy-core/manifest'
|
|
21
21
|
import { z } from 'zod'
|
|
22
22
|
import { cloudflareArtifactCodec } from './codec'
|
|
23
|
-
import {
|
|
23
|
+
import {
|
|
24
|
+
applicationRelease,
|
|
25
|
+
assertCloudflareContract,
|
|
26
|
+
assertStatelessEnvironment,
|
|
27
|
+
capsJobSegments,
|
|
28
|
+
runsInObject,
|
|
29
|
+
servesDataOperations,
|
|
30
|
+
servesOps,
|
|
31
|
+
servesRawSql,
|
|
32
|
+
} from './contract-support'
|
|
24
33
|
// `./runner` is this module: keep every import here clear of `oblaka-iac`, which the runner packages
|
|
25
34
|
// cannot typecheck (they do not relax the two strict flags the raw TS needs).
|
|
26
|
-
import { type RunnerApprovedAccess, runnerApprovedAccessSchema, type RunnerIamReconcile } from './runner-protocol'
|
|
35
|
+
import { applicationObjectsSchema, type RunnerApprovedAccess, runnerApprovedAccessSchema, type RunnerIamReconcile } from './runner-protocol'
|
|
27
36
|
|
|
28
37
|
export * from './runner-protocol'
|
|
29
38
|
|
|
@@ -66,6 +75,8 @@ export interface CloudflareRunnerJob {
|
|
|
66
75
|
readonly installationApps?: readonly string[]
|
|
67
76
|
/** What the deployed proxy enforces and the application starts as; every run but a dry one carries it. */
|
|
68
77
|
readonly approvedAccess?: RunnerApprovedAccess
|
|
78
|
+
/** The serving object and the listed objects Control records (ADR-0070 §9); absent, the deployer's defaults. */
|
|
79
|
+
readonly applicationObjects?: ApplicationObjects
|
|
69
80
|
readonly dryRun?: boolean
|
|
70
81
|
/**
|
|
71
82
|
* Shared secret the runner verifies before it touches D1 or the container; the binding alone proves
|
|
@@ -153,6 +164,7 @@ export const cloudflareRunnerJobSchema = z.object({
|
|
|
153
164
|
operationsOrigin: z.string().refine((origin) => isPolicyOrigin(origin, ['https:', 'http:'])).optional(),
|
|
154
165
|
installationApps: z.array(z.string().refine((id) => !hasUnsafeChars(id) && parseAppEnvironmentId(id) !== null)).optional(),
|
|
155
166
|
approvedAccess: runnerApprovedAccessSchema.optional(),
|
|
167
|
+
applicationObjects: applicationObjectsSchema.optional(),
|
|
156
168
|
dryRun: z.boolean().optional(),
|
|
157
169
|
secrets: stringRecordSchema.optional(),
|
|
158
170
|
vars: stringRecordSchema.optional(),
|
|
@@ -271,7 +283,7 @@ const runnerApprovedAccess = (environment: ProviderEnvironment): RunnerApprovedA
|
|
|
271
283
|
kind: 'contract',
|
|
272
284
|
contract: environment.access.contract,
|
|
273
285
|
contractDigest: environment.access.contractDigest,
|
|
274
|
-
framework: environment.access
|
|
286
|
+
framework: applicationRelease(environment.access),
|
|
275
287
|
}
|
|
276
288
|
|
|
277
289
|
const buildJob = async (options: CloudflareControlOptions, input: ProviderDeployInput): Promise<CloudflareRunnerJob> => {
|
|
@@ -285,9 +297,14 @@ const buildJob = async (options: CloudflareControlOptions, input: ProviderDeploy
|
|
|
285
297
|
throw new Error('Cloudflare deploy requires a canonical 40-character commit SHA')
|
|
286
298
|
}
|
|
287
299
|
const approvedAccess = runnerApprovedAccess(input.environment)
|
|
300
|
+
const release = input.environment.access === undefined ? undefined : applicationRelease(input.environment.access)
|
|
288
301
|
// The deployer refuses it again from the contract it serves; this fails before the clone.
|
|
289
|
-
if (approvedAccess !== undefined)
|
|
290
|
-
|
|
302
|
+
if (approvedAccess !== undefined) {
|
|
303
|
+
assertCloudflareContract(approvedAccess.contract, {
|
|
304
|
+
capsSegments: release !== undefined && capsJobSegments(release),
|
|
305
|
+
servesSql: release !== undefined && servesRawSql(release),
|
|
306
|
+
})
|
|
307
|
+
}
|
|
291
308
|
const stateless = release !== undefined && !runsInObject(release)
|
|
292
309
|
if (stateless) assertStatelessEnvironment(input.managedEnvironment, release)
|
|
293
310
|
const source = await awaitWithSignal(input.signal, () => options.prepareClone(input.app.source, input.signal, input.sourceBinding))
|
|
@@ -322,6 +339,7 @@ const buildJob = async (options: CloudflareControlOptions, input: ProviderDeploy
|
|
|
322
339
|
...(input.environment.operationsOrigin === undefined ? {} : { operationsOrigin: input.environment.operationsOrigin }),
|
|
323
340
|
...(installationApps === undefined ? {} : { installationApps }),
|
|
324
341
|
...(approvedAccess === undefined ? {} : { approvedAccess }),
|
|
342
|
+
...(input.applicationObjects === undefined ? {} : { applicationObjects: input.applicationObjects }),
|
|
325
343
|
...(input.dryRun ? { dryRun: true } : {}),
|
|
326
344
|
...(Object.keys(input.secrets).length === 0 ? {} : { secrets: input.secrets }),
|
|
327
345
|
...(Object.keys(input.vars).length === 0 ? {} : { vars: input.vars }),
|
|
@@ -364,7 +382,9 @@ export const createCloudflareControlProvider = (options: CloudflareControlOption
|
|
|
364
382
|
// The application's Worker forwards each request to its Durable Object with the environment's proxy secret.
|
|
365
383
|
applicationHopSecret: true,
|
|
366
384
|
// The environment's object serves Control's ops requests from the release that gets the composed row.
|
|
367
|
-
opsChannel: (access) => servesOps(access
|
|
385
|
+
opsChannel: (access) => servesOps(applicationRelease(access)),
|
|
386
|
+
// From the release whose object holds the barrier; the 0.9.0 prereleases before it serve only `inspect`.
|
|
387
|
+
dataOperations: (access) => servesOps(applicationRelease(access)) && servesDataOperations(applicationRelease(access)),
|
|
368
388
|
normalizeRegistration,
|
|
369
389
|
applicationRoot: (source) => checkoutRelativeDirectory(source.workerDir),
|
|
370
390
|
source: { binding: 'connection' },
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { GeneratedConfig } from 'oblaka-iac'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The generated configs in the order `wrangler deploy` can take them: a Worker another generated config binds as a
|
|
5
|
+
* service goes first, because wrangler refuses a service binding to a script with no deployment yet (code 10145) —
|
|
6
|
+
* on a first deploy the proxy would otherwise reach the application Worker before it exists. Configs with no such
|
|
7
|
+
* dependency keep oblaka's order. A cycle has no first deploy, so it is refused.
|
|
8
|
+
*/
|
|
9
|
+
export const deployOrder = (configs: readonly GeneratedConfig[]): readonly GeneratedConfig[] => {
|
|
10
|
+
const byName = new Map<string, GeneratedConfig>()
|
|
11
|
+
for (const generated of configs) {
|
|
12
|
+
if (generated.config.name !== undefined) byName.set(generated.config.name, generated)
|
|
13
|
+
}
|
|
14
|
+
const dependencies = (generated: GeneratedConfig): GeneratedConfig[] =>
|
|
15
|
+
(generated.config.services ?? []).flatMap((entry) => {
|
|
16
|
+
const target = byName.get(entry.service)
|
|
17
|
+
return target === undefined || target === generated ? [] : [target]
|
|
18
|
+
})
|
|
19
|
+
const ordered: GeneratedConfig[] = []
|
|
20
|
+
const state = new Map<GeneratedConfig, 'visiting' | 'done'>()
|
|
21
|
+
const visit = (generated: GeneratedConfig, path: readonly GeneratedConfig[]): void => {
|
|
22
|
+
const seen = state.get(generated)
|
|
23
|
+
if (seen === 'done') return
|
|
24
|
+
if (seen === 'visiting') {
|
|
25
|
+
const cycle = [...path.slice(path.indexOf(generated)), generated].map((item) => `\`${item.config.name ?? '(unnamed)'}\``)
|
|
26
|
+
throw new Error(`deploy-worker: the generated Workers bind each other as services in a cycle (${cycle.join(' → ')}), so none can deploy first`)
|
|
27
|
+
}
|
|
28
|
+
state.set(generated, 'visiting')
|
|
29
|
+
for (const target of dependencies(generated)) visit(target, [...path, generated])
|
|
30
|
+
state.set(generated, 'done')
|
|
31
|
+
ordered.push(generated)
|
|
32
|
+
}
|
|
33
|
+
for (const generated of configs) visit(generated, [])
|
|
34
|
+
return ordered
|
|
35
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
export * from 'oblaka-iac'
|
|
2
|
-
export {
|
|
2
|
+
export {
|
|
3
|
+
type ApplicationWorkerOptions,
|
|
4
|
+
type CloudflareAppConfig,
|
|
5
|
+
type CloudflareAppConfigInput,
|
|
6
|
+
defineApp,
|
|
7
|
+
isCloudflareAppConfig,
|
|
8
|
+
type ResourceContext,
|
|
9
|
+
} from './authoring'
|
|
3
10
|
export { assertGeneratedConfigs, assertGeneration, generateWranglerConfigs } from './bounds'
|
|
4
11
|
export type { ConfigGeneration, DeploymentBounds, GeneratedResource } from './bounds'
|
|
5
12
|
export { parseCloudflareArgs, platformComponents } from './cli-args'
|
|
@@ -25,7 +32,16 @@ export { cloudflareStoredTargetCodec, createCloudflareControlProvider } from './
|
|
|
25
32
|
export type { CloudflareCloneSource, CloudflareControlOptions, CloudflareRunnerJob, CloudflareStoredTarget } from './control'
|
|
26
33
|
export { buildPlan, findMigratableDatabases, PLATFORM_RESOURCE_NAMES } from './plan'
|
|
27
34
|
export type { CloudflareStep, CloudflareStepKind, MigratableDatabase } from './plan'
|
|
28
|
-
export {
|
|
35
|
+
export {
|
|
36
|
+
type CloudflareDeployerOptions,
|
|
37
|
+
type CloudflareDeployResult,
|
|
38
|
+
type CloudflareDeployRun,
|
|
39
|
+
composeLocalApplication,
|
|
40
|
+
createCloudflareDeployer,
|
|
41
|
+
type LocalApplicationOptions,
|
|
42
|
+
type StagedLocalAssets,
|
|
43
|
+
stageLocalAssets,
|
|
44
|
+
} from './provider'
|
|
29
45
|
export { createCloudflareProxyWorker, IAM_APPLICATION_ENTRYPOINT, iamServiceReference, proxyManifestJson } from './proxy'
|
|
30
46
|
export type { CloudflareProxyWorkerOptions } from './proxy'
|
|
31
47
|
export { type AppSchemaParse, parseAppSchema } from './schema'
|
|
@@ -146,6 +146,9 @@ jobs:
|
|
|
146
146
|
FABRIKA_IAM_SIGNING_KEYS: ${{ secrets.FABRIKA_IAM_SIGNING_KEYS }}
|
|
147
147
|
OIDC_CLIENT_SECRET: ${{ secrets.FABRIKA_IAM_OIDC_CLIENT_SECRET }}
|
|
148
148
|
FABRIKA_IAM_PROVISIONING_KEY: ${{ secrets.FABRIKA_IAM_PROVISIONING_KEY }}
|
|
149
|
+
# Control's public origin: IAM hands its mail to Control's relay there, under a key derived from the
|
|
150
|
+
# provisioning key, and the relay sends it with Control's copy of the transport.
|
|
151
|
+
FABRIKA_CONTROL_URL: https://${{ vars.FABRIKA_CONTROL_DOMAIN }}
|
|
149
152
|
# Every built-in mail provider's variables, written by init from the provider registry: IAM reads only the
|
|
150
153
|
# selected provider's, and an unset one is ''.
|
|
151
154
|
# {{EMAIL_PROVIDER_ENV}}
|
package/src/plan.ts
CHANGED