registry

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2021 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AnnotationMediaType            = "org.lfedge.eci.mediaType"
	AnnotationRole                 = "org.lfedge.eci.role"
	AnnotationRootPath             = "org.lfedge.eci.artifact.root"
	AnnotationInitrdPath           = "org.lfedge.eci.artifact.initrd"
	AnnotationKernelPath           = "org.lfedge.eci.artifact.kernel"
	AnnotationDiskIndexPathPattern = "org.lfedge.eci.artifact.disk-%d"
	AnnotationOther                = "org.lfedge.eci.other"
)
View Source
const (
	MimeTypeECIConfig           = "application/vnd.lfedge.eci.config.v1+json"
	MimeTypeECIKernel           = "application/vnd.lfedge.eci.kernel.layer.v1+kernel"
	MimeTypeECIInitrd           = "application/vnd.lfedge.eci.initrd.layer.v1+cpio"
	MimeTypeECIDiskRaw          = "application/vnd.lfedge.disk.layer.v1+raw"
	MimeTypeECIDiskVhd          = "application/vnd.lfedge.disk.layer.v1+vhd"
	MimeTypeECIDiskVmdk         = "application/vnd.lfedge.disk.layer.v1+vmdk"
	MimeTypeECIDiskISO          = "application/vnd.lfedge.disk.layer.v1+iso"
	MimeTypeECIDiskQcow         = "application/vnd.lfedge.disk.layer.v1+qcow"
	MimeTypeECIDiskQcow2        = "application/vnd.lfedge.disk.layer.v1+qcow2"
	MimeTypeECIDiskOva          = "application/vnd.lfedge.disk.layer.v1+ova"
	MimeTypeECIDiskVhdx         = "application/vnd.lfedge.disk.layer.v1+vhdx"
	MimeTypeECIOther            = "application/vnd.lfedge.eci.layer.v1"
	MimeTypeOCIImageConfig      = ocispec.MediaTypeImageConfig
	MimeTypeOCIImageLayer       = ocispec.MediaTypeImageLayer
	MimeTypeOCIImageLayerGzip   = ocispec.MediaTypeImageLayerGzip
	MimeTypeOCIImageManifest    = ocispec.MediaTypeImageManifest
	MimeTypeOCIImageIndex       = ocispec.MediaTypeImageIndex
	MimeTypeDockerImageConfig   = images.MediaTypeDockerSchema2Config
	MimeTypeDockerImageManifest = images.MediaTypeDockerSchema2Manifest
	MimeTypeDockerImageIndex    = images.MediaTypeDockerSchema2ManifestList
	MimeTypeDockerLayerTarGzip  = images.MediaTypeDockerSchema2LayerGzip
	MimeTypeDockerLayerTar      = images.MediaTypeDockerSchema2Layer
)
View Source
const (
	DefaultAuthor = "lf-edge/edge-containers"
	DefaultOS     = runtime.GOOS
	DefaultArch   = runtime.GOARCH
)
View Source
const (
	RoleKernel         = "kernel"
	RoleInitrd         = "initrd"
	RoleRootDisk       = "disk-root"
	RoleAdditionalDisk = "disk-additional"
)

Variables

View Source
var MimeToType = map[string]DiskType{
	MimeTypeECIDiskRaw:   Raw,
	MimeTypeECIDiskVhd:   Vhd,
	MimeTypeECIDiskVmdk:  Vmdk,
	MimeTypeECIDiskISO:   ISO,
	MimeTypeECIDiskQcow:  Qcow,
	MimeTypeECIDiskQcow2: Qcow2,
	MimeTypeECIDiskOva:   Ova,
	MimeTypeECIDiskVhdx:  Vhdx,
}
View Source
var NameToType = map[string]DiskType{
	"raw":   Raw,
	"vmdk":  Vmdk,
	"vhd":   Vhd,
	"iso":   ISO,
	"qcow":  Qcow,
	"qcow2": Qcow2,
	"ova":   Ova,
	"vhdx":  Vhdx,
}

Functions

func AllMimeTypes

func AllMimeTypes() []string

func GetConfigMediaType

func GetConfigMediaType(actualType string, format Format) string

func GetLayerMediaType

func GetLayerMediaType(actualType string, format Format) string

func IsConfigType

func IsConfigType(mediaType string) bool

Types

type Artifact

type Artifact struct {
	// Kernel path to the kernel file
	Kernel Source
	// Initrd path to the initrd file
	Initrd Source
	// Config path to the config
	Config Source
	// Root path to the root disk and its type
	Root *Disk
	// Disks paths and types for additional disks
	Disks []*Disk
	// Other other items that did not have appropriate annotations
	Other []Source
}

func (Artifact) Manifest

func (a Artifact) Manifest(format Format, configOpts ConfigOpts, legacyOpts ...LegacyOpt) (*ocispec.Manifest, ctrcontent.Provider, error)

Manifest create the manifest for the given Artifact.

type ConfigOpts

type ConfigOpts struct {
	Author       string
	OS           string
	Architecture string
}

type DirTarget

type DirTarget struct {
	Dir string
}

DirTarget save the entire contents to a single directory.

func (DirTarget) Ingester

func (d DirTarget) Ingester() IngesterCloser

Ingester get the IngesterCloser

func (DirTarget) MultiWriter

func (d DirTarget) MultiWriter() bool

MultiWriter does this support multiwriter

type Disk

type Disk struct {
	Source Source
	Type   DiskType
}

type DiskType

type DiskType int
const (
	Raw DiskType = iota
	Vmdk
	Vhd
	ISO
	Qcow
	Qcow2
	Ova
	Vhdx
)

func (DiskType) String

func (d DiskType) String() string

type FileSource

type FileSource struct {
	// Path path to the file source
	Path string
}

FileSource implements a Source for a file

func (*FileSource) GetContent

func (f *FileSource) GetContent() []byte

func (*FileSource) GetDigest

func (f *FileSource) GetDigest() string

func (*FileSource) GetName

func (f *FileSource) GetName() string

func (*FileSource) GetPath

func (f *FileSource) GetPath() string

func (*FileSource) GetSize

func (f *FileSource) GetSize() int64

type FilesTarget

type FilesTarget struct {
	// Kernel writer where to write the kernel
	Kernel io.Writer
	// Initrd writer where to write the initrd
	Initrd io.Writer
	// Config writer where to write the config
	Config io.Writer
	// Root writer where to write the root disk
	Root io.Writer
	// Disks writers where to write each additional disk
	Disks []io.Writer
	// Other writer where to write the other elements
	Other []io.Writer
	// BlockSize how big a blocksize to use when reading/writing. Defaults to whatever io.Copy uses
	BlockSize int
	// AcceptHash if set to true, accept the hash in the descriptor as is, i.e. do not recalculate it
	AcceptHash bool
	// contains filtered or unexported fields
}

FilesTarget provides targets for each file type. If a type is nil, its content is ignored

func (*FilesTarget) Close

func (f *FilesTarget) Close() error

Close close anything that might be open

func (*FilesTarget) Ingester

func (f *FilesTarget) Ingester() IngesterCloser

Ingester get the IngesterCloser

func (*FilesTarget) MultiWriter

func (f *FilesTarget) MultiWriter() bool

MultiWriter does this support multiwriter

func (*FilesTarget) Writer

Writer get a writer

func (*FilesTarget) Writers

func (f *FilesTarget) Writers(ctx context.Context, opts ...ctrcontent.WriterOpt) (func(name string) (ctrcontent.Writer, error), error)

Writers get writers by filename

type Format

type Format int
const (
	FormatArtifacts Format = iota
	FormatLegacy
)

type HashSource

type HashSource struct {
	// Hash the sha256 hash
	Hash string
	// Name of file to save
	Name string
	// Size size of the target
	Size int64
}

HashSource implements a source that has the hash directly, to enable creating a raw manifest

func (*HashSource) GetContent

func (h *HashSource) GetContent() []byte

func (*HashSource) GetDigest

func (h *HashSource) GetDigest() string

func (*HashSource) GetName

func (h *HashSource) GetName() string

func (*HashSource) GetPath

func (h *HashSource) GetPath() string

func (*HashSource) GetSize

func (h *HashSource) GetSize() int64

type IngesterCloser

type IngesterCloser interface {
	ctrcontent.Ingester
	io.Closer
}

IngesterCloser an ingester that also has a Close(). May return nil

type LegacyOpt

type LegacyOpt func(*legacyInfo)

func WithTimestamp

func WithTimestamp(timestamp *time.Time) LegacyOpt

WithTimestamp sets the timestamp to use for each file's tar header, else uses current time

func WithTmpDir

func WithTmpDir(dir string) LegacyOpt

WithTmpDir sets the temporary directory to use for tar/gzip the files. It is up to the caller to clean it up when done.

type MemorySource

type MemorySource struct {
	// Content the data
	Content []byte
	// Name of file to save
	Name string
}

MemorySource implements a Source for raw data

func (*MemorySource) GetContent

func (m *MemorySource) GetContent() []byte

func (*MemorySource) GetDigest

func (m *MemorySource) GetDigest() string

func (*MemorySource) GetName

func (m *MemorySource) GetName() string

func (*MemorySource) GetPath

func (m *MemorySource) GetPath() string

func (*MemorySource) GetSize

func (m *MemorySource) GetSize() int64

type Puller

type Puller struct {
	// Image reference to image, e.g. docker.io/foo/bar:tagabc
	Image string
	// Impl the OCI artifacts puller. Normally should be left blank, will be filled in to use oras. Override only for special cases like testing.
	Impl func(ctx context.Context, resolver remotes.Resolver, ref string, ingester ctrcontent.Ingester, opts ...oras.PullOpt) (ocispec.Descriptor, []ocispec.Descriptor, error)
}

func (*Puller) Config

func (p *Puller) Config(verbose bool, writer io.Writer, resolver ecresolver.ResolverCloser) (*ocispec.Descriptor, *ocispec.Image, error)

Config pull the config for the artifact from the appropriate registry and return it as an object

The resolver provides the channel to connect to the target type. resolver.Registry just uses the default registry, while resolver.Directory uses a local directory, etc.

func (*Puller) Pull

func (p *Puller) Pull(target Target, blocksize int, verbose bool, writer io.Writer, resolver ecresolver.ResolverCloser) (*ocispec.Descriptor, *Artifact, error)

Pull pull the artifact from the appropriate registry and save it to a local directory. Arguments are the dir where to write it, an io.Writer for logging output, and a target.

The resolver provides the channel to connect to the target type. resolver.Registry just uses the default registry, while resolver.Directory uses a local directory, etc.

type Pusher

type Pusher struct {
	// Artifact artifact to push
	Artifact *Artifact
	// Image reference to image, e.g. docker.io/foo/bar:tagabc
	Image string
	// Timestamp set any files to have this timestamp, instead of the default of the file time
	Timestamp *time.Time
	// Impl the OCI artifacts pusher. Normally should be left blank, will be filled in to use oras. Override only for special cases like testing.
	Impl func(ctx context.Context, resolver remotes.Resolver, ref string, provider ctrcontent.Provider, descriptors []ocispec.Descriptor, opts ...oras.PushOpt) (ocispec.Descriptor, error)
}

func (Pusher) Push

func (p Pusher) Push(format Format, verbose bool, writer io.Writer, configOpts ConfigOpts, resolver ecresolver.ResolverCloser) (string, error)

Push push the artifact to the appropriate registry. Arguments are the format to write, an io.Writer for sending debug output, ConfigOpts to configure how the image should be configured, and a target.

The target determines the target type. target.Registry just uses the default registry, while target.Directory uses a local directory.

type Source

type Source interface {
	// GetPath get path to a file, returns "" if no file
	GetPath() string
	// GetContent get the actual content if in memory, returns nil if in a file
	GetContent() []byte
	// GetName returns the target filename
	GetName() string
	// GetDigest returns the digest if provided directly; will not calculate for other sources.
	// Format is "sha256:<hash>"
	GetDigest() string
	// GetSize returns the size if provided directly; will not calculate for other sources.
	GetSize() int64
}

Source a source for an artifact component

type Target

type Target interface {
	Ingester() IngesterCloser
	MultiWriter() bool
}

Target a target where to send the contents of the artifact. May also handle processing config.

Jump to

Keyboard shortcuts

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