aboutsummaryrefslogtreecommitdiffstats
path: root/docs/cf.md
blob: fbfea238a035e8aebf5d133d423f7b22be050eb0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# Using `cf` instead of Wrangler
 
[`cf`](https://developers.cloudflare.com/cf/) is Cloudflare's CLI for the
whole public API. It can replace Wrangler for dgit, but not as a drop-in
yet. This page records what works today, what needs a migration, and the
migration steps for this repository.
 
Checked against `cf` 1.0.0-beta.20 and the Cloudflare docs of October
2026. `cf` is in beta; commands and configuration can change.
 
## Compatibility at a glance
 
| Task | Wrangler (today) | `cf` without migration | `cf` after `cf migrate` |
| --- | --- | --- | --- |
| Configuration file | `wrangler.jsonc` | not read | `cloudflare.config.ts` |
| Sign in | `wrangler login` | `cf auth login` (separate credentials) | same |
| Local dev | `wrangler dev` | **do not run** | `cf dev` |
| Deploy | `wrangler deploy` | **do not run** | `cf deploy` |
| Create the R2 bucket | `wrangler r2 bucket create dgit-pack-cache` | `cf r2 buckets create --name dgit-pack-cache` | same |
| Set `GIT_TOKEN` | `wrangler secret put GIT_TOKEN` | not supported | `cf deploy --secrets-file <file>` |
| Live logs | `wrangler tail` | not supported | not supported; use `npx wrangler tail git-cells` |
| Versions, deployments | `wrangler versions/deployments` | `cf workers versions/deployments` | same |
| celld (`wrangler.celld.jsonc`) | read by `celld deploy` | unaffected | unaffected |
 
In short:
 
- **Resource and account commands work now.** `cf r2 ...`,
  `cf workers deployments ...`, `cf durable-objects ...` and similar call
  the API directly and ignore `wrangler.jsonc`. They do not use its
  `account_id`: set `CLOUDFLARE_ACCOUNT_ID` or pick an account when `cf`
  asks. Both tools read `CLOUDFLARE_API_TOKEN` and
  `CLOUDFLARE_ACCOUNT_ID` in CI.
- **Project commands need a migration.** `cf dev`, `cf build`, and
  `cf deploy` read only `cloudflare.config.ts`. In this repository,
  without that file, they fail or run automatic configuration, which
  writes its own config and changes `package.json`. Do not run them
  until you have run `cf migrate`.
- **Project commands still use Wrangler underneath.** With the Wrangler
  bundler, `cf build` and `cf deploy` run the project's own Wrangler,
  which must be 4.136.0 or later. The lockfile pins 4.123.0, so
  `cf deploy` currently stops with
  `cf requires wrangler@4.136.0 or newer`.
 
## Finding commands
 
`cf` has more than 2,900 commands. Search instead of walking `--help`:
 
```sh
cf cli search "create an r2 bucket"      # five JSON matches
cf r2 buckets create --help              # flags for one match
cf schema r2 buckets create              # the underlying API request
cf docs search "durable object exports"  # Cloudflare docs, ranked
```
 
Keep search queries generic. Do not put account IDs, domains, or tokens
in them.
 
## Use `cf` next to Wrangler (no migration)
 
Keep deploying with Wrangler as the [README](../README.md) shows, and use
`cf` for the resources around the Worker:
 
```sh
cf auth login
cf auth whoami
cf r2 buckets create --name dgit-pack-cache   # optional R2 pack offload
cf r2 buckets list
cf workers deployments list --worker git-cells
```
 
`cf` resource commands take the IDs the API expects, not friendly names,
for most resources (for example, D1 database IDs). Check `--help` when a
name is rejected.
 
## Migrate this repository to `cf`
 
A dry run on this repository reports three required follow-ups: both
Durable Object bindings (`REPO`, `REGISTRY`) and the `migrations` block.
`cf migrate` keeps the Worker name, routes, R2 binding, `vars`, and
limits.
 
1. Start from a clean worktree and a current Wrangler:
 
   ```sh
   git status                       # must be clean
   npm install --save-dev wrangler@latest   # 4.136.0 or later
   git commit -am "chore(deps): update wrangler for cf"
   ```
 
2. Preview, then migrate. Pass the path, because the directory also has
   `wrangler.celld.jsonc`:
 
   ```sh
   cf migrate wrangler.jsonc --dry-run
   cf migrate wrangler.jsonc
   ```
 
   This writes `cloudflare.config.ts` (and `wrangler.config.ts` for build
   settings), adds `cf` as a dev dependency, and leaves `wrangler.jsonc`
   unchanged. The generated config starts with a `throw` until the
   follow-ups are resolved.
 
3. Resolve the Durable Object follow-ups. Both classes were created with
   `new_sqlite_classes`, so declare them with SQLite storage under
   `worker`:
 
   ```ts
   import { bindings, defineConfig, exports } from "cf/config";
 
   // inside worker: { ... }
   exports: {
     RepoCell: exports.durableObject({ storage: "sqlite" }),
     Registry: exports.durableObject({ storage: "sqlite" }),
   },
   ```
 
   Check that each generated binding reads
   `bindings.durableObject({ worker: "git-cells", exportName: "RepoCell" })`
   (and `"Registry"`). Do not copy the `migrations` history; the
   `v1` tag is already applied. Then delete the `TODO(@cloudflare)`
   comments and the `throw` statement.
 
4. Declare the secret, so the Worker's `env` type includes it:
 
   ```ts
   // inside worker.env
   GIT_TOKEN: bindings.secret(),
   ```
 
5. Finish the project:
 
   - In `package.json`, set `"dev": "cf dev"` and `"deploy": "cf deploy"`.
     (`"type": "module"` is already set.)
   - Add `.cloudflare/` to `.gitignore`.
   - Add `"cloudflare.config.ts"` and `".cloudflare/types"` to
     `include` in `tsconfig.json`, then generate types with
     `cf workers types`.
 
6. Validate without uploading, then deploy:
 
   ```sh
   cf dev                 # check that the index page loads, then stop it
   cf build
   cf deploy --dry-run    # prints bindings; must show REPO, REGISTRY, PACK_CACHE
   cf deploy
   ```
 
   The dry run must list the Worker as `git-cells`. A different name
   deploys a new, empty Worker, and the existing repositories stay bound
   to the old one.
 
## Secrets with `cf`
 
`cf` cannot set one secret on its own yet. Choose one:
 
- Upload with a deploy. Put the token in a file that git ignores (for
  example, `.dev.vars`, which is already in `.gitignore`) and run
  `cf deploy --secrets-file .dev.vars`. This makes a new Worker Version
  that includes the secret.
- Keep using Wrangler for this one step:
  `npx wrangler secret put GIT_TOKEN --name git-cells`.
 
Do not pass the token with `--text` on the command line; it stays in the
shell history and the process list.
 
## Keep `wrangler.jsonc`
 
After the migration, keep `wrangler.jsonc` while you still need Wrangler
for `wrangler tail` or `wrangler secret put`: Wrangler does not read
`cloudflare.config.ts`. While both files exist, change bindings, routes,
and `vars` in both, or the two tools deploy different Workers.
 
`wrangler.celld.jsonc` is for celld, not for `cf`. Keep it, and pass its
path to `cf migrate` only if you want a `cf` config for that target too.