Skip to content

Commit 60c8b00

Browse files
authored
Add reviewed production Wrangler configs (#15)
1 parent 19d4571 commit 60c8b00

5 files changed

Lines changed: 340 additions & 0 deletions

File tree

‎.github/workflows/v6-foundation-check.yml‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@ on:
1414
- 'package.json'
1515
- 'package-lock.json'
1616
- 'scripts/orbit-d1-*.ts'
17+
- 'scripts/orbit-production-config-tests.mjs'
1718
- 'scripts/orbit-slice1-*.ts'
1819
- 'src/server/**'
1920
- 'src/worker.ts'
2021
- 'wrangler.jsonc'
22+
- 'wrangler.production.dark-launch.jsonc'
23+
- 'wrangler.production.live.jsonc'
2124
- 'wrangler.staging.jsonc'
2225
- 'wrangler.test.jsonc'
2326
- 'wrangler.slice1-test.jsonc'
@@ -49,3 +52,12 @@ jobs:
4952

5053
- name: Verify isolated staging bundle
5154
run: npm run worker:build:staging
55+
56+
- name: Verify production config parity
57+
run: npm run production:config:check
58+
59+
- name: Verify production live bundle without deployment
60+
run: npm run worker:build:production:live
61+
62+
- name: Verify production dark-launch rollback bundle without deployment
63+
run: npm run worker:build:production:dark-launch

‎package.json‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
"build": "npm run test:d1 && npm run orbit:test && npm run orbit:validate && npm run og:generate && astro build && npm run site:test && npm run browser:test",
99
"worker:build": "astro build --config astro.worker.config.mjs && wrangler deploy --dry-run --config wrangler.jsonc --outdir dist/worker",
1010
"worker:build:staging": "ORBIT_SITE_URL=https://orbit-v6-staging.samett33710.workers.dev ORBIT_NOINDEX=true astro build --config astro.worker.config.mjs && node scripts/orbit-staging-assets.mjs && wrangler deploy --dry-run --config wrangler.staging.jsonc --outdir dist/worker-staging",
11+
"worker:build:production:live": "ORBIT_SITE_URL=https://orbit.sametbasbug.dev ORBIT_NOINDEX=false astro build --config astro.worker.config.mjs && wrangler deploy --dry-run --config wrangler.production.live.jsonc --outdir dist/worker-production-live",
12+
"worker:build:production:dark-launch": "ORBIT_SITE_URL=https://orbit-v6-production.samett33710.workers.dev ORBIT_NOINDEX=true astro build --config astro.worker.config.mjs && node scripts/orbit-staging-assets.mjs && wrangler deploy --dry-run --config wrangler.production.dark-launch.jsonc --outdir dist/worker-production-dark-launch",
1113
"worker:dev": "node scripts/orbit-local-dev.mjs",
1214
"d1:migrate:local": "wrangler d1 migrations apply orbit-v6-local --local",
1315
"d1:migrate:staging": "wrangler d1 migrations apply DB --remote --config wrangler.staging.jsonc",
@@ -28,6 +30,7 @@
2830
"preview": "astro preview",
2931
"check": "npm run orbit:validate && astro check",
3032
"orbit:validate": "node scripts/orbit-validate.mjs",
33+
"production:config:check": "node scripts/orbit-production-config-tests.mjs",
3134
"orbit:index": "node scripts/orbit-index.mjs",
3235
"orbit:test": "node scripts/orbit-content-tests.mjs && node scripts/orbit-cli-tests.mjs",
3336
"site:test": "node scripts/orbit-site-tests.mjs",
Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
import { readFile } from 'node:fs/promises';
2+
import { isDeepStrictEqual } from 'node:util';
3+
4+
const files = {
5+
live: new URL('../wrangler.production.live.jsonc', import.meta.url),
6+
darkLaunch: new URL('../wrangler.production.dark-launch.jsonc', import.meta.url),
7+
};
8+
9+
let assertions = 0;
10+
11+
function fail(message) {
12+
throw new Error(`Orbit production config validation failed: ${message}`);
13+
}
14+
15+
function assert(condition, message) {
16+
assertions += 1;
17+
if (!condition) fail(message);
18+
}
19+
20+
function assertDeepEqual(actual, expected, message) {
21+
assert(isDeepStrictEqual(actual, expected), message);
22+
}
23+
24+
async function readConfig(url, label) {
25+
try {
26+
return JSON.parse(await readFile(url, 'utf8'));
27+
} catch (error) {
28+
fail(`${label} is not strict JSON: ${error.message}`);
29+
}
30+
}
31+
32+
function findForbiddenKeys(value, path = '$') {
33+
const found = [];
34+
35+
if (Array.isArray(value)) {
36+
value.forEach((entry, index) => {
37+
found.push(...findForbiddenKeys(entry, `${path}[${index}]`));
38+
});
39+
return found;
40+
}
41+
42+
if (!value || typeof value !== 'object') return found;
43+
44+
for (const [key, entry] of Object.entries(value)) {
45+
const nextPath = `${path}.${key}`;
46+
if (
47+
['route', 'routes', 'custom_domain', 'secrets'].includes(key) ||
48+
/(secret|token|password|private_key|encryption_key|pepper|credential)/i.test(key)
49+
) {
50+
found.push(nextPath);
51+
}
52+
found.push(...findForbiddenKeys(entry, nextPath));
53+
}
54+
55+
return found;
56+
}
57+
58+
const expectedTopLevelKeys = [
59+
'$schema',
60+
'assets',
61+
'compatibility_date',
62+
'd1_databases',
63+
'images',
64+
'kv_namespaces',
65+
'main',
66+
'name',
67+
'observability',
68+
'preview_urls',
69+
'r2_buckets',
70+
'triggers',
71+
'vars',
72+
'workers_dev',
73+
];
74+
75+
const expectedCommonVars = {
76+
ORBIT_ENVIRONMENT: 'production',
77+
ORBIT_PLATFORM_OWNER_GITHUB_ID: '126420524',
78+
ORBIT_BACKUP_ENABLED: 'true',
79+
ORBIT_MEDIA_ENABLED: 'false',
80+
};
81+
82+
const expectedResources = {
83+
assets: {
84+
binding: 'ASSETS',
85+
directory: './dist/client',
86+
run_worker_first: true,
87+
},
88+
d1_databases: [
89+
{
90+
binding: 'DB',
91+
database_name: 'orbit-v6-production',
92+
database_id: '199fe088-2f56-48c4-bc81-50b8c5e4b471',
93+
migrations_dir: 'migrations',
94+
},
95+
],
96+
kv_namespaces: [
97+
{
98+
binding: 'CACHE',
99+
id: '5c1574a9562448cf863aa84fad10877f',
100+
},
101+
],
102+
r2_buckets: [
103+
{
104+
binding: 'BACKUPS',
105+
bucket_name: 'orbit-v6-production-backups',
106+
},
107+
{
108+
binding: 'MEDIA',
109+
bucket_name: 'orbit-v6-production-media',
110+
},
111+
],
112+
images: {
113+
binding: 'IMAGES',
114+
},
115+
observability: {
116+
enabled: true,
117+
logs: {
118+
enabled: true,
119+
head_sampling_rate: 1,
120+
invocation_logs: true,
121+
persist: true,
122+
},
123+
},
124+
triggers: {
125+
crons: ['17 3 * * *'],
126+
},
127+
};
128+
129+
function validateConfig(config, expected) {
130+
assertDeepEqual(
131+
Object.keys(config).sort(),
132+
expectedTopLevelKeys,
133+
`${expected.label} has an unexpected top-level key`,
134+
);
135+
assert(
136+
findForbiddenKeys(config).length === 0,
137+
`${expected.label} contains a route, custom-domain, secret, or credential field`,
138+
);
139+
assert(config.name === 'orbit-v6-production', `${expected.label} Worker name drifted`);
140+
assert(config.main === 'src/worker.ts', `${expected.label} Worker entrypoint drifted`);
141+
assert(
142+
config.compatibility_date === '2026-07-15',
143+
`${expected.label} compatibility date drifted`,
144+
);
145+
assert(config.workers_dev === expected.workersDev, `${expected.label} workers_dev drifted`);
146+
assert(config.preview_urls === false, `${expected.label} preview_urls must be false`);
147+
148+
for (const [key, value] of Object.entries(expectedResources)) {
149+
assertDeepEqual(config[key], value, `${expected.label} ${key} resource drifted`);
150+
}
151+
152+
assertDeepEqual(
153+
config.vars,
154+
{
155+
ORBIT_ENVIRONMENT: 'production',
156+
ORBIT_DEPLOYMENT_MODE: expected.mode,
157+
ORBIT_ALLOWED_ORIGIN: expected.origin,
158+
ORBIT_GITHUB_CALLBACK_URL: `${expected.origin}/v1/auth/github/callback`,
159+
ORBIT_PLATFORM_OWNER_GITHUB_ID: '126420524',
160+
ORBIT_BACKUP_ENABLED: 'true',
161+
ORBIT_MEDIA_ENABLED: 'false',
162+
},
163+
`${expected.label} vars drifted`,
164+
);
165+
166+
for (const [key, value] of Object.entries(expectedCommonVars)) {
167+
assert(config.vars[key] === value, `${expected.label} ${key} drifted`);
168+
}
169+
}
170+
171+
function normalizeModeDifferences(config) {
172+
const normalized = structuredClone(config);
173+
delete normalized.workers_dev;
174+
delete normalized.vars.ORBIT_DEPLOYMENT_MODE;
175+
delete normalized.vars.ORBIT_ALLOWED_ORIGIN;
176+
delete normalized.vars.ORBIT_GITHUB_CALLBACK_URL;
177+
return normalized;
178+
}
179+
180+
const live = await readConfig(files.live, 'live config');
181+
const darkLaunch = await readConfig(files.darkLaunch, 'dark-launch config');
182+
183+
validateConfig(live, {
184+
label: 'live config',
185+
workersDev: false,
186+
mode: 'live',
187+
origin: 'https://orbit.sametbasbug.dev',
188+
});
189+
190+
validateConfig(darkLaunch, {
191+
label: 'dark-launch config',
192+
workersDev: true,
193+
mode: 'dark_launch',
194+
origin: 'https://orbit-v6-production.samett33710.workers.dev',
195+
});
196+
197+
assertDeepEqual(
198+
normalizeModeDifferences(live),
199+
normalizeModeDifferences(darkLaunch),
200+
'live and dark-launch configs differ outside the reviewed mode surface',
201+
);
202+
203+
process.stdout.write(`Orbit production config tests: ${assertions} assertions passed\n`);
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{
2+
"$schema": "node_modules/wrangler/config-schema.json",
3+
"name": "orbit-v6-production",
4+
"main": "src/worker.ts",
5+
"compatibility_date": "2026-07-15",
6+
"workers_dev": true,
7+
"preview_urls": false,
8+
"assets": {
9+
"binding": "ASSETS",
10+
"directory": "./dist/client",
11+
"run_worker_first": true
12+
},
13+
"vars": {
14+
"ORBIT_ENVIRONMENT": "production",
15+
"ORBIT_DEPLOYMENT_MODE": "dark_launch",
16+
"ORBIT_ALLOWED_ORIGIN": "https://orbit-v6-production.samett33710.workers.dev",
17+
"ORBIT_GITHUB_CALLBACK_URL": "https://orbit-v6-production.samett33710.workers.dev/v1/auth/github/callback",
18+
"ORBIT_PLATFORM_OWNER_GITHUB_ID": "126420524",
19+
"ORBIT_BACKUP_ENABLED": "true",
20+
"ORBIT_MEDIA_ENABLED": "false"
21+
},
22+
"d1_databases": [
23+
{
24+
"binding": "DB",
25+
"database_name": "orbit-v6-production",
26+
"database_id": "199fe088-2f56-48c4-bc81-50b8c5e4b471",
27+
"migrations_dir": "migrations"
28+
}
29+
],
30+
"kv_namespaces": [
31+
{
32+
"binding": "CACHE",
33+
"id": "5c1574a9562448cf863aa84fad10877f"
34+
}
35+
],
36+
"r2_buckets": [
37+
{
38+
"binding": "BACKUPS",
39+
"bucket_name": "orbit-v6-production-backups"
40+
},
41+
{
42+
"binding": "MEDIA",
43+
"bucket_name": "orbit-v6-production-media"
44+
}
45+
],
46+
"images": {
47+
"binding": "IMAGES"
48+
},
49+
"observability": {
50+
"enabled": true,
51+
"logs": {
52+
"enabled": true,
53+
"head_sampling_rate": 1,
54+
"invocation_logs": true,
55+
"persist": true
56+
}
57+
},
58+
"triggers": {
59+
"crons": ["17 3 * * *"]
60+
}
61+
}

‎wrangler.production.live.jsonc‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{
2+
"$schema": "node_modules/wrangler/config-schema.json",
3+
"name": "orbit-v6-production",
4+
"main": "src/worker.ts",
5+
"compatibility_date": "2026-07-15",
6+
"workers_dev": false,
7+
"preview_urls": false,
8+
"assets": {
9+
"binding": "ASSETS",
10+
"directory": "./dist/client",
11+
"run_worker_first": true
12+
},
13+
"vars": {
14+
"ORBIT_ENVIRONMENT": "production",
15+
"ORBIT_DEPLOYMENT_MODE": "live",
16+
"ORBIT_ALLOWED_ORIGIN": "https://orbit.sametbasbug.dev",
17+
"ORBIT_GITHUB_CALLBACK_URL": "https://orbit.sametbasbug.dev/v1/auth/github/callback",
18+
"ORBIT_PLATFORM_OWNER_GITHUB_ID": "126420524",
19+
"ORBIT_BACKUP_ENABLED": "true",
20+
"ORBIT_MEDIA_ENABLED": "false"
21+
},
22+
"d1_databases": [
23+
{
24+
"binding": "DB",
25+
"database_name": "orbit-v6-production",
26+
"database_id": "199fe088-2f56-48c4-bc81-50b8c5e4b471",
27+
"migrations_dir": "migrations"
28+
}
29+
],
30+
"kv_namespaces": [
31+
{
32+
"binding": "CACHE",
33+
"id": "5c1574a9562448cf863aa84fad10877f"
34+
}
35+
],
36+
"r2_buckets": [
37+
{
38+
"binding": "BACKUPS",
39+
"bucket_name": "orbit-v6-production-backups"
40+
},
41+
{
42+
"binding": "MEDIA",
43+
"bucket_name": "orbit-v6-production-media"
44+
}
45+
],
46+
"images": {
47+
"binding": "IMAGES"
48+
},
49+
"observability": {
50+
"enabled": true,
51+
"logs": {
52+
"enabled": true,
53+
"head_sampling_rate": 1,
54+
"invocation_logs": true,
55+
"persist": true
56+
}
57+
},
58+
"triggers": {
59+
"crons": ["17 3 * * *"]
60+
}
61+
}

0 commit comments

Comments
 (0)