diff --git a/apps/api/test/e2e/native-compose-build.e2e.test.ts b/apps/api/test/e2e/native-compose-build.e2e.test.ts index f9d677040..c13176cf8 100644 --- a/apps/api/test/e2e/native-compose-build.e2e.test.ts +++ b/apps/api/test/e2e/native-compose-build.e2e.test.ts @@ -318,6 +318,12 @@ describeDockerE2E("native Compose build batches", () => { stderr: "", })); const commands = vi.spyOn(executor, "exec"); + const write = executor.writeFile.bind(executor); + // An unattainable free-space target reproduces pressure without filling the + // test host. The production reservedSpace/budget/guard remain unchanged. + const writes = vi.spyOn(executor, "writeFile").mockImplementation((path, contents, options) => + write(path, /^\/tmp\/openship-buildkit-.*\.toml$/.test(path) + ? contents.replace('minFreeSpace = "20%"', 'minFreeSpace = "100%"') : contents, options)); try { const batch = specs("protected"); for (const spec of batch) spec.config.resources = { cpuCores: 1, memoryMb: 2048, diskMb: 0 }; @@ -341,8 +347,18 @@ describeDockerE2E("native Compose build batches", () => { ) ).trim(), ).not.toBe(""); + logs.length = 0; + const warm = await runtime.buildImages(specs("protected-warm").map(spec => ({ + ...spec, config: { ...spec.config, resources: batch[0]!.config.resources }, + })), logger()); + expect(warm.map(entry => entry.result.status), JSON.stringify(warm)) + .toEqual(["deploying", "deploying", "deploying"]); + expect(logs.map(entry => entry.message).join("\n")) + .toMatch(/#(\d+) \[[^\n]+\] RUN sleep 2[^\n]*\n(?:\n)*#\1 CACHED/); + writes.mockRestore(); await verifyGeneratedEnvironmentBatch("protected-secrets", { cpuCores: 2, memoryMb: 2048, diskMb: 0 }); } finally { + writes.mockRestore(); commands.mockRestore(); await workerImage.dispose(); } diff --git a/docs/build-cache.md b/docs/build-cache.md index afa916149..5632d7b11 100644 --- a/docs/build-cache.md +++ b/docs/build-cache.md @@ -134,8 +134,14 @@ with the host daemon's native cache and migration sources never build, so the se offered on either. Collection removes the least recently used idle state first. BuildKit workers also receive that cache ceiling and a native BuildKit GC target of -20% free space. Attached state and active build records remain protected. Collection runs -before and after builds and in the daily cache sweep. Explicit cache clearing and project deletion use +20% free space. Their `reservedSpace` uses the same bounded minimum of the configured +budget and `min(5 GiB, 10%)`. This prevents BuildKit from discarding fresh layers merely +because application data makes the free-space target unattainable. It does not preallocate +disk space or exempt idle caches from emergency cleanup. +Attached state and active build records remain protected. Builds measure free bytes and +inodes before and after execution; they scan idle caches only below the free-space target +or when inodes are exhausted. The daily sweep handles routine budget and age accounting. +Explicit cache clearing and project deletion use the same protected collector for both Cloud and SSH destinations. Project deletion handles deleted-project state; the daily Cloud sweep also discovers ready owned hosts whose last project was moved or deleted. diff --git a/packages/adapters/src/runtime/cloud-build-limits.test.ts b/packages/adapters/src/runtime/cloud-build-limits.test.ts index 9bca8feee..7caa657b4 100644 --- a/packages/adapters/src/runtime/cloud-build-limits.test.ts +++ b/packages/adapters/src/runtime/cloud-build-limits.test.ts @@ -23,6 +23,7 @@ function fixture(transport = "cloud", buildKit = true, resources = config.resour command.includes("docker info --format '{{.ID}}'") ? "test-daemon" : command.startsWith("docker info --format") ? JSON.stringify({ OSType: "linux", SecurityOptions: [] }) : command.startsWith("docker image inspect") ? JSON.stringify([{ Config: { Labels: { "org.openship.build-metadata-policy": "1" }, Entrypoint: ["/usr/local/bin/openship-buildkitd"] } }]) : + command.includes("OPENSHIP_BUILD_WORKERS_STOPPED") ? "OPENSHIP_BUILD_WORKERS_STOPPED\n" : command.includes("df -Pk") ? "104857600 52428800\n200000 100000\n" : "", ), writeFile: vi.fn(async () => {}), @@ -61,6 +62,41 @@ function fixture(transport = "cloud", buildKit = true, resources = config.resour } describe("Cloud Docker build execution limits", () => { + it("keeps routine cache inventory out of a build with sufficient storage", async () => { + const h = fixture(); + await h.run(); + expect(h.runtime._docker.listVolumes).not.toHaveBeenCalled(); + expect(h.runtime._docker.listContainers).not.toHaveBeenCalled(); + expect(h.commands()).not.toContain("du -sk"); + expect(h.commands()).toContain("df -Pk"); + }); + + it.each(["bytes", "inodes", "headroom"])("reclaims idle cache under %s pressure", async dimension => { + const h = fixture(); + const exec = h.executor.exec.getMockImplementation()!; + let reclaimed = false; + h.executor.exec.mockImplementation(command => command.includes("df -Pk") && !reclaimed + ? Promise.resolve(dimension === "bytes" ? "104857600 0\n200000 100000\n" : dimension === "headroom" ? "104857600 15728640\n200000 100000\n" : "104857600 52428800\n200000 0\n") + : exec(command)); + h.runtime.pruneManagedBuildState = vi.fn(async () => { + reclaimed = true; + return { cachesDeleted: ["idle-cache"], spaceReclaimed: 4096 }; + }); + await h.run(); + expect(h.runtime.pruneManagedBuildState).toHaveBeenCalledTimes(1); + expect(h.executor.streamExec).toHaveBeenCalledTimes(1); + }); + + it("refuses repository execution when reclaim does not restore storage", async () => { + const h = fixture(); + const exec = h.executor.exec.getMockImplementation()!; + h.executor.exec.mockImplementation(command => command.includes("df -Pk") + ? Promise.resolve("104857600 0\n200000 100000\n") : exec(command)); + h.runtime.pruneManagedBuildState = vi.fn(async () => ({ cachesDeleted: [], spaceReclaimed: 0 })); + await expect(h.run()).rejects.toMatchObject({ code: "BUILD_STORAGE_LOW" }); + expect(h.executor.streamExec).not.toHaveBeenCalled(); + }); + it("clears both native and protected caches on explicit trusted-host maintenance", async () => { const h = fixture("ssh"); h.runtime.connectionOptions.nativeBuilds = true; diff --git a/packages/adapters/src/runtime/docker-build-cache-policy.test.ts b/packages/adapters/src/runtime/docker-build-cache-policy.test.ts index c25062a05..daee53ec8 100644 --- a/packages/adapters/src/runtime/docker-build-cache-policy.test.ts +++ b/packages/adapters/src/runtime/docker-build-cache-policy.test.ts @@ -203,6 +203,17 @@ fi ).toContain('minFreeSpace = "20%"'); }); + it.each([ + { total: 100, budget: null, reserved: 5 }, + { total: 25, budget: null, reserved: 2.5 }, + { total: 10, budget: null, reserved: 1 }, + { total: 100, budget: 1, reserved: 1 }, + ])("retains a bounded warm cache when the free-space target cannot be met: %j", ({ total, budget, reserved }) => { + const config = buildKitCacheConfig({ totalBytes: total * GIB, freeBytes: 3 * GIB, freeInodes: 100 }, budget === null ? null : budget * GIB); + expect(config).toContain(`reservedSpace = ${reserved * GIB}\n`); + expect(config).toContain('minFreeSpace = "20%"'); + }); + it("keeps a cache larger than the old fixed 5 GiB ceiling when the disk has room", async () => { // 100 GiB Docker filesystem: the automatic budget is 20 GiB. const h = fixture([volume("a", 13 * GIB)]); diff --git a/packages/adapters/src/runtime/docker-build-cache.test.ts b/packages/adapters/src/runtime/docker-build-cache.test.ts index 59227bf76..0b52e42c8 100644 --- a/packages/adapters/src/runtime/docker-build-cache.test.ts +++ b/packages/adapters/src/runtime/docker-build-cache.test.ts @@ -100,7 +100,10 @@ describe("managed project cache cleanup", () => { ), ); } - if (command.startsWith("docker buildx rm")) attached = false; + if (command.includes("OPENSHIP_BUILD_WORKERS_STOPPED")) { + attached = false; + return "OPENSHIP_BUILD_WORKERS_STOPPED\n"; + } if (command.includes("df -Pk")) return "OPENSHIP_STORAGE 104857600 52428800\nOPENSHIP_INODES 100000\n"; if (command.startsWith("du ")) return "1024\t/cache/state\n"; diff --git a/packages/adapters/src/runtime/docker-build-cache.ts b/packages/adapters/src/runtime/docker-build-cache.ts index bff8852d7..5f3f19ad7 100644 --- a/packages/adapters/src/runtime/docker-build-cache.ts +++ b/packages/adapters/src/runtime/docker-build-cache.ts @@ -92,6 +92,10 @@ export function buildCacheKeepBytes( return Math.min(configuredBytes, Math.max(0, storage.totalBytes - buildStorageReserve(storage))); } +function buildCacheRetentionFloor(storage: BuildStorage): number { + return Math.min(DEFAULT_BUILD_CACHE_KEEP_BYTES, Math.floor(storage.totalBytes / 10)); +} + /** * Below the 20% free-space GC target, idle caches give space back before rollback artifacts and * running apps do: the budget shrinks to what still fits above that target, but never below the @@ -106,7 +110,7 @@ export function pressureAdjustedKeepBytes( ): number { const freeTarget = Math.ceil(storage.totalBytes * BUILD_STORAGE_GC_FREE_FRACTION); if (storage.freeBytes >= freeTarget) return budgetBytes; - const floor = Math.min(DEFAULT_BUILD_CACHE_KEEP_BYTES, Math.floor(storage.totalBytes / 10)); + const floor = buildCacheRetentionFloor(storage); return Math.min(budgetBytes, Math.max(floor, idleCacheBytes + storage.freeBytes - freeTarget)); } @@ -392,5 +396,9 @@ export function buildKitCacheConfig( storage: BuildStorage, configuredBudgetBytes?: number | null, ): string { - return `insecure-entitlements = []\n[worker.oci]\nnetworkMode = "bridge"\ngc = true\nreservedSpace = 0\nmaxUsedSpace = ${buildCacheKeepBytes(storage, configuredBudgetBytes)}\nminFreeSpace = "${BUILD_STORAGE_GC_FREE_FRACTION * 100}%"\n`; + const budget = buildCacheKeepBytes(storage, configuredBudgetBytes); + // Match idle-cache retention: otherwise an unattainable free-space target + // evicts even freshly built layers and every redeploy becomes a cold build. + const reserved = Math.min(budget, buildCacheRetentionFloor(storage)); + return `insecure-entitlements = []\n[worker.oci]\nnetworkMode = "bridge"\ngc = true\nreservedSpace = ${reserved}\nmaxUsedSpace = ${budget}\nminFreeSpace = "${BUILD_STORAGE_GC_FREE_FRACTION * 100}%"\n`; } diff --git a/packages/adapters/src/runtime/docker-buildkit-worker.test.ts b/packages/adapters/src/runtime/docker-buildkit-worker.test.ts index 24add359b..4d28777d6 100644 --- a/packages/adapters/src/runtime/docker-buildkit-worker.test.ts +++ b/packages/adapters/src/runtime/docker-buildkit-worker.test.ts @@ -1,7 +1,72 @@ -import { expect, it, vi } from "vitest"; +import { afterEach, expect, it, vi } from "vitest"; +import { execFile } from "node:child_process"; +import { promisify } from "node:util"; +import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; import { projectBuildKitWorker, removeProjectBuildKitWorker } from "./docker-buildkit-worker"; const worker = projectBuildKitWorker("project-a"); +const directories: string[] = []; +afterEach(async () => { + await Promise.all( + directories.splice(0).map((path) => rm(path, { recursive: true, force: true })), + ); +}); + +// Execute the actual POSIX shell against a controlled Docker command. Checking +// mocked SSH responses alone cannot exercise set -e or reconciliation failures. +async function fixture( + options: { + present?: boolean; + offline?: boolean; + removal?: "failed" | "lost-ack"; + unexpected?: boolean; + } = {}, +) { + const directory = await mkdtemp(join(tmpdir(), "openship-worker-stop-")); + directories.push(directory); + await writeFile(join(directory, "state"), options.present ? worker.containerName : ""); + await writeFile( + join(directory, "docker"), + `#!${process.execPath} +const fs = require("node:fs"); +const args = process.argv.slice(2); +fs.appendFileSync(${JSON.stringify(join(directory, "calls"))}, JSON.stringify(args) + "\\n"); +const state = ${JSON.stringify(join(directory, "state"))}; +const options = ${JSON.stringify(options)}; +if (args[0] === "buildx") process.exit(1); // Missing client metadata is recoverable. +if (args[0] === "container" && args[1] === "ls") { + if (options.offline) process.exit(1); + const name = options.unexpected ? "customer-service" : fs.readFileSync(state, "utf8"); + if (options.unexpected || args.includes("name=^/" + name + "$")) process.stdout.write(name); +} else if (args[0] === "container" && args[1] === "rm") { + if (options.removal === "failed") process.exit(1); + if (args.at(-1) !== fs.readFileSync(state, "utf8")) process.exit(2); + fs.writeFileSync(state, ""); + if (options.removal === "lost-ack") process.exit(1); +} else process.exit(2); +`, + { mode: 0o755 }, + ); + const exec = vi.fn( + async (script: string) => + ( + await promisify(execFile)("sh", ["-c", script], { + env: { ...process.env, PATH: `${directory}:${process.env.PATH}` }, + }) + ).stdout, + ); + return { + exec, + calls: async () => + (await readFile(join(directory, "calls"), "utf8")) + .trim() + .split("\n") + .map((line) => JSON.parse(line) as string[]), + }; +} + it("derives a stable single-node identity without accepting command text from project IDs", () => { expect(worker.builderName).toMatch(/^openship-cache-[a-f0-9]{24}$/); expect(worker.nodeName).toBe(`${worker.builderName}0`); @@ -12,72 +77,58 @@ it("derives a stable single-node identity without accepting command text from pr ); }); -it("removes a daemon worker even when buildx metadata is missing, then verifies absence", async () => { - const exec = vi - .fn() - .mockResolvedValueOnce("") - .mockResolvedValueOnce("") - .mockRejectedValueOnce(new Error("builder metadata missing")) - .mockResolvedValueOnce(`${worker.containerName}\n`) - .mockResolvedValueOnce(worker.containerName) - .mockResolvedValueOnce(""); - await removeProjectBuildKitWorker({ exec }, "project-a"); - expect(exec.mock.calls[3]![0]).toContain(`name=^/${worker.containerName}$`); - expect(exec.mock.calls[4]![0]).toBe(`docker container rm --force '${worker.containerName}'`); - expect(exec.mock.calls[5]).toEqual(exec.mock.calls[3]); - expect(exec.mock.calls.flat().join(" ")).not.toContain( - projectBuildKitWorker("project-b").containerName, - ); -}); +it.skipIf(process.platform === "win32")( + "removes a daemon worker despite missing buildx metadata in one remote command", + async () => { + const h = await fixture({ present: true }); + await removeProjectBuildKitWorker(h, "project-a"); + expect(h.exec).toHaveBeenCalledTimes(1); + const calls = await h.calls(); + expect(calls.filter((args) => args[1] === "rm" && args[0] === "container")).toEqual([ + ["container", "rm", "--force", worker.containerName], + ]); + expect(calls).toContainEqual(["buildx", "rm", "--force", "--keep-state", worker.builderName]); + expect(calls.at(-1)?.slice(0, 2)).toEqual(["container", "ls"]); + }, +); -it("accepts already absent workers only after a successful daemon query", async () => { - const exec = vi - .fn() - .mockResolvedValueOnce("") - .mockResolvedValueOnce("") - .mockRejectedValueOnce(new Error("no buildx plugin")) - .mockResolvedValueOnce(""); - await removeProjectBuildKitWorker({ exec }, "project-a"); - expect(exec).toHaveBeenCalledTimes(4); -}); +it.skipIf(process.platform === "win32")( + "accepts already absent workers only after successful daemon queries", + async () => { + const h = await fixture(); + await removeProjectBuildKitWorker(h, "project-a"); + expect( + (await h.calls()).filter((args) => args[0] === "container").map((args) => args[1]), + ).toEqual(["ls", "ls"]); + }, +); -it("does not mistake an unreachable daemon for an absent worker", async () => { - const exec = vi.fn().mockResolvedValueOnce("").mockResolvedValueOnce("").mockResolvedValueOnce("").mockRejectedValueOnce(new Error("daemon offline")); - await expect(removeProjectBuildKitWorker({ exec }, "project-a")).rejects.toMatchObject({ - code: "CLOUD_BUILD_WORKER_EXIT_UNCONFIRMED", - }); -}); +it + .skipIf(process.platform === "win32") + .each([{ offline: true }, { present: true, removal: "failed" as const }, { unexpected: true }])( + "does not confirm shutdown when Docker cannot prove absence: %j", + async (options) => { + const h = await fixture(options); + await expect(removeProjectBuildKitWorker(h, "project-a")).rejects.toMatchObject({ + code: "CLOUD_BUILD_WORKER_EXIT_UNCONFIRMED", + }); + if (options.unexpected) + expect((await h.calls()).some((args) => args[0] === "container" && args[1] === "rm")).toBe( + false, + ); + }, +); -it("refuses to release when Docker still reports the worker after removal", async () => { - const exec = vi - .fn() - .mockResolvedValueOnce("") - .mockResolvedValueOnce("") - .mockResolvedValueOnce("") - .mockResolvedValueOnce(worker.containerName) - .mockRejectedValueOnce(new Error("removal failed")) - .mockResolvedValueOnce(worker.containerName); - await expect(removeProjectBuildKitWorker({ exec }, "project-a")).rejects.toMatchObject({ - code: "CLOUD_BUILD_WORKER_EXIT_UNCONFIRMED", - }); -}); +it.skipIf(process.platform === "win32")( + "reconciles a lost removal acknowledgement using confirmed daemon absence", + async () => { + const h = await fixture({ present: true, removal: "lost-ack" }); + await expect(removeProjectBuildKitWorker(h, "project-a")).resolves.toBeUndefined(); + }, +); -it("reconciles a lost removal acknowledgement using confirmed daemon absence", async () => { - const exec = vi - .fn() - .mockResolvedValueOnce("") - .mockResolvedValueOnce("") - .mockResolvedValueOnce("") - .mockResolvedValueOnce(worker.containerName) - .mockRejectedValueOnce(new Error("lost acknowledgement")) - .mockResolvedValueOnce(""); - await expect(removeProjectBuildKitWorker({ exec }, "project-a")).resolves.toBeUndefined(); -}); - -it("never removes a container with a different identity", async () => { - const exec = vi.fn().mockResolvedValueOnce("").mockResolvedValueOnce("customer-service"); - await expect(removeProjectBuildKitWorker({ exec }, "project-a")).rejects.toMatchObject({ - code: "CLOUD_BUILD_WORKER_EXIT_UNCONFIRMED", - }); - expect(exec).toHaveBeenCalledTimes(2); +it("rejects a truncated or disconnected command without a completion receipt", async () => { + await expect( + removeProjectBuildKitWorker({ exec: vi.fn(async () => "") }, "project-a"), + ).rejects.toMatchObject({ code: "CLOUD_BUILD_WORKER_EXIT_UNCONFIRMED" }); }); diff --git a/packages/adapters/src/runtime/docker-buildkit-worker.ts b/packages/adapters/src/runtime/docker-buildkit-worker.ts index f1e593f40..6d6e6fda4 100644 --- a/packages/adapters/src/runtime/docker-buildkit-worker.ts +++ b/packages/adapters/src/runtime/docker-buildkit-worker.ts @@ -26,36 +26,39 @@ export async function removeProjectBuildKitWorker( executor: Pick, projectId: string, ): Promise { - for (const [worker, keepState] of [ + const workers = [ [buildKitWorker(projectId, "openship-"), false], [projectBuildKitWorker(projectId), true], - ] as const) await removeBuildKitWorker(executor, worker, keepState); -} - -async function removeBuildKitWorker( - executor: Pick, - { builderName, containerName }: ReturnType, - keepState: boolean, -): Promise { - const list = `docker container ls --all --filter ${sq(`name=^/${containerName}$`)} --format ${sq("{{.Names}}")}`; - const exists = async () => { - const names = (await executor.exec(list)).trim().split(/\r?\n/).filter(Boolean); - if (names.some((name) => name !== containerName)) - throw new Error("Docker returned a different build worker identity"); - return names.length > 0; - }; + ] as const; + const receipt = "OPENSHIP_BUILD_WORKERS_STOPPED"; + // Run the complete reconciliation beside Docker. Repeated lifecycle checks + // still query the daemon, but no longer require four or more remote commands. + const script = [ + "set -eu", + ...workers.flatMap(([worker, keepState]) => { + const { builderName, containerName } = worker; + const list = `docker container ls --all --filter ${sq(`name=^/${containerName}$`)} --format ${sq("{{.Names}}")}`; + return [ + // Buildx metadata can remain after an interrupted client even if its + // container is gone. Remove it without treating its exit code as proof. + `docker buildx rm --force${keepState ? " --keep-state" : ""} ${sq(builderName)} >/dev/null 2>&1 || true`, + `names="$(${list})"`, + `case "$names" in`, + " '') ;;", + ` ${sq(containerName)})`, + ` docker container rm --force ${sq(containerName)} >/dev/null 2>&1 || true`, + ` names="$(${list})"`, + ' test -z "$names" ;;', + " *) exit 1 ;;", + "esac", + ]; + }), + `printf '%s\\n' ${sq(receipt)}`, + ].join("\n"); try { - // Buildx state may already be missing. The daemon check below is authoritative. - // Managed cache GC owns state deletion after the worker is confirmed absent. - await executor.exec(`docker buildx rm --force${keepState ? " --keep-state" : ""} ${sq(builderName)}`).catch(() => { - /* diagnostics-ignore: Confirmed daemon absence below supersedes CLI metadata errors. */ - }); - if (await exists()) { - await executor.exec(`docker container rm --force ${sq(containerName)}`).catch(() => { - /* diagnostics-ignore: A lost removal reply is resolved by the daemon query below. */ - }); - if (await exists()) throw new Error("Docker still reports the project build worker"); - } + const output = await executor.exec(script); + if (!output.split(/\r?\n/).includes(receipt)) + throw new Error("Docker did not confirm build worker shutdown"); } catch (cause) { throw Object.assign( new AppError( diff --git a/packages/adapters/src/runtime/docker.ts b/packages/adapters/src/runtime/docker.ts index abe4653d3..09ca0d246 100644 --- a/packages/adapters/src/runtime/docker.ts +++ b/packages/adapters/src/runtime/docker.ts @@ -46,7 +46,7 @@ import { pinDockerfileBaseImages } from "./docker-base-images"; import type { BaseImageReceipt } from "@repo/core"; import { DEFAULT_BUILD_CACHE_KEEP_BYTES, DOCKER_BUILD_STORAGE_COMMAND, parseBuildStorage, - assertBuildStorage, buildKitCacheConfig, + assertBuildStorage, buildKitCacheConfig, BUILD_STORAGE_GC_FREE_FRACTION, ensureProjectBuildCache, pruneManagedBuildCaches, touchProjectBuildCache, type BuildStorage, } from "./docker-build-cache"; @@ -1800,6 +1800,21 @@ export class DockerRuntime implements RuntimeAdapter { return buildKitCacheConfig(storage, await this.configuredBuildCacheBudget()); } + /** Routine cache accounting belongs to the scheduled sweep. Only storage + * pressure justifies walking idle caches on the deployment path. + * Called under the same host lock as worker creation and cache collection. */ + private async checkManagedBuildStorage(executor: CommandExecutor, log?: BuildLogger): Promise { + const host = await this.buildCacheHostExecutor(executor); + let storage = parseBuildStorage(await host.exec(DOCKER_BUILD_STORAGE_COMMAND)); + if (storage.freeBytes < Math.ceil(storage.totalBytes * BUILD_STORAGE_GC_FREE_FRACTION) || storage.freeInodes === 0) { + const cleaned = await this.pruneManagedBuildState(executor); + if (cleaned.spaceReclaimed) log?.log(`Build cache cleanup reclaimed ${cleaned.spaceReclaimed} bytes.\n`); + storage = parseBuildStorage(await host.exec(DOCKER_BUILD_STORAGE_COMMAND)); + } + assertBuildStorage(storage); + return storage; + } + /** A failed settings read falls back to the automatic budget rather than failing a build. */ private async configuredBuildCacheBudget(): Promise { try { @@ -1926,10 +1941,7 @@ export class DockerRuntime implements RuntimeAdapter { signal?.throwIfAborted(); await removeProjectBuildKitWorker(executor, config.projectId); await this.assertBuildCacheCommandsStopped(config.projectId); - const cleaned = await this.pruneManagedBuildState(executor); - if (cleaned.spaceReclaimed) log.log(`Build cache cleanup reclaimed ${cleaned.spaceReclaimed} bytes.\n`); - const storage = parseBuildStorage(await cacheHost.exec(DOCKER_BUILD_STORAGE_COMMAND)); - assertBuildStorage(storage); + const storage = await this.checkManagedBuildStorage(executor, log); const reused = await ensureProjectBuildCache(this.docker, config.projectId); const configPath = `/tmp/openship-buildkit-${randomUUID()}.toml`; try { @@ -1958,8 +1970,7 @@ export class DockerRuntime implements RuntimeAdapter { await removeProjectBuildKitWorker(executor, projectId); await this.assertBuildCacheCommandsStopped(projectId); await this.withBuildCacheLock(async () => { - await this.pruneManagedBuildState(executor); - assertBuildStorage(parseBuildStorage(await (await this.buildCacheHostExecutor(executor)).exec(DOCKER_BUILD_STORAGE_COMMAND))); + await this.checkManagedBuildStorage(executor); }); }