use exec instead of spawn for command -v to go through shell and let it interpret command as a shell built-in instead of looking for a command binary on system (note setting shell:true for spawn could also work) (#211)
This commit is contained in:
parent
825cecc089
commit
28518aee0a
|
@ -28,9 +28,9 @@ function sandbox_command(): string {
|
||||||
const opts: object = { stdio: 'ignore' };
|
const opts: object = { stdio: 'ignore' };
|
||||||
if (['1', 'true'].includes(sandbox)) {
|
if (['1', 'true'].includes(sandbox)) {
|
||||||
// look for docker or podman, in that order
|
// look for docker or podman, in that order
|
||||||
if (spawnSync('command', ['-v', 'docker'], opts).status === 0) {
|
if (execSync('command -v docker').toString().trim()) {
|
||||||
return 'docker'; // Set sandbox to 'docker' if found
|
return 'docker'; // Set sandbox to 'docker' if found
|
||||||
} else if (spawnSync('command', ['-v', 'podman'], opts).status === 0) {
|
} else if (execSync('command -v podman').toString().trim()) {
|
||||||
return 'podman'; // Set sandbox to 'podman' if found
|
return 'podman'; // Set sandbox to 'podman' if found
|
||||||
} else {
|
} else {
|
||||||
console.error(
|
console.error(
|
||||||
|
@ -41,13 +41,14 @@ function sandbox_command(): string {
|
||||||
}
|
}
|
||||||
} else if (sandbox) {
|
} else if (sandbox) {
|
||||||
// confirm that specfied command exists
|
// confirm that specfied command exists
|
||||||
if (spawnSync('command', ['-v', sandbox], opts).status !== 0) {
|
if (execSync(`command -v ${sandbox}`).toString().trim()) {
|
||||||
|
return sandbox;
|
||||||
|
} else {
|
||||||
console.error(
|
console.error(
|
||||||
`ERROR: missing sandbox command '${sandbox}' (from GEMINI_CODE_SANDBOX)`,
|
`ERROR: missing sandbox command '${sandbox}' (from GEMINI_CODE_SANDBOX)`,
|
||||||
);
|
);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
return sandbox;
|
|
||||||
} else {
|
} else {
|
||||||
return ''; // no sandbox
|
return ''; // no sandbox
|
||||||
}
|
}
|
||||||
|
@ -191,10 +192,12 @@ async function start_sandbox(sandbox: string) {
|
||||||
// set SANDBOX as container name
|
// set SANDBOX as container name
|
||||||
args.push('--env', `SANDBOX=${image}-${index}`);
|
args.push('--env', `SANDBOX=${image}-${index}`);
|
||||||
|
|
||||||
// for podman, use empty --authfile to skip unnecessary auth refresh overhead
|
// for podman only, use empty --authfile to skip unnecessary auth refresh overhead
|
||||||
const emptyAuthFilePath = path.join(os.tmpdir(), 'empty_auth.json');
|
if (sandbox === 'podman') {
|
||||||
fs.writeFileSync(emptyAuthFilePath, '{}', 'utf-8');
|
const emptyAuthFilePath = path.join(os.tmpdir(), 'empty_auth.json');
|
||||||
args.push('--authfile', emptyAuthFilePath);
|
fs.writeFileSync(emptyAuthFilePath, '{}', 'utf-8');
|
||||||
|
args.push('--authfile', emptyAuthFilePath);
|
||||||
|
}
|
||||||
|
|
||||||
// enable debugging via node --inspect-brk if DEBUG is set
|
// enable debugging via node --inspect-brk if DEBUG is set
|
||||||
const nodeArgs = [];
|
const nodeArgs = [];
|
||||||
|
|
Loading…
Reference in New Issue