Build caching
AgentBox builds a template as an ordered set of layers. When an instruction and its inputs have not changed, a completed layer can be reused.
Put stable work before frequently changed inputs:
- select the base image;
- install system dependencies;
- copy the package manifest and install packages;
- copy application source near the end.
skipCache() or skip_cache() bypasses the cache for the next instruction and every instruction after it. Pass skipCache: true or skip_cache=True to Template.build to bypass the layer cache for the entire build.
mjs
import { Template } from "@abox-dev/sdk";
const templateName = process.env.TEMPLATE_NAME ?? "cached-template";
const template = Template()
.fromBaseImage()
.runCmd("python3 -c 'print(6 * 7)'")
.skipCache()
.runCmd("echo refreshed");
await Template.build(template, templateName, { tags: ["v1"] });
await Template.build(template, templateName, {
tags: ["v2"],
skipCache: true,
});
console.log("Built cached-template:v1 and cached-template:v2");For copy, use forceUpload or force_upload when the local file must be uploaded again regardless of its content.