The cluster never ran Theia or the IDE gateway, so every workspace stayed "未配置" forever. The feature is gone instead of half-present: - API: workspace, launch and lifecycle endpoints, the gateway identity and its internal routes, the dispatcher's workspace provisioning and the lifecycle worker. Migration 003 deletes stored workspaces and settles their pending outbox items. - Provisioner: workspace provisioning and lifecycle for both backends. - Web: the 云 IDE panel, the launch route, the start-branch picker that listed IDE branches, and the workspace count on usage. - apps/ide, infra/oct, dev:ide and the CI job; IDE parts of local k3s, network policies, RBAC, docs and the architecture diagram. A wish can still start from a pushed branch through the API (sourceBranch). Plan files and stored entitlements may still carry maxWorkspaces; it is accepted and ignored. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
102 lines
3.7 KiB
JavaScript
102 lines
3.7 KiB
JavaScript
import http from 'node:http';
|
|
import { timingSafeEqual } from 'node:crypto';
|
|
import { readConfig, provisionRun } from './kubernetes.mjs';
|
|
import { purgeRunStorage, releaseRun } from './run-release.mjs';
|
|
import { createRunOperationQueue } from './run-operations.mjs';
|
|
import { createLocalBackend, readLocalConfig } from './local.mjs';
|
|
|
|
/** `local` runs workers as host processes for development; `kubernetes` creates Kata Jobs. */
|
|
function backendFor(name) {
|
|
if (name === 'local') return createLocalBackend(readLocalConfig());
|
|
if (name === 'kubernetes') {
|
|
const config = readConfig();
|
|
return {
|
|
tenantId: config.tenantId,
|
|
provisionRun: input => provisionRun(config, input),
|
|
releaseRun: input => releaseRun(config, input),
|
|
purgeRun: input => purgeRunStorage(config, input),
|
|
async close() {},
|
|
};
|
|
}
|
|
throw new Error('WF_PROVISIONER_BACKEND must be local or kubernetes');
|
|
}
|
|
|
|
// Like every service, the provisioner refuses to guess whether it runs in production.
|
|
if (!['production', 'development'].includes(process.env.WF_DEPLOYMENT_MODE))
|
|
throw new Error('Set WF_DEPLOYMENT_MODE to "production" or "development"');
|
|
const backend = backendFor(process.env.WF_PROVISIONER_BACKEND);
|
|
const expected = process.env.WF_PROVISIONER_TOKEN;
|
|
const runOperation = createRunOperationQueue();
|
|
if (!expected || expected.length < 32)
|
|
throw new Error('unconfigured: scoped WF_PROVISIONER_TOKEN must be at least 32 characters');
|
|
|
|
async function body(req, limit) {
|
|
let text = '';
|
|
for await (const part of req) {
|
|
text += part;
|
|
if (text.length > limit) throw new Error('INVALID_REQUEST');
|
|
}
|
|
return JSON.parse(text);
|
|
}
|
|
|
|
const server = http.createServer(async (req, res) => {
|
|
res.setHeader('content-type', 'application/json');
|
|
res.setHeader('cache-control', 'no-store');
|
|
try {
|
|
if (req.url === '/healthz' && req.method === 'GET') {
|
|
res.end(
|
|
JSON.stringify({ status: 'ok', service: 'wishforge-provisioner', backend: process.env.WF_PROVISIONER_BACKEND }),
|
|
);
|
|
return;
|
|
}
|
|
const token = req.headers.authorization?.replace(/^Bearer /, '') ?? '';
|
|
if (token.length !== expected.length || !timingSafeEqual(Buffer.from(token), Buffer.from(expected))) {
|
|
res.writeHead(401);
|
|
res.end(JSON.stringify({ error: 'UNAUTHORIZED' }));
|
|
return;
|
|
}
|
|
if (!['/runs', '/runs/release', '/runs/purge'].includes(req.url) || req.method !== 'POST') {
|
|
res.writeHead(404);
|
|
res.end(JSON.stringify({ error: 'NOT_FOUND' }));
|
|
return;
|
|
}
|
|
const input = await body(req, 40000);
|
|
const result = await runOperation(input.tenantId, input.runId, () =>
|
|
req.url === '/runs/release'
|
|
? backend.releaseRun(input)
|
|
: req.url === '/runs/purge'
|
|
? backend.purgeRun(input)
|
|
: backend.provisionRun(input),
|
|
);
|
|
res.writeHead(202);
|
|
res.end(JSON.stringify(result));
|
|
} catch (error) {
|
|
const infrastructure = error.message.startsWith('KUBERNETES_');
|
|
res.writeHead(infrastructure ? 502 : 400);
|
|
res.end(
|
|
JSON.stringify({
|
|
error:
|
|
infrastructure ||
|
|
[
|
|
'RESOURCE_GRANT_INVALID',
|
|
'RESOURCE_GRANT_EXPIRED',
|
|
'RESOURCE_LIMIT',
|
|
'RUNTIME_IMAGE_MIGRATION_REQUIRED',
|
|
].includes(error.message)
|
|
? error.message
|
|
: 'INVALID_RUN_REQUEST',
|
|
}),
|
|
);
|
|
}
|
|
});
|
|
server.listen(Number(process.env.WF_PROVISIONER_PORT ?? 4450), process.env.WF_PROVISIONER_HOST ?? '127.0.0.1', () =>
|
|
console.log(
|
|
`Provisioner (${process.env.WF_PROVISIONER_BACKEND}) ready; nothing runs until an authenticated request arrives.`,
|
|
),
|
|
);
|
|
for (const signal of ['SIGINT', 'SIGTERM'])
|
|
process.once(signal, () => {
|
|
server.close();
|
|
void backend.close().finally(() => process.exit(0));
|
|
});
|