Documentation
¶
Overview ¶
Package image is the image behavior: the Docker images of the host. It reads them through gohai's docker collector, and pulls and removes them with the docker CLI, on each platform where docker answers.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Behavior = behavior.Register(behavior.Define( "image", "The Docker images of the host", behavior.Title("Container image"), behavior.Node, behavior.API, behavior.Area(area.Containers), behavior.CLI, behavior.Platform(behavior.PlatformLinux, newCLI), behavior.Platform(behavior.PlatformDarwin, newCLI), behavior.Sudo("docker"), behavior.Runs("docker"), behavior.Read("list", List). Describe("List the images of the host"). Explain("Reads each image through gohai's docker collector, which runs docker images. "+ "A host whose docker does not answer reports skipped."). Example("A host with an image", ListInput{}, []Entry{{ID: "91ef0af61f39", Repository: "alpine", Tag: "3.20", Size: "7.8MB"}}, answers, behavior.Prints(imagesCmd, `{"ID":"91ef0af61f39","Repository":"alpine","Tag":"3.20","Size":"7.8MB"}`+"\n"), ), behavior.Action("pull", Pull). Describe("Pull an image"). Explain("Runs docker pull, and answers the ID and the size of the image that the host "+ "has after it. A pull that gets nothing new, because the host had the image of "+ "that reference already, reports changed: false."). Example("Pull an image", PullInput{Image: image}, PullResult{Image: image, ImageID: id, Size: 3634816, Changed: true}, pulled, behavior.Ran("docker", "pull", image), behavior.Reads(ListInput{}, Entry{Repository: "alpine", Tag: "3.20"}), ). Fails("An image that is an option", PullInput{Image: "--all-tags"}, "image_ref"). Fails("No image", PullInput{}, "required"), behavior.Write("delete", Delete).Key("image"). Describe("Remove an image"). Explain("Runs docker rmi, with -f when force is set, which removes an image that a "+ "container uses. An image that the host does not have reports changed: false."). Example("Remove an image", DeleteInput{Image: image}, Result{Image: image, Changed: true}, pulled, gone, behavior.After(PullInput{Image: image}), behavior.Ran("docker", "rmi", image), behavior.ReadsNone(ListInput{}, Entry{Repository: "alpine", Tag: "3.20"}, "repository", "tag"), ). Example("An image that the host does not have", DeleteInput{Image: image}, Result{Image: image}, behavior.ReadsNone(ListInput{}, Entry{Repository: "alpine", Tag: "3.20"}, "repository", "tag"), ). Fails("An image that is an option", DeleteInput{Image: "-f"}, "image_ref"), ))
Behavior is the image definition.
Functions ¶
This section is empty.
Types ¶
type DeleteInput ¶
type DeleteInput struct {
Image string `json:"image" validate:"required,image_ref" doc:"The image, by its reference or its ID"`
Force bool `json:"force,omitempty" validate:"omitempty" doc:"Remove it also when a container uses it"`
}
DeleteInput is delete's input.
type Entry ¶
type Entry struct {
ID string `json:"id" doc:"The image's ID"`
Repository string `json:"repository" doc:"Its repository, such as alpine"`
Tag string `json:"tag" doc:"Its tag, such as 3.20"`
Size string `json:"size" doc:"Its size, as docker prints it, such as 7.8MB"`
}
Entry is one image, as list answers it.
type Provider ¶
type Provider interface {
List(ctx context.Context) ([]Entry, error)
Pull(ctx context.Context, image string) (PullResult, error)
Delete(ctx context.Context, image string, force bool) (bool, error)
}
Provider reads the images of the host and changes them. host.go is the one implementation, the same on each platform.
type PullInput ¶
type PullInput struct {
Image string `json:"image" validate:"required,image_ref" doc:"The image, such as alpine:3.20" telemetry:"attr"`
}
PullInput is pull's input.
type PullResult ¶
type PullResult struct {
Image string `json:"image" doc:"The image"`
ImageID string `json:"image_id" doc:"The ID of the image that the host has now"`
Size int64 `json:"size" doc:"Its size in bytes"`
Changed bool `json:"changed" doc:"Whether the pull got a new image: false when the host had it already"`
}
PullResult is pull's output.