Diffinery

codician/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.

141 lines · 7.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 "upload_source_maps": true,
16 "limits": { "cpu_ms": 300000 },
17
18 "vars": {
19 "PUBLIC_URL": "https://diffinery.com",
20 "MAIL_FROM": "notifications@diffinery.com",
21 "BOOTSTRAP_ADMINS": "iletisim@canberkdemirci.com,canberkdemirci@icloud.com,iletisim@altugankarali.com",
22 "ACCESS_TEAM_DOMAIN": "",
23 "ACCESS_AUD": ""
24 },
25
26 "d1_databases": [
27 { "binding": "DB", "database_name": "diffinery", "database_id": "00000000-0000-0000-0000-000000000000", "migrations_dir": "migrations" }
28 ],
29 "r2_buckets": [{ "binding": "BUCKET", "bucket_name": "diffinery-data" }],
30 "queues": {
31 "producers": [
32 { "binding": "EVENTS", "queue": "diffinery-events" },
33 { "binding": "MAIL", "queue": "diffinery-mail" }
34 ],
35 "consumers": [
36 { "queue": "diffinery-events", "max_batch_size": 50, "max_batch_timeout": 2, "max_retries": 8, "dead_letter_queue": "diffinery-events-dlq" },
37 { "queue": "diffinery-mail", "max_batch_size": 20, "max_batch_timeout": 2, "max_retries": 8, "dead_letter_queue": "diffinery-mail-dlq" },
38 // Bounces and complaints: subscribe this queue to Email Sending's events (docs/admin/site-administration.md).
39 { "queue": "diffinery-mail-events", "max_batch_size": 50, "max_batch_timeout": 5, "max_retries": 8 }
40 ]
41 },
42 // Cloudflare Email Sending (notifications, security alerts, invites). The sending
43 // domain is onboarded under Compute > Email Service > Email Sending (see scripts/email-sending.sh).
44 "send_email": [{ "name": "EMAIL" }],
45 // Request rate limits per minute (src/lib/rate-limit.ts; RATE_LIMITS there must match). Local
46 // development declares none, so nothing is limited there.
47 "ratelimits": [
48 { "name": "RL_AUTH", "namespace_id": "1001", "simple": { "limit": 20, "period": 60 } },
49 { "name": "RL_ANON", "namespace_id": "1002", "simple": { "limit": 300, "period": 60 } },
50 { "name": "RL_ACCOUNT", "namespace_id": "1003", "simple": { "limit": 2000, "period": 60 } },
51 { "name": "RL_CREATE", "namespace_id": "1004", "simple": { "limit": 60, "period": 60 } }
52 ],
53 "durable_objects": {
54 "bindings": [
55 { "name": "REPO", "class_name": "RepoDO" },
56 { "name": "SCHEDULER", "class_name": "SchedulerDO" },
57 { "name": "RUNNER", "class_name": "RunnerContainer" },
58 { "name": "SANDBOX", "class_name": "SandboxContainer" },
59 { "name": "IMPORTER", "class_name": "ImportContainer" },
60 { "name": "PROJECT", "class_name": "ProjectDO" }
61 ]
62 },
63 "migrations": [
64 { "tag": "v1", "new_sqlite_classes": ["RepoDO", "RunnerContainer", "SandboxContainer"] },
65 { "tag": "v2", "new_sqlite_classes": ["ImportContainer"] },
66 // Agent tasks, one Durable Object per repository (agentic/ProjectDO.ts).
67 { "tag": "v3", "new_sqlite_classes": ["ProjectDO"] },
68 // Workflow schedules (scheduler.ts).
69 { "tag": "v4", "new_sqlite_classes": ["SchedulerDO"] }
70 ],
71 "workflows": [
72 { "name": "diffinery-run", "binding": "RUN_WORKFLOW", "class_name": "RunWorkflow" },
73 { "name": "diffinery-import", "binding": "IMPORT_WORKFLOW", "class_name": "ImportWorkflow" }
74 ],
75 // A deploy that changes the image rolls the running containers: once a container has been up
76 // longer than rollout_active_grace_period seconds, it gets SIGTERM and is killed 15 minutes later.
77 // Runner and import containers are covered for their whole life (a job is capped at 6 hours, an
78 // import transfer too), so a deploy never cuts one short; they pick up the new image next start.
79 // The rollout is one step (rollout_step_percentage 100): with the default [10, 100], the first
80 // step still starts 90% of new containers on the old image, and the next step replaced such a
81 // job's container seconds after it started. The rollout's SIGTERM reaches every process in the
82 // container, so the job's steps died with it.
83 "containers": [
84 { "class_name": "RunnerContainer", "image": "../../containers/runner/Dockerfile", "image_build_context": "../../containers/runner", "instance_type": "standard-2", "max_instances": 100, "rollout_active_grace_period": 23400, "rollout_step_percentage": 100 },
85 { "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 },
86 // GitHub imports: a mirror clone of a large repository needs disk and memory.
87 { "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 }
88 ],
89 // Housekeeping, and a check that the workflow scheduler's alarm is set (src/scheduler.ts).
90 "triggers": { "crons": ["*/5 * * * *"] },
91
92 "env": {
93 // Local development and end-to-end tests: no Access, a fixed dev identity, no containers.
94 "dev": {
95 "routes": [],
96 "workers_dev": true,
97 "vars": {
98 "PUBLIC_URL": "http://localhost:8787",
99 "MAIL_FROM": "notifications@diffinery.com",
100 "BOOTSTRAP_ADMINS": "dev@diffinery.local",
101 "ACCESS_TEAM_DOMAIN": "",
102 "ACCESS_AUD": "",
103 "DEV_AUTH": "dev@diffinery.local",
104 // Containers do not run under wrangler dev: an import agent started by hand (or by the e2e test) claims Git transfers.
105 "IMPORT_GIT_AGENT": "external"
106 },
107 "d1_databases": [{ "binding": "DB", "database_name": "diffinery-dev", "database_id": "00000000-0000-0000-0000-000000000000", "migrations_dir": "migrations" }],
108 "r2_buckets": [{ "binding": "BUCKET", "bucket_name": "diffinery-data-dev" }],
109 "queues": {
110 "producers": [
111 { "binding": "EVENTS", "queue": "diffinery-events-dev" },
112 { "binding": "MAIL", "queue": "diffinery-mail-dev" }
113 ],
114 "consumers": [
115 { "queue": "diffinery-events-dev", "max_batch_size": 50, "max_batch_timeout": 1 },
116 { "queue": "diffinery-mail-dev", "max_batch_size": 20, "max_batch_timeout": 1 },
117 { "queue": "diffinery-mail-events-dev", "max_batch_size": 50, "max_batch_timeout": 1 }
118 ]
119 },
120 // Local email: Miniflare captures sent messages instead of delivering them.
121 "send_email": [{ "name": "EMAIL" }],
122 "durable_objects": {
123 "bindings": [
124 { "name": "REPO", "class_name": "RepoDO" },
125 { "name": "SCHEDULER", "class_name": "SchedulerDO" },
126 { "name": "RUNNER", "class_name": "RunnerContainer" },
127 // Sandboxes run in an `agent.mjs --sandbox-pool` process (SANDBOX_POOL_URL), not containers.
128 { "name": "SANDBOX", "class_name": "SandboxPoolDO" },
129 { "name": "IMPORTER", "class_name": "ImportContainer" },
130 { "name": "PROJECT", "class_name": "ProjectDO" }
131 ]
132 },
133 "workflows": [
134 { "name": "diffinery-run-dev", "binding": "RUN_WORKFLOW", "class_name": "RunWorkflow" },
135 { "name": "diffinery-import-dev", "binding": "IMPORT_WORKFLOW", "class_name": "ImportWorkflow" }
136 ],
137 "triggers": { "crons": [] },
138 "containers": []
139 }
140 }
141}