From ce9bdf0b145ab5ec44a6f71822fc4e4142516283 Mon Sep 17 00:00:00 2001 From: Ashish Jha Date: Mon, 2 Nov 2026 12:40:13 +0530 Subject: [PATCH] fix: make build --no-cache and start --rebuild work Commander stores the negatable `--no-cache` option as `cache: false`, but runBuild read `opts.noCache`, which was always undefined, so docker never received --no-cache. `start --rebuild` was declared but never read. Read `cache` (via a shared noCacheArgs helper for the three docker build call sites), and have `start --rebuild` call runBuild with the same framework/browser selection before the image is resolved. Fixes #12 --- src/cli.ts | 2 +- src/commands/build.ts | 14 ++++++++++---- src/commands/quickstart.ts | 1 - src/commands/start.ts | 8 ++++++++ tests/commands/build.test.ts | 13 +++++++++++++ 5 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 tests/commands/build.test.ts diff --git a/src/cli.ts b/src/cli.ts index 605bade..810d84f 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -103,7 +103,7 @@ program .option("-f, --framework ", "Build image with a framework pre-installed (e.g. crewai, langgraph)") .option("--all-frameworks", "Build images for all supported frameworks", false) .option("--browser", "Build a browser-capable framework image", false) - .action(async (opts: { tag?: string; noCache: boolean; framework?: string; allFrameworks: boolean; browser: boolean }) => { + .action(async (opts: { tag?: string; cache: boolean; framework?: string; allFrameworks: boolean; browser: boolean }) => { await runBuild(opts); }); diff --git a/src/commands/build.ts b/src/commands/build.ts index f33d134..3325699 100644 --- a/src/commands/build.ts +++ b/src/commands/build.ts @@ -49,12 +49,18 @@ function resolveSandboxDir(): string { interface BuildOptions { tag?: string; - noCache: boolean; + /** False when `--no-cache` is passed (Commander stores negatable flags this way). */ + cache?: boolean; framework?: string; allFrameworks?: boolean; browser?: boolean; } +/** The `docker build` cache flag for the given `cache` option. */ +export function noCacheArgs(cache: boolean | undefined): string[] { + return cache === false ? ["--no-cache"] : []; +} + export async function runBuild(opts: BuildOptions): Promise { await assertDockerAvailable(); @@ -97,7 +103,7 @@ export async function runBuild(opts: BuildOptions): Promise { "build", "--file", dockerfilePath, "--tag", imageTag, - ...(opts.noCache ? ["--no-cache"] : []), + ...noCacheArgs(opts.cache), sandboxDir, ]; @@ -160,7 +166,7 @@ async function buildFrameworkImage( "build", "--file", dockerfilePath, "--tag", imageTag, - ...(opts.noCache ? ["--no-cache"] : []), + ...noCacheArgs(opts.cache), contextDir, ]; @@ -204,7 +210,7 @@ async function buildAllFrameworks( "build", "--file", dockerfilePath, "--tag", imageTag, - ...(opts.noCache ? ["--no-cache"] : []), + ...noCacheArgs(opts.cache), contextDir, ]); diff --git a/src/commands/quickstart.ts b/src/commands/quickstart.ts index 592c791..7d72c55 100644 --- a/src/commands/quickstart.ts +++ b/src/commands/quickstart.ts @@ -88,7 +88,6 @@ export async function runQuickstart(opts: QuickstartOptions): Promise { const { runBuild } = await import("./build.js"); await runBuild({ - noCache: false, framework: opts.framework, browser: opts.browser, }); diff --git a/src/commands/start.ts b/src/commands/start.ts index 3a4d803..26fa141 100644 --- a/src/commands/start.ts +++ b/src/commands/start.ts @@ -9,6 +9,7 @@ import { startContainer } from "../docker/runner.js"; import { SILO_NETWORK } from "../docker/templates.js"; import { ensureGatewaySidecar, needsGatewaySidecar } from "../docker/gateway.js"; import { log, printBanner } from "../utils/logger.js"; +import { runBuild } from "./build.js"; import { assertDockerAvailable, isContainerRunning, @@ -104,6 +105,13 @@ export async function runStart(opts: StartOptions): Promise { } } + // ── Rebuild image (--rebuild) ─────────────────────────────────────────── + // runBuild tags the image exactly as it is resolved below: the configured + // sandbox image, or the framework image for --framework / --browser. + if (opts.rebuild) { + await runBuild({ framework: framework?.id, browser: opts.browser }); + } + // ── Resolve image ─────────────────────────────────────────────────────── let image = config.sandbox.image; if (framework) { diff --git a/tests/commands/build.test.ts b/tests/commands/build.test.ts new file mode 100644 index 0000000..1c7dfe5 --- /dev/null +++ b/tests/commands/build.test.ts @@ -0,0 +1,13 @@ +import { describe, it, expect } from "vitest"; +import { noCacheArgs } from "../../src/commands/build.js"; + +describe("noCacheArgs", () => { + it("adds --no-cache when the cache option is false (silo build --no-cache)", () => { + expect(noCacheArgs(false)).toEqual(["--no-cache"]); + }); + + it("adds nothing when the cache option is true or unset", () => { + expect(noCacheArgs(true)).toEqual([]); + expect(noCacheArgs(undefined)).toEqual([]); + }); +});