image

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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.

func List

func List(
	ctx context.Context,
	p Provider,
	_ ListInput,
) ([]Entry, error)

List reads the images of the host.

type ListInput

type ListInput struct{}

ListInput is list's input; list takes none.

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.

func Pull

func Pull(
	ctx context.Context,
	p Provider,
	in PullInput,
) (PullResult, error)

Pull pulls an image.

type Result

type Result struct {
	Image   string `json:"image"   doc:"The image"`
	Changed bool   `json:"changed" doc:"Whether the host changed"`
}

Result is delete's output.

func Delete

func Delete(
	ctx context.Context,
	p Provider,
	in DeleteInput,
) (Result, error)

Delete removes an image.

Directories

Path Synopsis
Package mocks holds the generated double of the image provider, for the methods' tests.
Package mocks holds the generated double of the image provider, for the methods' tests.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL