Sandbox Jobs never received WF_DEPLOYMENT_MODE, which every worker requires before anything else, so each Kubernetes sandbox exited at start. The provisioner now passes its own mode. A local development cluster (k3s) has no Kata, no bubblewrap inside runc and no TLS between services. For it, and only with WF_DEPLOYMENT_MODE=development: - WF_ALLOW_INSECURE_HTTP=true lets services reach each other over plain HTTP (Git, the model proxy, the provisioner and IDE gateway targets, the worker's control-plane client); production refuses the setting outright. - The provisioner accepts WF_RUN_SANDBOX_MODE=host and WF_KATA_RUNTIME_CLASS=none and passes the HTTP settings to its sandboxes. - The development seed is built into the image (dist/api/seed.mjs). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
62 lines
3.0 KiB
JavaScript
62 lines
3.0 KiB
JavaScript
// Compiles each Node service to a single ESM file under dist/, so images run built code
|
|
// instead of transpiling TypeScript at start-up. The workspace packages are compiled into
|
|
// every service; everything else is loaded from node_modules at run time. esbuild applies the
|
|
// same transform tsx did in development, so the built services behave the same.
|
|
import { cp, mkdir, rm, writeFile } from 'node:fs/promises';
|
|
import path from 'node:path';
|
|
import { parseArgs } from 'node:util';
|
|
import { build } from 'esbuild';
|
|
|
|
const { values } = parseArgs({
|
|
options: { outdir: { type: 'string', default: 'dist' }, 'skip-workflows': { type: 'boolean', default: false } },
|
|
});
|
|
const outdir = path.resolve(values.outdir);
|
|
export const services = [
|
|
{ entry: 'apps/api/src/main.ts', out: 'api/main.mjs', tsconfig: 'apps/api/tsconfig.json' },
|
|
{ entry: 'apps/api/src/db/migrate.ts', out: 'api/migrate.mjs', tsconfig: 'apps/api/tsconfig.json' },
|
|
// Development clusters seed their local tenant from the image too (infra/k8s/local).
|
|
{ entry: 'apps/api/src/db/seed.ts', out: 'api/seed.mjs', tsconfig: 'apps/api/tsconfig.json' },
|
|
{ entry: 'apps/worker/src/main.ts', out: 'worker/main.mjs', tsconfig: 'apps/worker/tsconfig.json' },
|
|
{ entry: 'apps/runner/src/main.ts', out: 'runner/main.mjs', tsconfig: 'apps/runner/tsconfig.json' },
|
|
{ entry: 'apps/git-service/src/main.ts', out: 'git-service/main.mjs', tsconfig: 'apps/git-service/tsconfig.json' },
|
|
];
|
|
const externalPackages = {
|
|
name: 'external-packages',
|
|
setup(builder) {
|
|
builder.onResolve({ filter: /^[^./]/ }, args =>
|
|
args.path.startsWith('@wishforge/') || path.isAbsolute(args.path)
|
|
? undefined
|
|
: { path: args.path, external: true },
|
|
);
|
|
},
|
|
};
|
|
|
|
await rm(outdir, { recursive: true, force: true });
|
|
for (const service of services)
|
|
await build({
|
|
entryPoints: [service.entry],
|
|
outfile: path.join(outdir, service.out),
|
|
tsconfig: service.tsconfig,
|
|
bundle: true,
|
|
platform: 'node',
|
|
format: 'esm',
|
|
target: 'node22',
|
|
sourcemap: true,
|
|
plugins: [externalPackages],
|
|
// Bundled CommonJS interop expects `require`; ESM output provides it explicitly.
|
|
banner: {
|
|
js: "import { createRequire as __wfRequire } from 'node:module'; const require = __wfRequire(import.meta.url);",
|
|
},
|
|
logLevel: 'warning',
|
|
});
|
|
// The migration runner reads its SQL files next to itself.
|
|
await cp('apps/api/src/db/migrations', path.join(outdir, 'api/migrations'), { recursive: true });
|
|
if (!values['skip-workflows']) {
|
|
// Temporal runs workflows from their own bundle; building it here keeps webpack out of start-up.
|
|
const { bundleWorkflowCode } = await import('@temporalio/worker');
|
|
const { code } = await bundleWorkflowCode({ workflowsPath: path.resolve('apps/worker/src/workflows.ts') });
|
|
await mkdir(path.join(outdir, 'worker'), { recursive: true });
|
|
await writeFile(path.join(outdir, 'worker/workflow-bundle.js'), code);
|
|
}
|
|
console.log(`Built ${services.length} service entry points into ${path.relative(process.cwd(), outdir) || '.'}`);
|