Container artifacts
Background
The files in the container filesystem come from multiple sources:
- the container image typically holds the root filesystem of the container
- files the container has written to its writable layer are kept until the next container restart
- config files specified directly in the application specification and secrets stored in strongbox may be mounted read-only
- files written by the container itself in ephemeral and persistent volumes are persistent according to the corresponding volume lifecycle
In addition to this we have seen a need to mount an identical copy of a large file (too large to be inlined in the application specification as a config file) into containers on many sites, without requiring such a file to be baked into the container image. Example use-cases include distributing an ML model separately from the inference engine distributed in the container image, or distributing a VM installation media or a base VM disk separately from the image containing the hypervisor. This means, for example, that the inference engine may have its own lifecycle and the whole model does not have to be redistributed on smaller engine changes; or that the same model can be mounted in containers running different inference engines (perhaps, due to different hardware). This use-case motivates the container artifacts feature.
Concepts
A container artifact is a file or a collection of files stored in a container registry, similarly to how container images are stored. These files can be mounted into containers as a read-only volume.
The OCI distribution spec defines an artifact as a piece of content consisting of blobs with an accompanying manifest (also called an "object" in more recent versions of the specification). In other words, any collection of blobs with an attached manifest stored in a container registry is an artifact, whether or not it matches the OCI image format. However, it is important to note that not all artifacts in the broad OCI meaning are usable for mounting into containers.
Artifact types
In the context of the Avassa system, only certain defined types of artifacts are usable for the purpose of mounting read-only into the container:
- an artifact with type
application/vnd.avassa.file.v1that refers to a single blob holding the file contents, mounted as a regular file inside the container - an artifact with type
application/vnd.avassa.bundle.v1that refers to one or more blobs, each holding the contents of one file and annotated with its file name in the manifest; mounted as a directory inside the container, with the option to mount individual files by name - a container image with a single layer, mounted as a directory inside the container, with the option to mount individual files by name
Refer to the reference documentation for the description of how the artifacts with these types are expected to be formed.
Artifact references
Artifacts are referenced in the same way as images. The artifact reference includes an artifact name, a tag or digest and an optional registry. In the same way as images, artifacts may be stored in the Control Tower image registry or in an external registry. If the reference includes a registry address, the artifact is automatically pulled from that registry into the Control Tower registry. A reference without a registry address uses the configured default remote registry, or, if none is configured, the artifact has to be pushed to the Control Tower registry manually.
A reference that begins with a /, for example /mymodel:v1, always refers
to a repository in the Control Tower registry: no part of it is read as a
registry address, and no pull is attempted. This is useful when the first
component of the repository name looks like a hostname, for example
/docker.io/mymodel:v1.
It is also important to note that the rules for resolving an artifact tag are the same as for images: the tag is resolved to the corresponding artifact hash before the application is distributed to the edge sites. If the tag is moved to a new artifact hash, the application will not use the new artifact until the application version is updated. An application without a version specified picks up the new artifact.
Distributing artifacts to sites
The artifacts are distributed to sites just like images. When an application is deployed to the sites, these sites download all required artifacts before attempting to start the containers.
An artifact downloaded to the site is stored in one or more replicas in the site-local image registry. When mounted by an application, a working copy of the artifact is copied from the site-local image registry to the disk of each host where the services requiring this artifact are scheduled to run, similarly to how images are checked out to Docker cache, with the difference being that artifacts are checked out using the Avassa internal tools outside of Docker. If there are multiple containers on the host using the same artifact, then they share the single copy of it. The artifact is always mounted read-only, so this is safe.
Uploading artifacts to the registry
Artifacts can be stored either in the Control Tower registry or in an external registry. See Choosing between the Control Tower registry and an external registry for guidance on which to use.
In order to facilitate uploading the application/vnd.avassa.file.v1 and
application/vnd.avassa.bundle.v1 artifacts, there are special API endpoints
to upload one or multiple files to the Control Tower
registry. The corresponding supctl commands can be used to stream files from
the operator's machine to the Control Tower.
load-file and load-files API endpoints and supctl commands require the
registry-push capability. The same capability is required when pushing
images or artifacts with docker or oras using the Registry API.
See examples of uploading file and bundle artifacts to the Control Tower
registry with
supctl
and uploading a single-layer image
artifact.
In the case of a bundle, each file is stored as a layer of the artifact, and
its name is stored in the org.opencontainers.image.title annotation of the
layer. Layers without a title are ignored.
The mountpoint for the bundle is a directory with files under their stored
names by default, see mounting a bundle example and mounting
selected files from a bundle example. The file name is
not stored in the case of a single file, because the mountpoint is a file and
the file name is determined by the mount path, see mounting an artifact file
example. In both cases the file permissions are stored in the
io.avassa.file.mode annotation of the layer, as three or four octal digits,
for example 0755. The annotation is optional, and the default mode is 0444.
The setuid, setgid and sticky bits are ignored. The file ownership is
determined by the file-ownership setting of the volume, by default owned by root.
Just like a bundle, by default a single-layer image is mounted as a directory
into the container, with an option to mount only selected files individually.
The file name, permissions and ownership info are natively embedded in the
image's tar layer.
When uploading to the Control Tower registry, there is no advantage to using a single-layer image over bundle artifacts, and it requires more steps to produce, so it is only recommended if an image is readily available, or if it fits the continuous integration better.
If storing artifacts in an external registry is desired, the following example
shows how to upload an artifact with the oras
tool.
Single-layer images stored in external registries are also valid artifacts,
and can be pushed just like any other image.