39 lines
1.5 KiB
JavaScript
39 lines
1.5 KiB
JavaScript
import { spawn } from 'node:child_process';
|
|
import { deploymentOrgSettings } from './org-context-settings.mjs';
|
|
|
|
const worker = 'baron-qa-gateway-test';
|
|
const dryRun = process.argv.includes('--dry-run');
|
|
function execute(args, input) {
|
|
return new Promise((resolve, reject) => {
|
|
const child = spawn('npx', ['wrangler', ...args], {
|
|
stdio: [input === undefined ? 'ignore' : 'pipe', 'inherit', 'inherit']
|
|
});
|
|
child.once('error', (error) => {
|
|
console.error('Worker command OS error:', error.code);
|
|
reject(new Error('Worker deployment command failed'));
|
|
});
|
|
child.once('exit', (code, signal) => {
|
|
if (code === 0) resolve();
|
|
else {
|
|
console.error('Worker command exit:', signal || code);
|
|
reject(new Error('Worker deployment command failed'));
|
|
}
|
|
});
|
|
if (input !== undefined) {
|
|
child.stdin.once('error', () => reject(new Error('Worker secret input failed')));
|
|
child.stdin.end(input);
|
|
}
|
|
});
|
|
}
|
|
try {
|
|
const { vars, secrets } = deploymentOrgSettings(process.env);
|
|
if (!dryRun && Object.keys(secrets).length) await execute(['secret', 'bulk', '--name', worker], JSON.stringify(secrets));
|
|
const args = ['deploy', '--name', worker];
|
|
if (dryRun) args.push('--dry-run');
|
|
for (const [name, value] of Object.entries(vars)) args.push('--var', name + ':' + value);
|
|
await execute(args);
|
|
} catch {
|
|
console.error('Worker deployment failed. Check configuration and preceding Wrangler diagnostics.');
|
|
process.exitCode = 1;
|
|
}
|