Expand description
Content-addressed build-or-reuse for an image: what Sandbox::ensure_image does (#221).
A harness with many concurrent trials of one task needs one image for them all: the one already built, the one a sibling trial is building, or — when there is none — one it builds itself. This module is that composition, from build inputs to a usable image:
- Name (IMAGE-6).
<prefix>-<hash12>, the hash over the artifact’s inputs (the daemon, the Dockerfile, the build context —artifact_content_hash_with_context) plus the base image, the size class and every field the service sets only when it creates the image (identity repair,inherit_workdir, the hook timeouts, the log destination), because an image is created on one base at one size with those fixed. Equal inputs name one image; any changed input names a fresh one, which is what keeps a stale snapshot, or one built without a field the caller asked for, from being served under a reused name. - Artifact (IMAGE-7). The Dockerfile, the daemon, and the context, zipped with fixed dates and modes, so equal inputs are one object at one content-addressed key.
- ARN and upload (IMAGE-8). The service takes image ARNs, not names, so the ARN is
built from the caller’s account, looked up once per sandbox
(
super::services::BuildServices::caller_account). The artifact goes tos3://<bucket>/<prefix>/<name>/artifact.zip, and only when a build is needed. - Decide (IMAGE-9, IMAGE-10). After each describe,
plansays what to do: reuse a ready image, wait for one building, delete a failed one (or, underforce, any one) and wait for the name to be free, or build. - Race (IMAGE-11). Two trials that both find the name free both create; the service accepts one and refuses the other. The loser describes again and waits for the winner’s build, returning it only once it is ready, and marks it reused.
crates/model/src/image.rs is this module as a Stateright model: two concurrent callers against
a platform that moves the image through its states, checked over every interleaving. The
decision table there is plan’s, row for row.
§Everything local happens before the first call
prepare derives the name, the key, the artifact, and the create request, and runs the
create call’s preflight, with zero calls. A request this client refuses costs nothing: not
the account lookup, not a describe, not the upload.
§Timeouts
The build wait is the one build uses — WaitOpts::default, 45 minutes with a
four-minute stall probe — or the caller’s wait_timeout. The wait for a deleted name to
free up is DEFAULT_DELETE_TIMEOUT.
Structs§
- Ensure
Image Request - Everything
Sandbox::ensure_imageneeds. - Ensured
Image - What
Sandbox::ensure_imagereturns. - Prepared
- Everything
preparedecided locally: the name, the key, the artifact, and the create request, with the create’s preflight already passed.
Enums§
- Found
- What a describe of the ensured image found.
- Plan
- What
ensure_imagedoes next with what a describe found.
Constants§
- DEFAULT_
DELETE_ TIMEOUT - How long a deleted image may take to free its name before
ensure_imagegives up.
Functions§
- artifact_
key - The artifact’s S3 key:
<prefix>/<name>/artifact.zip, with the prefix’s empty segments dropped so no key starts with or doubles a/(IMAGE-8). - ensured_
image_ name - The image name for a prefix and an identity hash:
<prefix>-<hash12>(IMAGE-6). - image_
identity_ hash - The identity an ensured image is named for (IMAGE-6): the artifact’s content hash, the
base image’s name (what
baseImageArnnames), and the size class’s baseline, for an image created withCreateImageRequest::new’s create-only fields. - pinned_
identity_ hash image_identity_hashwith the base version a build pins (#258): a pinned base builds on that version whatever the service’s default later becomes, so the pin is identity.- plan
- The decision
ensure_imagemakes after each describe (IMAGE-9, IMAGE-10). - prepare
- The local half of
ensure_image: every name, key, and artifact decision and every guard, with zero calls. - s3_
location - The bucket and key of an
s3://<bucket>/<key>URI, refused when it isn’t one S3 admits.