Images
Convert OCI images into bootable rootfs images with the images service
The images service converts an OCI image, such as ubuntu:24.04, into a
rootfs on a Firecracker host, the step a Fusefile’s
from: runs inside
fuse up. A create boots the result by naming its digest in
Spec.ImageDigest. Public registries only, and only apt and dnf based images
convert.
client.Images
func (s *ImagesService) Convert(ctx context.Context, req ConvertImageRequest, opts ...CallOption) (*Image, error)
func (s *ImagesService) Get(ctx context.Context, digest string) (*Image, error)
func (s *ImagesService) GetOnHost(ctx context.Context, hostID, digest string) (*Image, error)
Convert sends POST /v1/images and returns the image at once (a 202),
usually still ImageConverting. The bake keeps running on the host if your
process goes away. Converting a ref that is already converting or ready returns
that image; one that failed is converted again. The convert runs as an
operation: each call sends an Idempotency-Key, a
fresh one unless you pass WithIdempotencyKey, and a retry of the same request
under the same key attaches to the first convert. The same key with another
ref is a 409 whose Details["reason"] is idempotency_key_reused. A convert
that answered 5xx, such as the 507 below, runs again when retried under its
key. One that outlasts the server’s wait is followed until it answers. A malformed ref, a registry that
needs credentials, or a HostID that runs the QEMU backend is an error
IsInvalidArgument reports; a ref the registry does not have is one
IsNotFound reports. A host whose image cache is full evicts its least recently
used images first; when every one is converting or used by a vm or snapshot the
convert is a 507 that IsUnavailable reports. An evicted image reads as
not found again until it is converted again.
Get reads an image by digest. When more than one host holds it, the most
usable record wins: ready, then converting, then failed. An unknown digest is an
error IsNotFound reports. There is no Wait: poll Get until State is no
longer ImageConverting.
GetOnHost reads one host’s record (GET /v1/hosts/{hostId}/images/{digest}).
To wait on a convert pinned with HostID, Region or Labels, poll it with
the HostID the convert returned: Get could answer with another host’s ready
record while the pinned host is still converting. An unknown host, or a host
without the digest, is an error IsNotFound reports; a QEMU host is one
IsInvalidArgument reports.
img, err := client.Images.Convert(ctx, fuse.ConvertImageRequest{Ref: "ubuntu:24.04"})
if err != nil {
return err
}
for img.State == fuse.ImageConverting {
time.Sleep(2 * time.Second)
if img, err = client.Images.Get(ctx, img.Digest); err != nil {
return err
}
}
if img.State != fuse.ImageReady {
return fmt.Errorf("convert %s: %s", img.Ref, img.Error)
}
env, err := client.Environments.Create(ctx, fuse.CreateRequest{
TaskID: "t",
Spec: fuse.Spec{ImageDigest: img.Digest},
})
ConvertImageRequest
type ConvertImageRequest struct {
Ref string
HostID string
Region string
Labels map[string]string
}
Refis required: an OCI reference such asubuntu:24.04orghcr.io/org/app@sha256:<digest>.HostID,RegionandLabelspick the Firecracker host the way a create’s placement does. Convert where the environment will run: a create lands only on a host where the image is ready.
Image
type Image struct {
Digest string
Ref string
ManifestDigest string
HostID string
State string // ImageConverting, ImageReady or ImageFailed
Error string
}
Digestis a hex sha256 of the manifest digest for the host’s arch and thefusedbinary baked into the rootfs, so a moved tag or a newfusedis a new image.Errorsays why whenStateisImageFailed.
Spec.ImageDigest
Spec.ImageDigest boots a converted image. The create is pinned to a host
where the image is ready; one that is not ready on any host is a 409
conflict. It is mutually exclusive with Spec.Image and SeedSnapshotID,
and is refused with Spec.GPUs and with a desktop (a 400).