Detect actual service and Runner readiness, restore LAN access after network changes, protect production web builds with rollback, honor cancellation during executor startup, and show truthful cached-data and credential states.
57 lines
2.0 KiB
JavaScript
57 lines
2.0 KiB
JavaScript
import { spawn } from 'node:child_process';
|
|
import { resolve } from 'node:path';
|
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
import { environment, loadLocalEnvironment } from './local-services.mjs';
|
|
import { buildWithRollback } from './local-web-build.mjs';
|
|
|
|
export async function main() {
|
|
const root = fileURLToPath(new URL('..', import.meta.url));
|
|
process.chdir(root);
|
|
loadLocalEnvironment();
|
|
// Load env in this parent, not Node's --env-file argv: Next forwards execArgv to
|
|
// worker NODE_OPTIONS, where Node rejects --env-file. No database credentials go to Web.
|
|
const build = () =>
|
|
new Promise((resolveBuild, reject) => {
|
|
const child = spawn(process.execPath, [resolve('node_modules/next/dist/bin/next'), 'build'], {
|
|
cwd: resolve('apps/web'),
|
|
env: environment(
|
|
[
|
|
/^WF_LOCAL_ACCESS/,
|
|
/^WF_LOCAL_ALLOWED_ORIGINS$/,
|
|
/^WF_DEV_AUTH_TOKEN$/,
|
|
/^WF_SESSION_SECRET$/,
|
|
/^WF_PUBLIC_URL$/,
|
|
/^WF_API_URL$/,
|
|
/^WF_WEB_/,
|
|
/^WF_IDE_/,
|
|
/^OIDC_/,
|
|
],
|
|
{ NODE_ENV: 'production', NEXT_TELEMETRY_DISABLED: '1' },
|
|
),
|
|
stdio: 'inherit',
|
|
});
|
|
const stop = () => child.kill('SIGTERM');
|
|
process.once('SIGINT', stop);
|
|
process.once('SIGTERM', stop);
|
|
child.on('error', reject);
|
|
child.on('close', code => {
|
|
process.removeListener('SIGINT', stop);
|
|
process.removeListener('SIGTERM', stop);
|
|
code === 0
|
|
? resolveBuild()
|
|
: reject(new Error(`Web build failed (${code ?? 'signal'}); the previous build was restored when available`));
|
|
});
|
|
});
|
|
const receipt = await buildWithRollback(root, build, {
|
|
port: Number(process.env.WF_WEB_PORT || 3000),
|
|
host: process.env.WF_WEB_HOST || '0.0.0.0',
|
|
});
|
|
console.log(JSON.stringify(receipt, null, 2));
|
|
}
|
|
|
|
if (process.argv[1] && pathToFileURL(resolve(process.argv[1])).href === import.meta.url)
|
|
main().catch(error => {
|
|
console.error(error.message);
|
|
process.exitCode = 1;
|
|
});
|