@fabrika/provider-cloudflare 0.2.0 → 0.3.2

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.
@@ -0,0 +1,101 @@
1
+ /**
2
+ * The per-account base repo `<org>/fabrika-platform`: which files it carries, and the one migration that
3
+ * must stop a refresh. The create/clone/commit/push mechanics are shared
4
+ * (`@fabrika/installation-init`); everything here is Cloudflare's answer to what gets written.
5
+ *
6
+ * `fabrika.ref` is written ONLY when absent (operator-owned after creation — bumping it is how you roll a new
7
+ * base); `platform.yml` / `README.md` / `.gitignore` are CLI-owned and refreshed every run.
8
+ */
9
+
10
+ import {
11
+ INITIAL_SCAFFOLD_COMMIT_MESSAGE,
12
+ type ProtectionOutcome,
13
+ REFRESH_SCAFFOLD_COMMIT_MESSAGE,
14
+ scaffoldSidecarRepository,
15
+ } from '@fabrika/installation-init'
16
+ import { existsSync } from 'node:fs'
17
+ import { resolve } from 'node:path'
18
+
19
+ const TEMPLATES = resolve(import.meta.dir, 'templates')
20
+
21
+ /**
22
+ * All scaffold files we ever `git add` (the CLI-owned trio + the operator-owned, write-once `fabrika.ref` pin).
23
+ */
24
+ const ALL_FILES = ['.gitignore', 'README.md', 'fabrika.ref', '.github/workflows/platform.yml']
25
+ const LEGACY_REF_FILES = ['vozka.ref', 'propustka.ref']
26
+
27
+ export { INITIAL_SCAFFOLD_COMMIT_MESSAGE, REFRESH_SCAFFOLD_COMMIT_MESSAGE }
28
+
29
+ export interface ScaffoldInput {
30
+ /** The base repo, e.g. `manGoweb/fabrika-platform`. */
31
+ repo: string
32
+ /** The account label (positional `init` arg) — substituted into the templates + the env/summary names. */
33
+ account: string
34
+ /** Local directory to check the repo out into. */
35
+ dir: string
36
+ }
37
+
38
+ /** Result of scaffolding: the local checkout dir + whether the repo was freshly created. */
39
+ export interface ScaffoldResult {
40
+ dir: string
41
+ created: boolean
42
+ /** Set only for a repository this run created; absent means an existing repo was left as it is. */
43
+ branchProtection?: ProtectionOutcome
44
+ }
45
+
46
+ /** Render a template: replace every `{{ACCOUNT}}` token. (Account is the only placeholder today.) */
47
+ async function renderTemplate(name: string, account: string): Promise<string> {
48
+ const raw = await Bun.file(resolve(TEMPLATES, name)).text()
49
+ return raw.replaceAll('{{ACCOUNT}}', account)
50
+ }
51
+
52
+ /** Write the file at `rel` under `dir` with `content`, creating parent dirs as needed. */
53
+ async function writeFile(dir: string, rel: string, content: string): Promise<void> {
54
+ await Bun.write(resolve(dir, rel), content)
55
+ }
56
+
57
+ /**
58
+ * Materialize the CLI-owned files and the write-once source pin.
59
+ *
60
+ * Legacy two-repository pins need an operator-chosen merged-repository ref. Stop before writing anything
61
+ * so a refresh cannot hide the migration requirement or delete operator-owned files.
62
+ */
63
+ export async function materializePlatformScaffold(dir: string, account: string): Promise<void> {
64
+ const legacyRefs = LEGACY_REF_FILES.filter((name) => existsSync(resolve(dir, name)))
65
+ if (legacyRefs.length > 0) {
66
+ throw new Error(
67
+ `Legacy two-repository scaffold detected (${legacyRefs.join(', ')}). Choose the matching `
68
+ + 'contember/fabrika-platform commit or tag, write it to fabrika.ref, then remove the legacy '
69
+ + 'pin files manually and run `fabrika platform init --provider=cloudflare` again. '
70
+ + 'The CLI cannot infer the merged ref.',
71
+ )
72
+ }
73
+ await writeFile(dir, '.gitignore', await Bun.file(resolve(TEMPLATES, 'gitignore')).text())
74
+ await writeFile(dir, 'README.md', await renderTemplate('README.md', account))
75
+ await writeFile(dir, '.github/workflows/platform.yml', await renderTemplate('platform.yml', account))
76
+ if (!existsSync(resolve(dir, 'fabrika.ref'))) {
77
+ await writeFile(dir, 'fabrika.ref', await Bun.file(resolve(TEMPLATES, 'fabrika.ref')).text())
78
+ }
79
+ }
80
+
81
+ /**
82
+ * Ensure `<org>/fabrika-platform` exists + carries the current scaffold. Returns the local checkout dir.
83
+ * Requires `gh` authed with rights to create/admin the repo.
84
+ */
85
+ export async function scaffoldPlatformRepo(input: ScaffoldInput): Promise<ScaffoldResult> {
86
+ return scaffoldSidecarRepository({
87
+ repo: input.repo,
88
+ dir: input.dir,
89
+ files: ALL_FILES,
90
+ materialize: (dir) => materializePlatformScaffold(dir, input.account),
91
+ })
92
+ }
93
+
94
+ /** Read the configured `fabrika.ref` (for display), or 'main' when absent. Used in the final summary. */
95
+ export async function readFabrikaRef(dir: string): Promise<string> {
96
+ const file = Bun.file(resolve(dir, 'fabrika.ref'))
97
+ if (!(await file.exists())) {
98
+ return 'main'
99
+ }
100
+ return (await file.text()).trim() || 'main'
101
+ }
@@ -0,0 +1,72 @@
1
+ # fabrika-platform ({{ACCOUNT}})
2
+
3
+ The **per-account root of trust** for the {{ACCOUNT}} Cloudflare account. Its GitHub pipeline deploys the
4
+ fabrika control-plane base so the control plane never deploys itself:
5
+
6
+ ```
7
+ Stage 1 — IAM (root authz)
8
+ Stage 2 — Operations
9
+ Stage 3 — fabrika runner + control plane
10
+ apps (poplach, revizor, …) ← deployed through fabrika, not here
11
+ ```
12
+
13
+ Generated and maintained by **`fabrika platform init --provider=cloudflare {{ACCOUNT}}`** (`@fabrika/cli`). Secrets and variables live in
14
+ the **`{{ACCOUNT}}` GitHub Environment** (Settings → Environments) and are written there by the CLI.
15
+ Scaffold commits use `[skip ci]`; init explicitly dispatches the workflow only after that Environment is configured.
16
+
17
+ Every credential this installation has is in that Environment — the Cloudflare API token, the vault KEK,
18
+ IAM's signing key, the provisioning key and `FABRIKA_RUNNER_KEY` (the shared key the
19
+ control plane presents to the deploy runner; Stage 3 pushes it to both Workers). Init therefore protects
20
+ `main` (no force pushes, no deletions) on a repository it creates, and restricts the Environment to
21
+ protected branches. The two go together: the Environment policy admits any branch that carries no
22
+ protection rule, so it is worth nothing on its own. GitHub Free offers neither on a private repository —
23
+ if init warned that one was refused, run the command it printed once the plan allows it.
24
+
25
+ Whatever the plan, add yourself as a **required reviewer** on the `{{ACCOUNT}}` Environment
26
+ (Settings → Environments → {{ACCOUNT}} → Required reviewers). It is the only rule that stops a push to
27
+ `main` from spending these credentials without a human first agreeing to it. Init deliberately does not
28
+ set it: it turns every deploy into an approval click, which is the operator's call and not the CLI's.
29
+
30
+ `contember/fabrika-platform` is public and pinned in [`fabrika.ref`](./fabrika.ref). The pipeline checks it
31
+ out once, then runs `fabrika platform deploy --provider=cloudflare` three times: `--component-config` for
32
+ IAM, `--component-config` for Operations, and the `--runner-config`/`--worker-config` pair for
33
+ `packages/runner-cloudflare` and `packages/control`. Every stage is a PLATFORM deploy because each names a
34
+ platform resource; `fabrika app deploy` is for applications and is refused one. The workflow builds the runner image from that same checkout into this account's
35
+ registry. It never depends on an image published by upstream CI or another account. Re-running it is
36
+ a safe redeploy.
37
+
38
+ ## First bring-up
39
+
40
+ Run init with the Cloudflare API token in `CLOUDFLARE_API_TOKEN`:
41
+
42
+ ```sh
43
+ fabrika platform init --provider=cloudflare {{ACCOUNT}} \
44
+ --console-host=<host> --operations-host=<host> --iam-host=<host> \
45
+ --auth-methods=<oidc|password|oidc,password> --email-provider=<none|resend>
46
+ ```
47
+
48
+ `fabrika platform init --provider=cloudflare --help` lists the optional flags. It creates this repo,
49
+ the Environment with its secrets and variables, and triggers the workflow. The run builds and pushes the
50
+ runner container image into the account.
51
+
52
+ Public repositories deploy without a GitHub App. To deploy private repositories, connect GitHub from the
53
+ control plane at **Settings → Source**: each connection is an organization-owned GitHub App whose key
54
+ Control keeps in its encrypted vault, never in this Environment.
55
+
56
+ To close the escape hatch once IAM grants you admin, set the `{{ACCOUNT}}` Environment variable
57
+ `FABRIKA_CONTROL_BOOTSTRAP_ADMINS` to `[]` and re-run the workflow.
58
+
59
+ IAM authentication methods are independent Environment switches: `FABRIKA_IAM_OIDC_ENABLED` and
60
+ `FABRIKA_IAM_PASSWORD_ENABLED`. At least one must be `true`. Password enrollment is managed through
61
+ IAM provisioning and its admin surface. Email delivery is optional; `FABRIKA_EMAIL_PROVIDER=none`
62
+ keeps password enrollment and reset admin-driven, while `resend` also requires the sender variable
63
+ and the Resend API key secret.
64
+
65
+ ## Routine redeploy or version bump
66
+
67
+ - Bump [`fabrika.ref`](./fabrika.ref) to a new `contember/fabrika-platform` commit or tag and push.
68
+ - Or run _Actions → platform → Run workflow_ manually.
69
+
70
+ Both paths rebuild the account-owned runner image from the exact checkout selected by `fabrika.ref`.
71
+
72
+ `fabrika.ref` is operator-owned. `fabrika platform init` creates it once and does not overwrite later version pins.
@@ -0,0 +1 @@
1
+ main
@@ -0,0 +1,2 @@
1
+ # The fabrika CLI persists collected secrets/values here for resume — NEVER commit it.
2
+ .env
@@ -0,0 +1,181 @@
1
+ name: platform
2
+
3
+ # Deploys the {{ACCOUNT}} account's fabrika BASE: IAM (Stage 1, root authz) → Operations (Stage 2) →
4
+ # runner + control plane (Stage 3). THIS repo is the per-account root of trust, so the control plane
5
+ # never deploys itself.
6
+ # Idempotent: re-run for a first bring-up OR a routine redeploy. Concrete apps deploy through fabrika.
7
+ #
8
+ # Generated + maintained by `fabrika platform init --provider=cloudflare {{ACCOUNT}}`. Secrets + variables live in the `{{ACCOUNT}}` GitHub
9
+ # Environment (Settings → Environments → {{ACCOUNT}}) and are written there by the CLI — don't hand-edit them.
10
+ #
11
+ # contember/fabrika-platform is public and checked out tokenless. The version this account runs is pinned
12
+ # in `fabrika.ref` (bump it and push to roll out a new base).
13
+
14
+ on:
15
+ workflow_dispatch:
16
+ inputs:
17
+ retire_legacy_propustka_worker:
18
+ description: >-
19
+ Name of a LEGACY propustka Worker to delete BEFORE Stage 1 (one-off migration off an old
20
+ deploy — e.g. a CF-Access-era `mangoweb-propustka-worker`). Deleting it releases its Custom
21
+ Domain so the new env-prod propustka can claim it. Empty = skip (the normal case).
22
+ type: string
23
+ default: ''
24
+ push:
25
+ branches: [main]
26
+ # Only a version bump (or a workflow edit) redeploys — not a README tweak.
27
+ paths: ['fabrika.ref', '.github/workflows/platform.yml']
28
+
29
+ concurrency:
30
+ group: platform-deploy
31
+ cancel-in-progress: false
32
+
33
+ permissions:
34
+ contents: read
35
+
36
+ jobs:
37
+ deploy:
38
+ runs-on: ubuntu-latest
39
+ timeout-minutes: 25
40
+ # Secrets + variables resolve from this GitHub Environment (created + populated by `fabrika platform init`).
41
+ environment: {{ACCOUNT}}
42
+ # Cloudflare creds at the JOB level so EVERY oblaka/wrangler step (provision, migrate, deploy, secret
43
+ # put) inherits them — wrangler errors in a non-interactive shell without CLOUDFLARE_API_TOKEN.
44
+ env:
45
+ CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
46
+ CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
47
+ steps:
48
+ - name: Checkout this repo (base config + pinned refs)
49
+ uses: actions/checkout@v5
50
+
51
+ - name: Resolve pinned refs
52
+ id: ref
53
+ run: echo "fabrika=$(tr -d '[:space:]' < fabrika.ref)" >> "$GITHUB_OUTPUT"
54
+
55
+ - name: Checkout contember/fabrika-platform@${{ steps.ref.outputs.fabrika }}
56
+ uses: actions/checkout@v5
57
+ with:
58
+ repository: contember/fabrika-platform
59
+ ref: ${{ steps.ref.outputs.fabrika }}
60
+ path: fabrika-platform
61
+
62
+ - uses: oven-sh/setup-bun@v2
63
+ with:
64
+ bun-version: latest
65
+ # wrangler launches under Node even via Bun and needs Node 22+.
66
+ - uses: actions/setup-node@v5
67
+ with:
68
+ node-version: '24'
69
+
70
+ - name: Install fabrika
71
+ working-directory: fabrika-platform
72
+ run: bun install
73
+
74
+ # The Cloudflare provider spawns a BARE `wrangler` (Bun.spawn), so the workspace bins must be on PATH.
75
+ - name: Put fabrika workspace bins on PATH
76
+ working-directory: fabrika-platform
77
+ # `fabrika` itself is asserted rather than assumed: `bun install` links a workspace package's bin
78
+ # only when the root package depends on it, so an older pinned tag can install cleanly and still
79
+ # have no `fabrika` at all — a bare `command not found` several steps later, naming nothing.
80
+ run: |
81
+ if [ ! -x node_modules/.bin/fabrika ]; then
82
+ echo "fabrika-platform@${{ steps.ref.outputs.fabrika }} installed no \`fabrika\` binary." >&2
83
+ echo "Pin a tag whose root package.json depends on @fabrika/cli." >&2
84
+ exit 1
85
+ fi
86
+ echo "$PWD/node_modules/.bin" >> "$GITHUB_PATH"
87
+ echo "$PWD/packages/control/node_modules/.bin" >> "$GITHUB_PATH"
88
+ echo "$PWD/packages/runner-cloudflare/node_modules/.bin" >> "$GITHUB_PATH"
89
+
90
+ # ── Migration escape hatch — retire a legacy propustka Worker ─────────────────────────────────────
91
+ # Off by default. When `retire_legacy_propustka_worker` is set, delete that Worker so its Custom Domain
92
+ # is freed for the new env-prod propustka below. Its D1 database is NOT deleted (a Worker delete leaves
93
+ # databases) — orphaned, prune it by hand later. One-off: clear the input on subsequent runs.
94
+ - name: Retire legacy propustka Worker
95
+ if: ${{ inputs.retire_legacy_propustka_worker != '' }}
96
+ env:
97
+ CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
98
+ CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
99
+ LEGACY: ${{ inputs.retire_legacy_propustka_worker }}
100
+ # `wrangler delete` is non-interactive in CI (no TTY → no confirmation prompt). Removing the Worker
101
+ # detaches its Custom Domain. If the domain attach below races a just-freed hostname, re-run (idempotent).
102
+ run: bunx wrangler delete --name "$LEGACY"
103
+
104
+ # ── Stage 1 — IAM (root authz) ───────────────────────────────────────────────────────────────────
105
+ # IAM is a regular Cloudflare provider bundle. Its empty schema needs no self-reconcile.
106
+ - name: Deploy IAM
107
+ working-directory: fabrika-platform/packages/iam
108
+ env:
109
+ CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
110
+ CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
111
+ CLOUDFLARE_STATE_NAMESPACE: propustka-state
112
+ FABRIKA_CONTROL_DOMAIN: ${{ vars.FABRIKA_IAM_HOSTNAME }}
113
+ # Non-secret config (Environment Variables).
114
+ FABRIKA_IAM_HUMAN_EMAIL_DOMAINS: ${{ vars.FABRIKA_IAM_HUMAN_EMAIL_DOMAINS }}
115
+ FABRIKA_IAM_HUMAN_EMAILS: ${{ vars.FABRIKA_IAM_HUMAN_EMAILS }}
116
+ FABRIKA_IAM_BOOTSTRAP_ADMINS: ${{ vars.FABRIKA_IAM_BOOTSTRAP_ADMINS }}
117
+ FABRIKA_IAM_OIDC_ENABLED: ${{ vars.FABRIKA_IAM_OIDC_ENABLED }}
118
+ FABRIKA_IAM_PASSWORD_ENABLED: ${{ vars.FABRIKA_IAM_PASSWORD_ENABLED }}
119
+ FABRIKA_IAM_OIDC_ISSUER: ${{ vars.FABRIKA_IAM_OIDC_ISSUER }}
120
+ FABRIKA_IAM_OIDC_CLIENT_ID: ${{ vars.FABRIKA_IAM_OIDC_CLIENT_ID }}
121
+ FABRIKA_IAM_OIDC_SCOPES: ${{ vars.FABRIKA_IAM_OIDC_SCOPES }}
122
+ FABRIKA_IAM_OIDC_REQUIRE_VERIFIED_EMAIL: ${{ vars.FABRIKA_IAM_OIDC_REQUIRE_VERIFIED_EMAIL }}
123
+ FABRIKA_EMAIL_PROVIDER: ${{ vars.FABRIKA_EMAIL_PROVIDER }}
124
+ FABRIKA_EMAIL_FROM: ${{ vars.FABRIKA_EMAIL_FROM }}
125
+ FABRIKA_IAM_SIGNING_KEYS: ${{ secrets.FABRIKA_IAM_SIGNING_KEYS }}
126
+ OIDC_CLIENT_SECRET: ${{ secrets.FABRIKA_IAM_OIDC_CLIENT_SECRET }}
127
+ FABRIKA_EMAIL_RESEND_API_KEY: ${{ secrets.FABRIKA_EMAIL_RESEND_API_KEY }}
128
+ FABRIKA_IAM_PROVISIONING_KEY: ${{ secrets.FABRIKA_IAM_PROVISIONING_KEY }}
129
+ # `platform deploy`, not `app deploy`: IAM's own Worker is a PLATFORM resource name, and only the
130
+ # platform verb may name one. The single-component form deploys just this config.
131
+ run: fabrika platform deploy --provider=cloudflare --env=prod --component-config=fabrika.config.ts
132
+
133
+ # ── Stage 2 — Operations ────────────────────────────────────────────────────────────────────────
134
+ # Operations must exist before control: control carries a private service binding to it.
135
+ - name: Deploy Operations
136
+ working-directory: fabrika-platform/packages/operations
137
+ env:
138
+ CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
139
+ CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
140
+ # The provider's app-deploy adapter reads FABRIKA_CONTROL_DOMAIN as the selected app domain.
141
+ FABRIKA_CONTROL_DOMAIN: ${{ vars.OPERATIONS_HOSTNAME }}
142
+ FABRIKA_IAM_ISSUER: ${{ vars.FABRIKA_IAM_ISSUER }}
143
+ OPERATIONS_SYNC_KEY: ${{ secrets.OPERATIONS_SYNC_KEY }}
144
+ run: fabrika platform deploy --provider=cloudflare --env=prod --component-config=fabrika.config.ts
145
+
146
+ # ── Stage 3 — fabrika platform (executor + control plane) ────────────────────────────────────────
147
+ - name: Deploy fabrika runner + control plane
148
+ id: platform
149
+ working-directory: fabrika-platform
150
+ env:
151
+ CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
152
+ CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
153
+ FABRIKA_CONTROL_VAULT_KEY: ${{ secrets.FABRIKA_CONTROL_VAULT_KEY }}
154
+ # The seeded IAM provisioning key — the control plane reconciles its own schema with it (Bearer px_).
155
+ FABRIKA_IAM_PROVISIONING_KEY: ${{ secrets.FABRIKA_IAM_PROVISIONING_KEY }}
156
+ OPERATIONS_SYNC_KEY: ${{ secrets.OPERATIONS_SYNC_KEY }}
157
+ # `wrangler secret put FABRIKA_RUNNER_KEY` on BOTH Workers this step deploys: the control plane
158
+ # presents it to the deploy runner, and the runner rejects an RPC caller without it. One step,
159
+ # one value, because a mismatched pair breaks every deploy.
160
+ FABRIKA_RUNNER_KEY: ${{ secrets.FABRIKA_RUNNER_KEY }}
161
+ # Non-secret config (Environment Variables).
162
+ FABRIKA_CONTROL_DOMAIN: ${{ vars.FABRIKA_CONTROL_DOMAIN }}
163
+ FABRIKA_IAM_ISSUER: ${{ vars.FABRIKA_IAM_ISSUER }}
164
+ OPERATIONS_ARTIFACT_ORIGIN: https://${{ vars.OPERATIONS_HOSTNAME }}
165
+ FABRIKA_CONTROL_BOOTSTRAP_ADMINS: ${{ vars.FABRIKA_CONTROL_BOOTSTRAP_ADMINS }}
166
+ run: |
167
+ fabrika platform deploy --provider=cloudflare \
168
+ --runner-config=packages/runner-cloudflare/fabrika-runner.config.ts \
169
+ --worker-config=packages/control/fabrika.config.ts
170
+
171
+ - name: Summary
172
+ if: always()
173
+ run: |
174
+ {
175
+ echo "### platform deploy → {{ACCOUNT}}"
176
+ echo ""
177
+ echo "- fabrika ref: \`${{ steps.ref.outputs.fabrika || '(unresolved)' }}\`"
178
+ echo "- platform deploy: \`${{ steps.platform.outcome || 'not run' }}\`"
179
+ echo "- runner image source: account-local build from the pinned fabrika checkout"
180
+ echo "- retired legacy propustka: \`${{ inputs.retire_legacy_propustka_worker || '(none)' }}\`"
181
+ } >> "$GITHUB_STEP_SUMMARY"
package/src/plan.ts CHANGED
@@ -1,16 +1,13 @@
1
- import type { ProviderDeployPlan, ProviderJobSpec } from '@fabrika/provider-contract'
2
- import { isProxyHost } from '@fabrika/proxy-contract'
1
+ import { isProxyHost } from '@fabrika/proxy-core/manifest'
3
2
  import { Container, D1Database, KVNamespace, Queue, R2Bucket, ServiceReference, Worker } from 'oblaka-iac'
4
3
  import type { CloudflareAppConfig } from './authoring'
5
4
 
6
5
  export type CloudflareStepKind = 'build' | 'provision-resources' | 'migrate' | 'deploy-worker' | 'reconcile-schema' | 'sync-secrets'
7
6
 
8
- export interface CloudflareJobSpec extends ProviderJobSpec {
7
+ export interface CloudflareStep {
8
+ readonly id: string
9
9
  readonly kind: CloudflareStepKind
10
- }
11
-
12
- export interface CloudflarePlan extends ProviderDeployPlan {
13
- readonly steps: readonly CloudflareJobSpec[]
10
+ readonly description: string
14
11
  }
15
12
 
16
13
  export interface MigratableDatabase {
@@ -262,43 +259,36 @@ export const assertAuthoredGraph = (root: Worker, limits: AuthoredGraphLimits):
262
259
  visit(root)
263
260
  }
264
261
 
265
- export interface CloudflarePlanInput {
266
- readonly appId: string
267
- readonly env: string
268
- }
269
-
270
- export const buildPlan = (
271
- config: CloudflareAppConfig,
272
- input: CloudflarePlanInput,
273
- worker: Worker,
274
- ): CloudflarePlan => {
275
- const steps: CloudflareJobSpec[] = []
276
- let previous: string | undefined
277
-
278
- const add = (spec: Omit<CloudflareJobSpec, 'dependsOn'>): void => {
279
- steps.push(previous === undefined ? spec : { ...spec, dependsOn: [previous] })
280
- previous = spec.id
281
- }
262
+ export const buildPlan = (config: CloudflareAppConfig, worker: Worker): readonly CloudflareStep[] => {
263
+ const steps: CloudflareStep[] = []
282
264
 
283
265
  if (config.pipeline?.build !== undefined) {
284
- add({ id: 'build', kind: 'build', description: `Build the Worker (\`${config.pipeline.build}\`)` })
266
+ steps.push({ id: 'build', kind: 'build', description: `Build the Worker (\`${config.pipeline.build}\`)` })
285
267
  }
286
268
 
287
- add({ id: 'provision-resources', kind: 'provision-resources', description: 'Provision Cloudflare resources via oblaka' })
269
+ steps.push({ id: 'provision-resources', kind: 'provision-resources', description: 'Provision Cloudflare resources via oblaka' })
288
270
 
289
271
  for (const database of findMigratableDatabases(worker)) {
290
- add({ id: `migrate:${database.binding}`, kind: 'migrate', description: `Apply D1 migrations for \`${database.binding}\` (${database.name})` })
272
+ steps.push({
273
+ id: `migrate:${database.binding}`,
274
+ kind: 'migrate',
275
+ description: `Apply D1 migrations for \`${database.binding}\` (${database.name})`,
276
+ })
291
277
  }
292
278
 
293
- add({ id: 'deploy-worker', kind: 'deploy-worker', description: 'Deploy the Worker (`wrangler deploy`)' })
279
+ steps.push({ id: 'deploy-worker', kind: 'deploy-worker', description: 'Deploy the Worker (`wrangler deploy`)' })
294
280
 
295
281
  if (config.schema !== undefined) {
296
- add({ id: 'reconcile-schema', kind: 'reconcile-schema', description: 'Report the authz schema for the control plane to reconcile into IAM' })
282
+ steps.push({ id: 'reconcile-schema', kind: 'reconcile-schema', description: 'Report the authz schema for the control plane to reconcile into IAM' })
297
283
  }
298
284
 
299
285
  if (config.pipeline?.secrets !== undefined && config.pipeline.secrets.length > 0) {
300
- add({ id: 'sync-secrets', kind: 'sync-secrets', description: `Sync ${config.pipeline.secrets.length} secret(s) via \`wrangler secret put\`` })
286
+ steps.push({
287
+ id: 'sync-secrets',
288
+ kind: 'sync-secrets',
289
+ description: `Sync ${config.pipeline.secrets.length} secret(s) via \`wrangler secret put\``,
290
+ })
301
291
  }
302
292
 
303
- return { appId: input.appId, env: input.env, steps }
293
+ return steps
304
294
  }