Documentation
¶
Index ¶
- Constants
- func ParseReference(imageStr string) (imageRef string, originalRef string, err error)
- func WithLazyLayerSquashes(ctx context.Context) context.Context
- type AdditionalMetadata
- func WithArchitecture(architecture, variant string) AdditionalMetadata
- func WithConfig(config []byte) AdditionalMetadata
- func WithManifest(manifest []byte) AdditionalMetadata
- func WithManifestDigest(digest string) AdditionalMetadata
- func WithOS(o string) AdditionalMetadata
- func WithPlatform(platform string) AdditionalMetadata
- func WithRepoDigests(digests ...string) AdditionalMetadata
- func WithTags(tags ...string) AdditionalMetadata
- type ErrPlatformMismatch
- type FileCatalog
- func (c *FileCatalog) Add(f file.Reference, m file.Metadata, l *Layer, opener file.Opener)
- func (c *FileCatalog) AssociateLayer(f file.Reference, l *Layer)
- func (c *FileCatalog) AssociateOpener(f file.Reference, opener file.Opener)
- func (c *FileCatalog) Layer(f file.Reference) *Layer
- func (c *FileCatalog) Open(f file.Reference) (io.ReadCloser, error)
- type FileCatalogReader
- type Image
- func (i *Image) Cleanup() error
- func (i *Image) FileContentsByRef(ref file.Reference) (io.ReadCloser, error)deprecated
- func (i *Image) FileContentsFromSquash(path file.Path) (io.ReadCloser, error)deprecated
- func (i *Image) FilesByMIMETypeFromSquash(mimeTypes ...string) ([]file.Reference, error)deprecated
- func (i *Image) IDs() []string
- func (i *Image) OpenPathFromSquash(path file.Path) (io.ReadCloser, error)
- func (i *Image) OpenReference(ref file.Reference) (io.ReadCloser, error)
- func (i *Image) Read(ctx context.Context) error
- func (i *Image) ResolveLinkByImageSquash(ref file.Reference, options ...filetree.LinkResolutionOption) (*file.Resolution, error)
- func (i *Image) ResolveLinkByLayerSquash(ref file.Reference, layer int, options ...filetree.LinkResolutionOption) (*file.Resolution, error)
- func (i *Image) SquashedTree() filetree.Reader
- type Layer
- func (l *Layer) FileContents(path file.Path) (io.ReadCloser, error)deprecated
- func (l *Layer) FileContentsFromSquash(path file.Path) (io.ReadCloser, error)deprecated
- func (l *Layer) FilesByMIMEType(mimeTypes ...string) ([]file.Reference, error)deprecated
- func (l *Layer) FilesByMIMETypeFromSquash(mimeTypes ...string) ([]file.Reference, error)deprecated
- func (l *Layer) OpenPath(path file.Path) (io.ReadCloser, error)
- func (l *Layer) OpenPathFromSquash(path file.Path) (io.ReadCloser, error)
- func (l *Layer) Read(catalog *FileCatalog, idx int, uncompressedLayersCacheDir string) error
- type LayerMetadata
- type Metadata
- type Platform
- type Provider
- type RegistryCredentials
- type RegistryOptions
- type Source
Constants ¶
const ( LayerFetchExecutor = "layer-fetch" LayerIndexExecutor = "layer-index" )
LayerFetchExecutor and LayerIndexExecutor name the go-sync executors bounding each stage of a layer read. Install one under either name to take over that stage's concurrency:
ctx = sync.SetContextExecutor(ctx, image.LayerFetchExecutor, sync.NewExecutor(2))
A caller-supplied executor always wins; Read only fills in what is missing. It must run every function handed to Go: Read waits for in-flight workers rather than abandoning them, so an executor that silently drops work will hang the read.
const ( SingularitySquashFSLayer types.MediaType = "application/vnd.sylabs.sif.layer.v1.squashfs" BuildKitZstdCompressedLayer types.MediaType = "application/vnd.docker.image.rootfs.diff.tar.zstd" BuildKitZstdCompressedLayerAlt types.MediaType = "application/vnd.docker.image.rootfs.diff.tar+zstd" // we're future proofing against a possible media type variation )
Variables ¶
This section is empty.
Functions ¶
func ParseReference ¶ added in v0.0.2
func WithLazyLayerSquashes ¶ added in v0.4.0
WithLazyLayerSquashes returns a context that tells Read to build only the image squash (the top layer's), and to build every lower layer's squash the first time something uses it. By default Read builds every layer's squash, and since each one is a full copy of the tree below it, memory grows with layers x files. Use this when you expect to need only the image squash (for example a squashed-scope scan): lower layers then cost nothing.
Lower layers still work, Layer.SquashedTree and Layer.SquashedSearchContext are never nil, but:
- the first call that touches a lower layer builds its squash, and the squash of every layer below it that has not been built yet. That call can take a while and cannot be cancelled, since no context reaches it. Concurrent callers wait for the same build rather than repeating it.
- a failed build no longer fails Read. Methods that return an error report it, and the rest see an empty tree (see filetree.NewLazySquash). A caller that must not miss files (a scanner) should read lower layers through the methods that return an error: SquashedSearchContext, and SquashedTree's File, FilesByGlob, ListPaths and Walk, rather than AllFiles or HasPath.
- a lower layer's SquashedTree is not a *filetree.FileTree, so type assertions on it fail.
It applies to every Read under the returned context, so set it on a context scoped to the reads that want it.
Types ¶
type AdditionalMetadata ¶
func WithArchitecture ¶
func WithArchitecture(architecture, variant string) AdditionalMetadata
func WithConfig ¶
func WithConfig(config []byte) AdditionalMetadata
func WithManifest ¶
func WithManifest(manifest []byte) AdditionalMetadata
func WithManifestDigest ¶
func WithManifestDigest(digest string) AdditionalMetadata
func WithOS ¶
func WithOS(o string) AdditionalMetadata
func WithPlatform ¶
func WithPlatform(platform string) AdditionalMetadata
func WithRepoDigests ¶
func WithRepoDigests(digests ...string) AdditionalMetadata
func WithTags ¶
func WithTags(tags ...string) AdditionalMetadata
type ErrPlatformMismatch ¶ added in v0.0.12
ErrPlatformMismatch is meant to be used when a provider has positively resolved the image but the image OS or architecture does not match with what was requested.
func (*ErrPlatformMismatch) Error ¶ added in v0.0.12
func (e *ErrPlatformMismatch) Error() string
func (*ErrPlatformMismatch) Unwrap ¶ added in v0.0.12
func (e *ErrPlatformMismatch) Unwrap() error
type FileCatalog ¶
FileCatalog represents all file metadata and source tracing for all files contained within the image layer blobs (i.e. everything except for the image index/manifest/metadata files).
func NewFileCatalog ¶
func NewFileCatalog() *FileCatalog
NewFileCatalog returns an empty FileCatalog.
func (*FileCatalog) Add ¶
Add creates a new FileCatalogEntry for the given file reference and metadata, cataloged by the ID of the file reference (overwriting any existing entries without warning).
func (*FileCatalog) AssociateLayer ¶ added in v0.1.5
func (c *FileCatalog) AssociateLayer(f file.Reference, l *Layer)
func (*FileCatalog) AssociateOpener ¶ added in v0.1.5
func (c *FileCatalog) AssociateOpener(f file.Reference, opener file.Opener)
func (*FileCatalog) Open ¶
func (c *FileCatalog) Open(f file.Reference) (io.ReadCloser, error)
Open returns a io.ReadCloser for the given file reference. The underlying io.ReadCloser will not attempt to allocate resources until the first read is performed.
type FileCatalogReader ¶
type FileCatalogReader interface {
Layer(file.Reference) *Layer
Open(file.Reference) (io.ReadCloser, error)
filetree.IndexReader
}
type Image ¶
type Image struct {
// Metadata contains select image attributes
Metadata Metadata
// Layers contains the rich layer objects in build order
Layers []*Layer
// FileCatalog contains all file metadata for all files in all layers
FileCatalog FileCatalogReader
SquashedSearchContext filetree.Searcher
// contains filtered or unexported fields
}
Image represents a container image.
func New ¶
func New(image v1.Image, tmpDirGen *file.TempDirGenerator, contentCacheDir string, additionalMetadata ...AdditionalMetadata) *Image
New provides a new (unread) image object.
func NewImage
deprecated
func NewImage(image v1.Image, tmpDirGen *file.TempDirGenerator, contentCacheDir string, additionalMetadata ...AdditionalMetadata) *Image
NewImage provides a new (unread) image object.
Deprecated: use New() instead
func (*Image) Cleanup ¶
Cleanup removes all temporary files created from parsing the image. Future calls to image will not function correctly after this call.
func (*Image) FileContentsByRef
deprecated
func (*Image) FileContentsFromSquash
deprecated
func (*Image) FilesByMIMETypeFromSquash
deprecated
func (*Image) OpenPathFromSquash ¶
OpenPathFromSquash fetches file contents for a single path, relative to the image squash tree. If the path does not exist an error is returned.
func (*Image) OpenReference ¶
OpenReference fetches file contents for a single file reference, regardless of the source layer. If the path does not exist an error is returned.
func (*Image) Read ¶
Read parses information from the underlying image tar into this struct. This includes image metadata, layer metadata, layer file trees, and layer squash trees (which implies the image squash tree). Under WithLazyLayerSquashes only the top layer's squash, the image squash, is built here, and every lower layer's squash is built the first time something uses it.
The context bounds the read: cancelling it abandons work that has not started and stops the layer pools from picking up more. It does not return until the layer work already in flight has finished, so nothing it releases on the way out is still being written to - neither the layers themselves nor i.Metadata, which the index stage accumulates into.
How long that wait is depends on the source. A registry fetch aborts with the caller's context, but a daemon or archive fetch reads a local tar through go-containerregistry, which takes no context, and indexing a layer is never interruptible. So a cancelled read costs up to one fetch plus one index per in-flight worker slot, plus the one layer squash in progress.
func (*Image) ResolveLinkByImageSquash ¶
func (i *Image) ResolveLinkByImageSquash(ref file.Reference, options ...filetree.LinkResolutionOption) (*file.Resolution, error)
ResolveLinkByImageSquash resolves a symlink for the given file reference relative to the result from the image squash. If the given file reference is not a link type it resolves to itself. A dead link, or a link that is malformed in the image (a cycle, or a chain too deep to follow), resolves to nil with a nil error, see ResolveLinkByLayerSquash.
func (*Image) ResolveLinkByLayerSquash ¶
func (i *Image) ResolveLinkByLayerSquash(ref file.Reference, layer int, options ...filetree.LinkResolutionOption) (*file.Resolution, error)
ResolveLinkByLayerSquash resolves a symlink for the given file reference relative to the result from the layer squash of the given layer index argument. If the given file reference is not a link type it resolves to itself. A dead link, or a link that is malformed in the image (a cycle, or a chain too deep to follow), resolves to nil with a nil error: callers are resolving one file out of many and one bad link should not fail the whole set.
func (*Image) SquashedTree ¶
SquashedTree returns the pre-computed image squash file tree.
type Layer ¶
type Layer struct {
// Metadata contains select layer attributes
Metadata LayerMetadata
// Tree is a filetree that represents the structure of the layer tar contents ("diff tree"). It keeps this
// layer's whiteout entries, since a merge reads them off the upper tree to know what to remove.
Tree filetree.Reader
// SquashedTree is a filetree that represents the combination of this layers diff tree and all diff trees
// in lower layers relative to this one. It never contains whiteout entries: those are changeset metadata
// and do not materialize as files in an applied rootfs. It is set for every layer once the image is read.
// Below the top layer of an image read with WithLazyLayerSquashes it is built on first use, so it is
// not a *filetree.FileTree and its first call can take a while (see WithLazyLayerSquashes).
SquashedTree filetree.Reader
// SquashedSearchContext searches SquashedTree. Over a lazy SquashedTree it is lazy too: neither the tree
// nor the search context's link index is built until the first search.
SquashedSearchContext filetree.Searcher
SearchContext filetree.Searcher
// contains filtered or unexported fields
}
Layer represents a single layer within a container image.
func (*Layer) FileContents
deprecated
FileContents reads the file contents for the given path from the underlying layer blob, relative to the layers "diff tree". An error is returned if there is no file at the given path and layer or the read operation cannot continue.
Deprecated: use OpenPath() instead.
func (*Layer) FileContentsFromSquash
deprecated
FileContentsFromSquash reads the file contents for the given path from the underlying layer blob, relative to the layers squashed file tree. An error is returned if there is no file at the given path and layer or the read operation cannot continue.
Deprecated: use OpenPathFromSquash() instead.
func (*Layer) FilesByMIMEType
deprecated
func (*Layer) FilesByMIMETypeFromSquash
deprecated
FilesByMIMETypeFromSquash returns file references for files that match at least one of the given MIME types relative to the squashed file tree representation.
Deprecated: use SquashedSearchContext().SearchByMIMEType() instead.
func (*Layer) OpenPath ¶
OpenPath reads the file contents for the given path from the underlying layer blob, relative to the layers "diff tree". An error is returned if there is no file at the given path and layer or the read operation cannot continue.
func (*Layer) OpenPathFromSquash ¶
OpenPathFromSquash reads the file contents for the given path from the underlying layer blob, relative to the layers squashed file tree. An error is returned if there is no file at the given path and layer or the read operation cannot continue.
type LayerMetadata ¶
type LayerMetadata struct {
Index uint
// Digest is the layer's diff ID: the sha256 of the uncompressed layer contents. Taken from the
// image config's rootfs.diff_ids when it lists exactly one per layer (as ggcr itself does for
// registry and docker images), otherwise computed from the layer. It is what the image claims
// about its contents, not a verification of them.
Digest string
MediaType v1Types.MediaType
// Size in bytes of the layer content size
Size int64
}
LayerMetadata represents container layer metadata.
type Metadata ¶
type Metadata struct {
// ID is the sha256 of this image config json (not manifest)
ID string
// Size in bytes of all the image layer content sizes (does not include config / manifest / index metadata sizes)
Size int64
Config v1.ConfigFile
MediaType v1Types.MediaType
// --- below fields are optional metadata
Tags []name.Tag
RawManifest []byte
ManifestDigest string
RawConfig []byte
RepoDigests []string
Architecture string
Variant string
OS string
}
Metadata represents container image metadata.
type Platform ¶
type Platform struct {
// Architecture field specifies the CPU architecture, for example
// `amd64` or `ppc64`.
Architecture string `json:"architecture"`
// OS specifies the operating system, for example `linux` or `windows`.
OS string `json:"os"`
// Variant is an optional field specifying a variant of the CPU, for
// example `v7` to specify ARMv7 when architecture is `arm`.
Variant string `json:"variant,omitempty"`
}
Platform is a subset of the supported fields from specs "github.com/opencontainers/image-spec/specs-go/v1.Platform"
func NewPlatform ¶
type Provider ¶
Provider is an abstraction for any object that provides image objects (e.g. the docker daemon API, a tar file of an OCI image, podman varlink API, etc.).
type RegistryCredentials ¶
type RegistryCredentials struct {
Authority string
Username string
Password string
Token string
// Explicitly pass in the Authenticator, allowing for things like
// k8schain to be passed through explicitly.
Authenticator authn.Authenticator
// MTLS configuration
ClientCert string
ClientKey string
}
RegistryCredentials contains any information necessary to authenticate against an OCI-distribution-compliant registry (either with basic auth, or bearer token, or ggcr authenticator implementation). Note: only valid for the OCI registry provider.
type RegistryOptions ¶
type RegistryOptions struct {
InsecureSkipTLSVerify bool
InsecureUseHTTP bool
Credentials []RegistryCredentials
Keychain authn.Keychain
CAFileOrDir string
// DisableBlobResume turns off resuming a registry blob download from where it stopped when the
// connection drops partway through, so the layer fails outright instead. Resuming is on by
// default, and applies to the OCI registry provider only. It also turns off what comes with it:
// a read that receives nothing for two minutes is treated as a drop, and the first resume of a
// pull pings and authenticates against the registry again.
//
// The idle clock is the part worth knowing, since it is the one piece that changes a pull which
// previously only ran slowly: a registry that pauses longer than that mid-blob is reopened rather
// than waited on. One that then ignores the range costs a re-download of what had already
// arrived, and one that refuses it outright (a 416, say) fails the layer where waiting would have
// finished it. Two minutes is picked to sit well above a pull-through cache filling from upstream.
//
// Note that this is a Go API only: syft, grype and anchorectl would each need to plumb a config
// key through before an operator meeting such a registry could reach it.
DisableBlobResume bool
}
RegistryOptions for the OCI registry provider and containerd provider. If no specific Credential is found in the RegistryCredentials, will check for Keychain, and barring that will use Default Keychain.
func (RegistryOptions) Authenticator ¶
func (r RegistryOptions) Authenticator(registry string) authn.Authenticator
Authenticator selects the credentials used to authenticate with a registry. Returns an authn.Authenticator object capable for handling high level credentials for the registry.
type Source ¶
type Source = string
const ( UnknownSource Source = "" ContainerdDaemonSource Source = "containerd" ContainersStorageSource Source = "containers-storage" DockerTarballSource Source = "docker-archive" DockerDaemonSource Source = "docker" OciDirectorySource Source = "oci-dir" OciTarballSource Source = "oci-archive" OciRegistrySource Source = "oci-registry" PodmanDaemonSource Source = "podman" SingularitySource Source = "singularity" )