snapshot

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package snapshot pushes and pulls cocoon VM snapshots as OCI artifacts. Push streams from `cocoon snapshot export`; pull writes to `cocoon snapshot import`.

Index

Constants

View Source
const (
	// CocoonBinaryEnv is the env var that overrides the cocoon binary path.
	CocoonBinaryEnv = "EPOCH_COCOON_BINARY"
)

Variables

This section is empty.

Functions

func FetchSnapshotConfig

func FetchSnapshotConfig(ctx context.Context, dl Downloader, name string, desc manifest.Descriptor) (*manifest.SnapshotConfig, error)

FetchSnapshotConfig downloads and parses the snapshot config blob.

func ResolveCocoonBinary

func ResolveCocoonBinary(envValue string) (string, error)

ResolveCocoonBinary finds the cocoon binary on PATH.

func Stream

func Stream(ctx context.Context, raw []byte, dl Downloader, opts StreamOptions) error

Stream reassembles a snapshot manifest into a cocoon-import tar stream.

func StreamParsed

func StreamParsed(ctx context.Context, m *manifest.OCIManifest, dl Downloader, opts StreamOptions) error

StreamParsed accepts an already-parsed manifest.

Types

type CocoonRunner

type CocoonRunner interface {
	Export(ctx context.Context, name string) (io.ReadCloser, func() error, error)
	Import(ctx context.Context, opts ImportOptions) (io.WriteCloser, func() error, error)
}

CocoonRunner abstracts the local `cocoon` CLI. Default is ExecCocoon; tests substitute a fake.

type Downloader

type Downloader interface {
	GetManifest(ctx context.Context, name, tag string) ([]byte, string, error)
	GetBlob(ctx context.Context, name, digest string) (io.ReadCloser, error)
}

Downloader abstracts OCI manifest and blob downloads.

type ExecCocoon

type ExecCocoon struct {
	Binary string
	Stderr io.Writer
}

ExecCocoon runs the cocoon binary as a subprocess.

func (*ExecCocoon) Export

func (e *ExecCocoon) Export(ctx context.Context, name string) (io.ReadCloser, func() error, error)

Export streams a snapshot out of cocoon via `cocoon snapshot export`.

func (*ExecCocoon) ImageImport

func (e *ExecCocoon) ImageImport(ctx context.Context, name string) (io.WriteCloser, func() error, error)

ImageImport starts a `cocoon image import` subprocess accepting data on stdin.

func (*ExecCocoon) Import

func (e *ExecCocoon) Import(ctx context.Context, opts ImportOptions) (io.WriteCloser, func() error, error)

Import starts a `cocoon snapshot import` subprocess accepting tar on stdin.

type ImportOptions

type ImportOptions struct {
	Name        string
	Description string
}

ImportOptions configures a cocoon snapshot import invocation.

type PullOptions

type PullOptions struct {
	Name        string
	Tag         string
	LocalName   string // overrides cocoon-side snapshot name; empty = use Name
	Description string
	Progress    func(string)
}

PullOptions configures a snapshot pull operation.

type Puller

type Puller struct {
	Downloader Downloader
	Cocoon     CocoonRunner
}

Puller downloads snapshot artifacts and pipes them into cocoon snapshot import.

func (*Puller) Pull

func (p *Puller) Pull(ctx context.Context, opts PullOptions) error

Pull downloads a snapshot artifact and feeds it to `cocoon snapshot import`.

type PushOptions

type PushOptions struct {
	Name      string
	Tag       string
	BaseImage string // optional cocoonstack.snapshot.baseimage annotation
	Source    string
	Revision  string
	Progress  func(string)
}

PushOptions configures a snapshot push operation.

type PushResult

type PushResult struct {
	Name           string
	Tag            string
	ManifestDigest string // sha256:<hex>
	ManifestBytes  []byte
	TotalSize      int64
	LayerCount     int
}

PushResult contains the outcome of a successful push.

type Pusher

type Pusher struct {
	Uploader Uploader
	Cocoon   CocoonRunner
}

Pusher exports and uploads cocoon snapshots as OCI artifacts.

func (*Pusher) Push

func (p *Pusher) Push(ctx context.Context, opts PushOptions) (*PushResult, error)

Push exports a snapshot via cocoon and uploads it as an OCI artifact.

type StreamOptions

type StreamOptions struct {
	Name      string
	LocalName string // empty = use Name
	Writer    io.Writer
	Progress  func(string)
}

StreamOptions configures snapshot tar stream assembly.

type Uploader

type Uploader interface {
	BlobExists(ctx context.Context, name, digest string) (bool, error)
	PutBlob(ctx context.Context, name, digest string, body io.Reader, size int64) error
	PutManifest(ctx context.Context, name, tag string, data []byte, contentType string) error
}

Uploader abstracts OCI blob and manifest uploads.

Jump to

Keyboard shortcuts

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