docker

package
v0.50.0 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2026 License: Apache-2.0 Imports: 46 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultHost is the standard ipv4 loopback
	DefaultHost = "127.0.0.1"

	// DefaultPort is used as the preferred port, and in the unlikly event of an
	// error querying the OS for a free port during allocation.
	DefaultPort = "8080"

	// DefaultDialTimeout when checking if a port is available.
	DefaultDialTimeout = 2 * time.Second

	// DefaultStopTimeout when attempting to stop underlying containers.
	DefaultStopTimeout = 10 * time.Second
)

Variables

View Source
var ErrNoDocker = errors.New("docker/podman API not available")
View Source
var GetDockerContextHostFunc = getDockerContextHost

GetDockerContextHostFunc is a variable to allow mocking in tests

Functions

func GetPlatformImage

func GetPlatformImage(ref, platform string) (string, error)

GetPlatformImage returns image reference for specific platform. If the image is not multi-arch it returns ref argument directly (provided platform matches). If the image is multi-arch it returns digest based reference (provided the platform is part of the multi-arch image).

func GetRegistry

func GetRegistry(img string) (string, error)

func ParseDigest

func ParseDigest(output string) string

ParseDigest tries to parse the last line from the output, which holds the pushed image digest The output should contain line like this: latest: digest: sha256:a278a91112d17f8bde6b5f802a3317c7c752cf88078dae6f4b5a0784deb81782 size: 2613

Types

type DockerClient added in v0.50.0

type DockerClient interface {
	daemon.Client // Ping, ImageSave, ImageLoad, ImageTag, ImageInspect, ImageHistory

	ContainerAttach(ctx context.Context, container string, options client.ContainerAttachOptions) (client.ContainerAttachResult, error)
	ContainerCommit(ctx context.Context, container string, options client.ContainerCommitOptions) (client.ContainerCommitResult, error)
	ContainerCreate(ctx context.Context, options client.ContainerCreateOptions) (client.ContainerCreateResult, error)
	ContainerInspect(ctx context.Context, containerID string, options client.ContainerInspectOptions) (client.ContainerInspectResult, error)
	ContainerKill(ctx context.Context, containerID string, options client.ContainerKillOptions) (client.ContainerKillResult, error)
	ContainerRemove(ctx context.Context, container string, options client.ContainerRemoveOptions) (client.ContainerRemoveResult, error)
	ContainerStart(ctx context.Context, container string, options client.ContainerStartOptions) (client.ContainerStartResult, error)
	ContainerStop(ctx context.Context, containerID string, options client.ContainerStopOptions) (client.ContainerStopResult, error)
	ContainerWait(ctx context.Context, containerID string, options client.ContainerWaitOptions) client.ContainerWaitResult
	CopyFromContainer(ctx context.Context, containerID string, options client.CopyFromContainerOptions) (client.CopyFromContainerResult, error)
	CopyToContainer(ctx context.Context, container string, options client.CopyToContainerOptions) (client.CopyToContainerResult, error)

	ImageBuild(ctx context.Context, buildContext io.Reader, options client.ImageBuildOptions) (client.ImageBuildResult, error)
	ImagePull(ctx context.Context, ref string, options client.ImagePullOptions) (client.ImagePullResponse, error)
	ImagePush(ctx context.Context, ref string, options client.ImagePushOptions) (client.ImagePushResponse, error)
	ImageRemove(ctx context.Context, image string, options client.ImageRemoveOptions) (client.ImageRemoveResult, error)

	Info(ctx context.Context, options client.InfoOptions) (client.SystemInfoResult, error)
	NetworkCreate(ctx context.Context, name string, options client.NetworkCreateOptions) (client.NetworkCreateResult, error)
	NetworkRemove(ctx context.Context, networkID string, options client.NetworkRemoveOptions) (client.NetworkRemoveResult, error)
	ServerVersion(ctx context.Context, options client.ServerVersionOptions) (client.ServerVersionResult, error)
	VolumeList(ctx context.Context, options client.VolumeListOptions) (client.VolumeListResult, error)
	VolumeRemove(ctx context.Context, volumeID string, options client.VolumeRemoveOptions) (client.VolumeRemoveResult, error)

	Close() error
}

DockerClient is a subset of client.APIClient with only the methods needed by this project and its third-party integrations (pack, s2i).

func NewClient

func NewClient(defaultHost string) (dc DockerClient, dockerHostInRemote string, err error)

NewClient creates a new docker client. reads the DOCKER_HOST envvar but it may or may not return it as dockerHost.

  • For local connection (unix socket and windows named pipe) it returns the DOCKER_HOST directly.
  • For ssh connections it reads the DOCKER_HOST from the ssh remote.
  • For TCP connections it returns "" so it defaults in the remote (note that one should not be use client.DefaultDockerHost in this situation). This is needed beaus of TCP+tls connections.

type ErrNoImage added in v0.47.0

type ErrNoImage struct{}

func (ErrNoImage) Error added in v0.47.0

func (e ErrNoImage) Error() string

type Opt

type Opt func(*Pusher)

func WithCredentialsProvider

func WithCredentialsProvider(cp oci.CredentialsProvider) Opt

func WithInsecure added in v0.50.0

func WithInsecure(insecure bool) Opt

func WithPusherDockerClientFactory

func WithPusherDockerClientFactory(dockerClientFactory PusherDockerClientFactory) Opt

func WithTransport

func WithTransport(transport http.RoundTripper) Opt

func WithVerbose

func WithVerbose(verbose bool) Opt

type Pusher

type Pusher struct {
	// contains filtered or unexported fields
}

Pusher of images from local to remote registry.

func NewPusher

func NewPusher(opts ...Opt) *Pusher

NewPusher creates an instance of a docker-based image pusher.

func (*Pusher) Push

func (n *Pusher) Push(ctx context.Context, f fn.Function) (string, error)

Push the image index of the function.

type PusherDockerClient

type PusherDockerClient interface {
	daemon.Client
	ImagePush(ctx context.Context, ref string, options client.ImagePushOptions) (client.ImagePushResponse, error)
	Close() error
}

PusherDockerClient is sub-interface of client.APIClient required by pusher.

type PusherDockerClientFactory

type PusherDockerClientFactory func() (PusherDockerClient, error)

type Runner

type Runner struct {
	// contains filtered or unexported fields
}

Runner starts and stops functions as local containers.

func NewRunner

func NewRunner(verbose bool, out, errOut io.Writer) *Runner

NewRunner creates an instance of a docker-backed runner.

func (*Runner) Run

func (n *Runner) Run(ctx context.Context, f fn.Function, address string, startTimeout time.Duration) (job *fn.Job, err error)

Run the function.

Jump to

Keyboard shortcuts

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