Diffinery

homeflare/diffinerypublic

Open-source, agent-first GitHub and GitHub Actions alternative that runs on your own Cloudflare account: git hosting, pull requests, code review and drop-in GitHub Actions YAML on Workers, Durable Objects, R2 and Containers.

diffinery/apps/diffinery/wrangler.jsonc
183 lines · 11.7 KBRaw History
1// Diffinery: one Worker, everything on Cloudflare.
2// `scripts/bootstrap.sh` creates the account resources and writes
3// wrangler.deploy.jsonc (this file plus real IDs) for CI deploys.
4{
5 "$schema": "node_modules/wrangler/config-schema.json",
6 "name": "diffinery",
7 "main": "src/index.ts",
8 "compatibility_date": "2026-10-01",
9 "compatibility_flags": ["nodejs_compat"],
10 "workers_dev": false,
11 // A zone route, not a Custom Domain: diffinery.com already has DNS records, and a
12 // route runs the Worker in front of them as long as the record is proxied (orange cloud).
13 "routes": [{ "pattern": "diffinery.com/*", "zone_name": "diffinery.com" }],
14 "observability": { "enabled": true, "head_sampling_rate": 1 },
15 // The deployed version's id and time: IndexNow checks the site's pages once per new version (src/web/indexnow.ts).
16 "version_metadata": { "binding": "CF_VERSION_METADATA" },
17 "upload_source_maps": true,
18 "limits": { "cpu_ms": 300000 },
19
20 "vars": {
21 "PUBLIC_URL": "https://diffinery.com",
22 "MAIL_FROM": "[email protected]",
23 // Emails that become site administrators on first sign-in. Left empty here: the deploy takes the
24 // list from the BOOTSTRAP_ADMINS environment variable, else keeps the deployed Worker's (scripts/bootstrap-admins.sh).
25 "BOOTSTRAP_ADMINS": "",
26 "ACCESS_TEAM_DOMAIN": "",
27 "ACCESS_AUD": ""
28 },
29
30 "d1_databases": [
31 { "binding": "DB", "database_name": "diffinery", "database_id": "00000000-0000-0000-0000-000000000000", "migrations_dir": "migrations" }
32 ],
33 "r2_buckets": [{ "binding": "BUCKET", "bucket_name": "diffinery-data" }],
34 "queues": {
35 "producers": [
36 { "binding": "EVENTS", "queue": "diffinery-events" },
37 { "binding": "MAIL", "queue": "diffinery-mail" }
38 ],
39 "consumers": [
40 // 20 events per batch: each makes D1 queries (webhooks, notifications, audit), and one consumer
41 // invocation may make at most 1,000.
42 { "queue": "diffinery-events", "max_batch_size": 20, "max_batch_timeout": 2, "max_retries": 8, "dead_letter_queue": "diffinery-events-dlq" },
43 { "queue": "diffinery-mail", "max_batch_size": 20, "max_batch_timeout": 2, "max_retries": 8, "dead_letter_queue": "diffinery-mail-dlq" },
44 // Bounces and complaints: subscribe this queue to Email Sending's events (docs/admin/site-administration.md).
45 { "queue": "diffinery-mail-events", "max_batch_size": 50, "max_batch_timeout": 5, "max_retries": 8 }
46 ]
47 },
48 // Cloudflare Email Sending (notifications, security alerts, invites). The sending
49 // domain is onboarded under Compute > Email Service > Email Sending (see scripts/email-sending.sh).
50 "send_email": [{ "name": "EMAIL" }],
51 // Request rate limits per minute (src/lib/rate-limit.ts; RATE_LIMITS there must match). Local
52 // development declares none, so nothing is limited there.
53 "ratelimits": [
54 { "name": "RL_AUTH", "namespace_id": "1001", "simple": { "limit": 20, "period": 60 } },
55 { "name": "RL_ANON", "namespace_id": "1002", "simple": { "limit": 300, "period": 60 } },
56 { "name": "RL_ACCOUNT", "namespace_id": "1003", "simple": { "limit": 2000, "period": 60 } },
57 { "name": "RL_CREATE", "namespace_id": "1004", "simple": { "limit": 60, "period": 60 } },
58 // Model requests through the proxy (/-/model/*), per paying person (agentic/proxy.ts MODEL_RATE_LIMIT).
59 { "name": "RL_MODEL", "namespace_id": "1005", "simple": { "limit": 600, "period": 60 } }
60 ],
61 "durable_objects": {
62 "bindings": [
63 { "name": "REPO", "class_name": "RepoDO" },
64 { "name": "SCHEDULER", "class_name": "SchedulerDO" },
65 { "name": "COMPOSE", "class_name": "ComposeDO" },
66 { "name": "RUNNER", "class_name": "RunnerContainer" },
67 // Smaller hosted runners (src/runner/sizes.ts), the same runner on smaller instance types.
68 { "name": "RUNNER_MEDIUM", "class_name": "RunnerContainerMedium" },
69 { "name": "RUNNER_SMALL", "class_name": "RunnerContainerSmall" },
70 { "name": "RUNNER_TINY", "class_name": "RunnerContainerTiny" },
71 { "name": "SANDBOX", "class_name": "SandboxContainer" },
72 { "name": "IMPORTER", "class_name": "ImportContainer" },
73 { "name": "PROJECT", "class_name": "ProjectDO" },
74 // GitHub jobs on Diffinery runners, one per paying account (src/github-runners/GitHubRunnersDO.ts).
75 { "name": "GITHUB_RUNNERS", "class_name": "GitHubRunnersDO" }
76 ]
77 },
78 "migrations": [
79 { "tag": "v1", "new_sqlite_classes": ["RepoDO", "RunnerContainer", "SandboxContainer"] },
80 { "tag": "v2", "new_sqlite_classes": ["ImportContainer"] },
81 // Agent tasks, one Durable Object per repository (agentic/ProjectDO.ts).
82 { "tag": "v3", "new_sqlite_classes": ["ProjectDO"] },
83 // Workflow schedules (scheduler.ts).
84 { "tag": "v4", "new_sqlite_classes": ["SchedulerDO"] },
85 // Smaller hosted runner sizes (src/runner/sizes.ts).
86 { "tag": "v5", "new_sqlite_classes": ["RunnerContainerMedium", "RunnerContainerSmall", "RunnerContainerTiny"] },
87 // Joining large uploads' blocks, a step per object (compose.ts).
88 { "tag": "v6", "new_sqlite_classes": ["ComposeDO"] },
89 // GitHub jobs on Diffinery runners (src/github-runners/GitHubRunnersDO.ts).
90 { "tag": "v7", "new_sqlite_classes": ["GitHubRunnersDO"] }
91 ],
92 "workflows": [
93 { "name": "diffinery-run", "binding": "RUN_WORKFLOW", "class_name": "RunWorkflow" },
94 { "name": "diffinery-import", "binding": "IMPORT_WORKFLOW", "class_name": "ImportWorkflow" },
95 // Account exports and deletions (src/accounts/workflow.ts).
96 { "name": "diffinery-account", "binding": "ACCOUNT_WORKFLOW", "class_name": "AccountWorkflow" }
97 ],
98 // A deploy that changes the image rolls the running containers: once a container has been up
99 // longer than rollout_active_grace_period seconds, it gets SIGTERM and is killed 15 minutes later.
100 // Runner and import containers are covered for their whole life (a job is capped at 6 hours, an
101 // import transfer too), so a deploy shouldn't cut one short; they pick up the new image next start.
102 // The platform doesn't guarantee it: a job that started on an old-image container during a rollout
103 // was replaced minutes in. So a runner on a replaced image is turned away before it runs anything
104 // (repo/actions.ts STALE_IMAGE_TRIES), and a job whose runner is replaced before its steps ran
105 // starts again on a new one (MAX_RUNNER_RESTARTS).
106 // The rollout is one step (rollout_step_percentage 100): with the default [10, 100], the first
107 // step still starts 90% of new containers on the old image, and the next step replaced such a
108 // job's container seconds after it started. The rollout's SIGTERM reaches every process in the
109 // container, so the job's steps died with it.
110 "containers": [
111 // standard-4 (4 vCPU, 12 GiB, 20 GB): standard-2 has 1 vCPU, on which typecheck and test steps took
112 // 2.3 to 2.6 times as long. Active CPU is what's billed, so a faster job costs about the same.
113 { "class_name": "RunnerContainer", "image": "../../containers/runner/Dockerfile", "image_build_context": "../../containers/runner", "instance_type": "standard-4", "max_instances": 100, "rollout_active_grace_period": 23400, "rollout_step_percentage": 100 },
114 // Smaller sizes for jobs that use little of a large runner (src/runner/sizes.ts): Cloudflare bills a container's
115 // memory and disk as provisioned, used or not, so a job that waits on the network costs a large runner's memory.
116 // A job gets one when runs-on asks for it, or when its own earlier runs show it fits with room to spare.
117 { "class_name": "RunnerContainerMedium", "image": "../../containers/runner/Dockerfile", "image_build_context": "../../containers/runner", "instance_type": "standard-3", "max_instances": 100, "rollout_active_grace_period": 23400, "rollout_step_percentage": 100 },
118 { "class_name": "RunnerContainerSmall", "image": "../../containers/runner/Dockerfile", "image_build_context": "../../containers/runner", "instance_type": "standard-1", "max_instances": 100, "rollout_active_grace_period": 23400, "rollout_step_percentage": 100 },
119 { "class_name": "RunnerContainerTiny", "image": "../../containers/runner/Dockerfile", "image_build_context": "../../containers/runner", "instance_type": "basic", "max_instances": 100, "rollout_active_grace_period": 23400, "rollout_step_percentage": 100 },
120 { "class_name": "SandboxContainer", "image": "../../containers/runner/Dockerfile", "image_build_context": "../../containers/runner", "instance_type": "standard-1", "max_instances": 50, "rollout_active_grace_period": 3600, "rollout_step_percentage": 100 },
121 // GitHub imports: a mirror clone of a large repository needs disk and memory.
122 { "class_name": "ImportContainer", "image": "../../containers/runner/Dockerfile", "image_build_context": "../../containers/runner", "instance_type": "standard-4", "max_instances": 20, "rollout_active_grace_period": 25200, "rollout_step_percentage": 100 }
123 ],
124 // Housekeeping, and a check that the workflow scheduler's alarm is set (src/scheduler.ts).
125 "triggers": { "crons": ["*/5 * * * *"] },
126
127 "env": {
128 // Local development and end-to-end tests: no Access, a fixed dev identity, no containers.
129 "dev": {
130 "routes": [],
131 "workers_dev": true,
132 "vars": {
133 "PUBLIC_URL": "http://localhost:8787",
134 "MAIL_FROM": "[email protected]",
135 "BOOTSTRAP_ADMINS": "[email protected]",
136 "ACCESS_TEAM_DOMAIN": "",
137 "ACCESS_AUD": "",
138 "DEV_AUTH": "[email protected]",
139 // Containers do not run under wrangler dev: an import agent started by hand (or by the e2e test) claims Git transfers.
140 "IMPORT_GIT_AGENT": "external"
141 },
142 "version_metadata": { "binding": "CF_VERSION_METADATA" },
143 "d1_databases": [{ "binding": "DB", "database_name": "diffinery-dev", "database_id": "00000000-0000-0000-0000-000000000000", "migrations_dir": "migrations" }],
144 "r2_buckets": [{ "binding": "BUCKET", "bucket_name": "diffinery-data-dev" }],
145 "queues": {
146 "producers": [
147 { "binding": "EVENTS", "queue": "diffinery-events-dev" },
148 { "binding": "MAIL", "queue": "diffinery-mail-dev" }
149 ],
150 "consumers": [
151 { "queue": "diffinery-events-dev", "max_batch_size": 50, "max_batch_timeout": 1 },
152 { "queue": "diffinery-mail-dev", "max_batch_size": 20, "max_batch_timeout": 1 },
153 { "queue": "diffinery-mail-events-dev", "max_batch_size": 50, "max_batch_timeout": 1 }
154 ]
155 },
156 // Local email: Miniflare captures sent messages instead of delivering them.
157 "send_email": [{ "name": "EMAIL" }],
158 "durable_objects": {
159 "bindings": [
160 { "name": "REPO", "class_name": "RepoDO" },
161 { "name": "SCHEDULER", "class_name": "SchedulerDO" },
162 { "name": "COMPOSE", "class_name": "ComposeDO" },
163 { "name": "RUNNER", "class_name": "RunnerContainer" },
164 { "name": "RUNNER_MEDIUM", "class_name": "RunnerContainerMedium" },
165 { "name": "RUNNER_SMALL", "class_name": "RunnerContainerSmall" },
166 { "name": "RUNNER_TINY", "class_name": "RunnerContainerTiny" },
167 // Sandboxes run in an `agent.mjs --sandbox-pool` process (SANDBOX_POOL_URL), not containers.
168 { "name": "SANDBOX", "class_name": "SandboxPoolDO" },
169 { "name": "IMPORTER", "class_name": "ImportContainer" },
170 { "name": "PROJECT", "class_name": "ProjectDO" },
171 { "name": "GITHUB_RUNNERS", "class_name": "GitHubRunnersDO" }
172 ]
173 },
174 "workflows": [
175 { "name": "diffinery-run-dev", "binding": "RUN_WORKFLOW", "class_name": "RunWorkflow" },
176 { "name": "diffinery-import-dev", "binding": "IMPORT_WORKFLOW", "class_name": "ImportWorkflow" },
177 { "name": "diffinery-account-dev", "binding": "ACCOUNT_WORKFLOW", "class_name": "AccountWorkflow" }
178 ],
179 "triggers": { "crons": [] },
180 "containers": []
181 }
182 }
183}