refactor: consolidate container image tag source of truth to cli package.json (#1156)
This commit is contained in:
parent
c7a422ccdd
commit
cc89830b2a
|
@ -85,18 +85,13 @@ export async function loadSandboxConfig(
|
||||||
argv: SandboxCliArgs,
|
argv: SandboxCliArgs,
|
||||||
): Promise<SandboxConfig | undefined> {
|
): Promise<SandboxConfig | undefined> {
|
||||||
const sandboxOption = argv.sandbox ?? settings.sandbox;
|
const sandboxOption = argv.sandbox ?? settings.sandbox;
|
||||||
const sandboxCommand = getSandboxCommand(sandboxOption);
|
const command = getSandboxCommand(sandboxOption);
|
||||||
if (!sandboxCommand) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
const packageJson = await getPackageJson();
|
const packageJson = await getPackageJson();
|
||||||
return {
|
const image =
|
||||||
command: sandboxCommand,
|
argv['sandbox-image'] ??
|
||||||
image:
|
process.env.GEMINI_SANDBOX_IMAGE ??
|
||||||
argv['sandbox-image'] ??
|
packageJson?.config?.sandboxImageUri;
|
||||||
process.env.GEMINI_SANDBOX_IMAGE ??
|
|
||||||
packageJson?.config?.sandboxImageUri ??
|
return command && image ? { command, image } : undefined;
|
||||||
'gemini-cli-sandbox',
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ import { chmodSync, readFileSync, rmSync } from 'fs';
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
import yargs from 'yargs';
|
import yargs from 'yargs';
|
||||||
import { hideBin } from 'yargs/helpers';
|
import { hideBin } from 'yargs/helpers';
|
||||||
|
import cliPkgJson from '../packages/cli/package.json' with { type: 'json' };
|
||||||
|
|
||||||
const argv = yargs(hideBin(process.argv))
|
const argv = yargs(hideBin(process.argv))
|
||||||
.option('s', {
|
.option('s', {
|
||||||
|
@ -47,9 +48,7 @@ try {
|
||||||
.toString()
|
.toString()
|
||||||
.trim();
|
.trim();
|
||||||
} catch {
|
} catch {
|
||||||
console.warn(
|
console.warn('ERROR: could not detect sandbox container command');
|
||||||
'WARNING: container-based sandboxing is disabled (see README.md#sandboxing)',
|
|
||||||
);
|
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,11 +61,17 @@ if (sandboxCommand === 'sandbox-exec') {
|
||||||
|
|
||||||
console.log(`using ${sandboxCommand} for sandboxing`);
|
console.log(`using ${sandboxCommand} for sandboxing`);
|
||||||
|
|
||||||
const baseImage = 'gemini-cli-sandbox';
|
const baseImage = cliPkgJson.config.sandboxImageUri;
|
||||||
const customImage = argv.i;
|
const customImage = argv.i;
|
||||||
const baseDockerfile = 'Dockerfile';
|
const baseDockerfile = 'Dockerfile';
|
||||||
const customDockerfile = argv.f;
|
const customDockerfile = argv.f;
|
||||||
|
|
||||||
|
if (!baseImage?.length) {
|
||||||
|
console.warn(
|
||||||
|
'No default image tag specified in gemini-cli/packages/cli/package.json',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (!argv.s) {
|
if (!argv.s) {
|
||||||
execSync('npm install', { stdio: 'inherit' });
|
execSync('npm install', { stdio: 'inherit' });
|
||||||
execSync('npm run build --workspaces', { stdio: 'inherit' });
|
execSync('npm run build --workspaces', { stdio: 'inherit' });
|
||||||
|
@ -122,7 +127,9 @@ function buildImage(imageName, dockerfile) {
|
||||||
console.log(`built ${imageName}`);
|
console.log(`built ${imageName}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
buildImage(baseImage, baseDockerfile);
|
if (baseImage && baseDockerfile) {
|
||||||
|
buildImage(baseImage, baseDockerfile);
|
||||||
|
}
|
||||||
|
|
||||||
if (customDockerfile && customImage) {
|
if (customDockerfile && customImage) {
|
||||||
buildImage(customImage, customDockerfile);
|
buildImage(customImage, customDockerfile);
|
||||||
|
|
Loading…
Reference in New Issue