imagemove

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Overview

Package imagemove streams a host-built image from a source Docker host over SSH into a target node's image store and verifies it by image ID.

Index

Constants

View Source
const DefaultSSHPort = 22

DefaultSSHPort is used when the target names no port.

Variables

View Source
var ErrArchiveContent = errors.New("the image archive has no readable config")

ErrArchiveContent is returned when the saved archive carries no readable image config, so its content cannot be verified.

View Source
var ErrTooLarge = errors.New("the image stream passed the size limit")

ErrTooLarge is returned when the stream passes the size bound.

Functions

func SaveCommand

func SaveCommand(ref string) (string, error)

SaveCommand is the only command ever run on the source host.

func ValidateImageID

func ValidateImageID(id string) error

ValidateImageID accepts a full sha256 image ID as `docker inspect` prints it.

func ValidateImageRef

func ValidateImageRef(ref string) error

ValidateImageRef accepts a plain repository reference with an optional tag. Digests, uppercase names and anything that could act as a remote shell token or a command line option are refused.

Types

type ArchiveInfo

type ArchiveInfo struct {
	// ConfigDigest is the sha256 of the image config blob, which is the
	// image ID on a classic (overlay2) image store.
	ConfigDigest string
	DiffIDs      []string
}

ArchiveInfo is what a streamed `docker save` archive says about its image.

type Credentials

type Credentials struct {
	PrivateKey []byte
	Passphrase []byte
	// UseAgent signs with the control plane process's SSH agent (SSH_AUTH_SOCK).
	UseAgent bool
}

Credentials authenticate to the source host. They are held in memory only.

type HostKeys

type HostKeys struct {
	Path string
	// contains filtered or unexported fields
}

HostKeys pins each source host's key on first use, the in-process equivalent of StrictHostKeyChecking=accept-new. Path "" pins in memory.

func (*HostKeys) Callback

func (h *HostKeys) Callback(hostname string, remote net.Addr, key ssh.PublicKey) error

Callback checks key against the pinned one, recording it when unknown.

type Request

type Request struct {
	Ref string
	// WantID is the source image ID; "" means the load cannot be verified.
	WantID   string
	MaxBytes int64
	Progress func(bytes int64)
}

Request is one image to move.

type Result

type Result struct {
	Bytes    int64
	LoadedID string
	// AlreadyPresent is true when the target already had the exact image.
	AlreadyPresent bool
	Verified       bool
	// ConfigDigest is the sha256 of the streamed image config.
	ConfigDigest string
}

Result reports what a transfer did.

func Transfer

func Transfer(ctx context.Context, src Saver, dst Runtime, req Request) (Result, error)

Transfer moves one image and verifies it by content: the loaded image's layers must equal the streamed config's diff IDs, and a source image ID must match the config digest (classic store) or the loaded ID (same store). It skips the stream when the target already holds the same image ID, so a re-run resumes instead of re-copying.

type Runtime

Runtime is the target node surface a transfer needs.

type SSHSaver

type SSHSaver struct {
	Target      Target
	Creds       Credentials
	HostKeys    *HostKeys
	DialTimeout time.Duration
}

SSHSaver runs the fixed save command over an in-process SSH client: no shell or ssh binary runs on this side, and no prompt can ever block.

func (*SSHSaver) Save

func (s *SSHSaver) Save(ctx context.Context, ref string) (io.ReadCloser, error)

Save starts `docker save ref` on the source. Close waits for the remote command and reports its failure with the tail of its stderr.

type Saver

type Saver interface {
	Save(ctx context.Context, ref string) (io.ReadCloser, error)
}

Saver streams `docker save` of one image from the source host.

type Target

type Target struct {
	User string `json:"user"`
	Host string `json:"host"`
	Port int    `json:"port"`
}

Target is a validated SSH login on the source host.

func ParseTarget

func ParseTarget(s string, port int) (Target, error)

ParseTarget parses user@host, user@host:port or user@[ipv6]:port. A non-zero port argument is used when the string names none, and must agree with it when it does.

func (Target) Addr

func (t Target) Addr() string

Addr is the host:port to dial.

func (Target) String

func (t Target) String() string

String renders the target as user@host:port.

Jump to

Keyboard shortcuts

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