docker

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2024 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	FlyteSandboxConfigDir          = f.FilePathJoin(f.UserHomeDir(), ".flyte", "sandbox")
	Kubeconfig                     = f.FilePathJoin(FlyteSandboxConfigDir, "kubeconfig")
	SandboxKubeconfig              = f.FilePathJoin(f.UserHomeDir(), ".flyte", "k3s", "k3s.yaml")
	SuccessMessage                 = "Deploying Flyte..."
	FlyteSandboxClusterName        = "flyte-sandbox"
	FlyteSandboxVolumeName         = "flyte-sandbox"
	FlyteSandboxInternalDir        = "/var/lib/flyte"
	FlyteSandboxInternalConfigDir  = f.FilePathJoin(FlyteSandboxInternalDir, "config")
	FlyteSandboxInternalStorageDir = f.FilePathJoin(FlyteSandboxInternalDir, "storage")
	Environment                    = []string{"SANDBOX=1", "KUBERNETES_API_PORT=30086", "FLYTE_HOST=localhost:30081", "FLYTE_AWS_ENDPOINT=http://localhost:30084"}
	Source                         = "/root"
	K3sDir                         = "/etc/rancher/"
	Client                         Docker
	Volumes                        = []mount.Mount{
		{
			Type:   mount.TypeBind,
			Source: f.FilePathJoin(f.UserHomeDir(), ".flyte"),
			Target: K3sDir,
		},
	}
	ExecConfig = types.ExecConfig{
		AttachStderr: true,
		Tty:          true,
		WorkingDir:   "/",
		AttachStdout: true,
		Cmd:          []string{},
	}
	StdWriterPrefixLen = 8
	StartingBufLen     = 32*1024 + StdWriterPrefixLen + 1
	ExtraHosts         = []string{"host.docker.internal:host-gateway"}
)
View Source
var (
	DefaultConfig = &Config{
		Force: false,
	}
)

Config holds configuration flags for docker command.

Functions

func CopyContainerFile

func CopyContainerFile(ctx context.Context, cli Docker, source, destination, name, image string) error

CopyContainerFile try to create the container, see if the source file is there, copy it to the destination

func ExecCommend

func ExecCommend(ctx context.Context, cli Docker, containerID string, command []string) (types.IDResponse, error)

ExecCommend will execute a command in container and returns an execution id

func GetDemoPorts

func GetDemoPorts() (map[nat.Port]struct{}, map[nat.Port][]nat.PortBinding, error)

GetDemoPorts will return demo ports

func GetDevPorts

func GetDevPorts() (map[nat.Port]struct{}, map[nat.Port][]nat.PortBinding, error)

GetDevPorts will return dev cluster (minio + postgres) ports

func GetOrCreateVolume

func GetOrCreateVolume(
	ctx context.Context, cli Docker, volumeName string, dryRun bool,
) (*volume.Volume, error)

func GetSandbox

func GetSandbox(ctx context.Context, cli Docker) (*types.Container, error)

GetSandbox will return sandbox container if it exist

func GetSandboxPorts

func GetSandboxPorts() (map[nat.Port]struct{}, map[nat.Port][]nat.PortBinding, error)

GetSandboxPorts will return sandbox ports

func InspectExecResp

func InspectExecResp(ctx context.Context, cli Docker, containerID string) error

func PrintCreateContainer

func PrintCreateContainer(volumes []mount.Mount, portBindings map[nat.Port][]nat.PortBinding, name, image string, environment []string)

PrintCreateContainer helper function to print the docker command to run

func PrintCreateVolume

func PrintCreateVolume(name string)

func PrintPullImage

func PrintPullImage(image string, pullOptions ImagePullOptions)

PrintPullImage helper function to print the sandbox pull image command

func PrintRemoveContainer

func PrintRemoveContainer(name string)

PrintRemoveContainer helper function to remove sandbox container

func PullDockerImage

func PullDockerImage(ctx context.Context, cli Docker, image string, pullPolicy ImagePullPolicy,
	imagePullOptions ImagePullOptions, dryRun bool) error

PullDockerImage will Pull docker image

func ReadLogs

func ReadLogs(ctx context.Context, cli Docker, id string) (*bufio.Scanner, error)

ReadLogs will return io scanner for reading the logs of a container

func RemoveSandbox

func RemoveSandbox(ctx context.Context, cli Docker, reader io.Reader) error

RemoveSandbox will remove sandbox container if exist

func StartContainer

func StartContainer(ctx context.Context, cli Docker, volumes []mount.Mount, exposedPorts map[nat.Port]struct{},
	portBindings map[nat.Port][]nat.PortBinding, name, image string, additionalEnvVars []string, dryRun bool) (string, error)

StartContainer will create and start docker container

func WaitForSandbox

func WaitForSandbox(reader *bufio.Scanner, message string) bool

WaitForSandbox will wait until it doesn't get success message

Types

type Config

type Config struct {
	Force bool `json:"force" pflag:",Optional. Forcefully delete existing sandbox cluster if it exists."`
}

type Docker

type Docker interface {
	ContainerCreate(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, platform *ocispec.Platform, containerName string) (container.CreateResponse, error)
	ContainerStart(ctx context.Context, containerID string, options container.StartOptions) error
	ImagePull(ctx context.Context, refStr string, options types.ImagePullOptions) (io.ReadCloser, error)
	ContainerWait(ctx context.Context, container string, condition container.WaitCondition) (<-chan container.WaitResponse, <-chan error)
	ContainerLogs(ctx context.Context, container string, options container.LogsOptions) (io.ReadCloser, error)
	ContainerRemove(ctx context.Context, containerID string, options container.RemoveOptions) error
	ContainerList(ctx context.Context, options container.ListOptions) ([]types.Container, error)
	ContainerExecCreate(ctx context.Context, container string, config types.ExecConfig) (types.IDResponse, error)
	ContainerExecAttach(ctx context.Context, execID string, config types.ExecStartCheck) (types.HijackedResponse, error)
	ContainerExecInspect(ctx context.Context, execID string) (types.ContainerExecInspect, error)
	ImageList(ctx context.Context, listOption types.ImageListOptions) ([]image.Summary, error)
	ContainerStatPath(ctx context.Context, containerID, path string) (types.ContainerPathStat, error)
	CopyFromContainer(ctx context.Context, containerID, srcPath string) (io.ReadCloser, types.ContainerPathStat, error)
	VolumeCreate(ctx context.Context, options volume.CreateOptions) (volume.Volume, error)
	VolumeList(ctx context.Context, options volume.ListOptions) (volume.ListResponse, error)
	VolumeRemove(ctx context.Context, volumeID string, force bool) error
}

func GetDockerClient

func GetDockerClient() (Docker, error)

GetDockerClient will returns the docker client

type FlyteDocker

type FlyteDocker struct {
	*client.Client
}

type ImagePullOptions

type ImagePullOptions struct {
	RegistryAuth string `json:"registryAuth" pflag:",The base64 encoded credentials for the registry."`
	Platform     string `json:"platform" pflag:",Forces a specific platform's image to be pulled.'"`
}

type ImagePullPolicy

type ImagePullPolicy int
const (
	ImagePullPolicyAlways ImagePullPolicy = iota
	ImagePullPolicyIfNotPresent
	ImagePullPolicyNever
)

func ImagePullPolicyString

func ImagePullPolicyString(s string) (ImagePullPolicy, error)

ImagePullPolicyString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func ImagePullPolicyValues

func ImagePullPolicyValues() []ImagePullPolicy

ImagePullPolicyValues returns all values of the enum

func (ImagePullPolicy) IsAImagePullPolicy

func (i ImagePullPolicy) IsAImagePullPolicy() bool

IsAImagePullPolicy returns "true" if the value is listed in the enum definition. "false" otherwise

func (ImagePullPolicy) MarshalJSON

func (i ImagePullPolicy) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for ImagePullPolicy

func (*ImagePullPolicy) Set

func (i *ImagePullPolicy) Set(val string) error

Set implements PFlag's Value interface to attempt to set the value of the flag from string.

func (ImagePullPolicy) String

func (i ImagePullPolicy) String() string

func (ImagePullPolicy) Type

func (i ImagePullPolicy) Type() string

Type implements PFlag's Value interface to return type name.

func (*ImagePullPolicy) UnmarshalJSON

func (i *ImagePullPolicy) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for ImagePullPolicy

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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