oci

package
v1.0.0-alpha4 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2017 License: Apache-2.0, CC-BY-SA-4.0 Imports: 12 Imported by: 1,071

Documentation

Overview

Package oci provides basic operations for manipulating OCI images. This package can be used even outside of containerd, and contains some functions not used in containerd itself.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteBlob

func DeleteBlob(img ImageDriver, d digest.Digest) error

DeleteBlob deletes an OCI blob.

func GetBlobReader

func GetBlobReader(img ImageDriver, d digest.Digest) (io.ReadCloser, error)

GetBlobReader returns io.ReadCloser for a blob.

func Init

func Init(img ImageDriver, opts InitOpts) error

Init initializes an OCI image structure. Init calls img.Init, creates `oci-layout`(0444), and creates `index.json`(0644).

func PutManifestDescriptorToIndex

func PutManifestDescriptorToIndex(img ImageDriver, desc spec.Descriptor) error

PutManifestDescriptorToIndex puts a manifest descriptor to the index. If ref name is set and conflicts with the existing descriptors, the old ones are removed.

func ReadBlob

func ReadBlob(img ImageDriver, d digest.Digest) ([]byte, error)

ReadBlob reads an OCI blob.

func ReadImageLayout

func ReadImageLayout(img ImageDriver) (spec.ImageLayout, error)

ReadImageLayout returns the image layout.

func ReadIndex

func ReadIndex(img ImageDriver) (spec.Index, error)

ReadIndex returns the index.

func RemoveManifestDescriptorFromIndex

func RemoveManifestDescriptorFromIndex(img ImageDriver, refName string) error

RemoveManifestDescriptorFromIndex removes the manifest descriptor from the index. Returns nil error when the entry not found.

func WriteBlob

func WriteBlob(img ImageDriver, b []byte) (digest.Digest, error)

WriteBlob writes bytes as an OCI blob and returns its digest using the canonical digest algorithm. If you need to specify certain algorithm, you can use NewBlobWriter(img string, algo digest.Algorithm).

func WriteImageLayout

func WriteImageLayout(img ImageDriver, layout spec.ImageLayout) error

WriteImageLayout writes the image layout.

func WriteIndex

func WriteIndex(img ImageDriver, idx spec.Index) error

WriteIndex writes the index.

func WriteJSONBlob

func WriteJSONBlob(img ImageDriver, x interface{}, mediaType string) (spec.Descriptor, error)

WriteJSONBlob is an utility function that writes x as a JSON blob with the specified media type, and returns the descriptor.

Types

type BlobWriter

type BlobWriter interface {
	// Close is expected to be called after Commit() when commission is needed.
	io.WriteCloser
	// Digest may return empty digest or panics until committed.
	Digest() digest.Digest
	// Commit commits the blob (but no roll-back is guaranteed on an error).
	// size and expected can be zero-value when unknown.
	Commit(size int64, expected digest.Digest) error
}

BlobWriter writes an OCI blob and returns a digest when committed.

func NewBlobWriter

func NewBlobWriter(img ImageDriver, algo digest.Algorithm) (BlobWriter, error)

NewBlobWriter returns a BlobWriter.

type ErrUnexpectedDigest

type ErrUnexpectedDigest struct {
	Expected digest.Digest
	Actual   digest.Digest
}

ErrUnexpectedDigest can be returned from BlobWriter.Commit()

func (ErrUnexpectedDigest) Error

func (e ErrUnexpectedDigest) Error() string

type ErrUnexpectedSize

type ErrUnexpectedSize struct {
	Expected int64
	Actual   int64
}

ErrUnexpectedSize can be returned from BlobWriter.Commit()

func (ErrUnexpectedSize) Error

func (e ErrUnexpectedSize) Error() string

type ImageDriver

type ImageDriver interface {
	Init() error
	Remove(path string) error
	Reader(path string) (io.ReadCloser, error)
	Writer(path string, perm os.FileMode) (io.WriteCloser, error)
	BlobWriter(algo digest.Algorithm) (BlobWriter, error)
}

ImageDriver corresponds to the representation of an image. Path uses os.PathSeparator as the separator. The methods of ImageDriver should only be called from oci package.

func Tar

func Tar(w TarWriter) ImageDriver

Tar is ImageDriver for TAR representation of an OCI image.

type InitOpts

type InitOpts struct {
	// imageLayoutVersion can be an empty string for specifying the default version.
	ImageLayoutVersion string
	// skip creating oci-layout
	SkipCreateImageLayout bool
	// skip creating index.json
	SkipCreateIndex bool
}

type TarWriter

type TarWriter interface {
	io.WriteCloser
	Flush() error
	WriteHeader(hdr *tar.Header) error
}

TarWriter is an interface that is implemented by archive/tar.Writer. (Using an interface allows hooking)

Jump to

Keyboard shortcuts

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