app

package
v3.16.4 Latest Latest
Warning

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

Go to latest
Published: May 7, 2024 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StartPhaseStartup = iota
	StartPhaseInitPlugins
	StartPhaseInitManager
	StartPhaseEventBeforeInstance
	StartPhaseEventWithInstance
	StartPhaseInstanceRunning
	StartPhaseEventAfterInstance
	StartPhaseShutdown
)

The order here *must* match the actual order that things are started

Variables

View Source
var (
	// ErrNoSuchInstance is an error used when the requested instance does not exist
	ErrNoSuchInstance = errors.New("No such instance")
	// ErrSingleInstanceArg is an error used when the wrong number of instances is provided
	ErrSingleInstanceArg = errors.New("Must provide a single instance as the first argument")
	// ErrFailedToAddPluginFlags is an error used when adding flags for a plugin fails
	ErrFailedToAddPluginFlags = errors.New("Failed to add flags from plugin")
	// ErrNotInContainer is an error used when the process is not executed in a container when it should be
	ErrNotInContainer = errors.New("Not in Docker container")
	// ErrFailedEventPlugin is an error used when a plugin fails to execute properly
	ErrFailedEventPlugin = errors.New("Failed to execute event plugin")
)
View Source
var DockerClient *docker.Client

DockerClient holds a reference to a client for interacting with docker

Functions

func DockerCopy

func DockerCopy(instance *iscenv.ISCInstance, instancePath, localPath string) error

DockerCopy will copy a file from inside an instance to a local path

func DockerExec

func DockerExec(instance *iscenv.ISCInstance, interactive bool, username string, commandAndArgs ...string) error

DockerExec performs a docker exec against the provided instance

func DockerLogs

func DockerLogs(instance *iscenv.ISCInstance, since int64, tail string, follow bool, outputStream io.Writer) error

DockerLogs will retrieve logs from a docker container If follow is true, the logs will be followed since is the unix time from which logs should be retrieved tail is the string value to pass to docker to determine the number of lines to tail. It should be either "all" or a string representation of the number of lines. Will return any error encountered

func DockerPort

func DockerPort(port iscenv.ContainerPort) docker.Port

DockerPort creates and returns a container docker port

func DockerPortBinding

func DockerPortBinding(port int64, portOffset int64) []docker.PortBinding

DockerPortBinding returns a slice of PortBindings representing the binding between a container port and a host port based on the offset

func DockerPull

func DockerPull(image, tag string) error

DockerPull performs a docker pull of the requested image at the designated tag

func DockerRemove

func DockerRemove(instance *iscenv.ISCInstance) error

DockerRemove removes the container that backs the provided instance

func DockerRepoLogger

func DockerRepoLogger(repo string) *log.Entry

DockerRepoLogger creates and returns a logger with a reference to the provided docker repository

func DockerStart

func DockerStart(opts DockerStartOptions) (id string, err error)

DockerStart ensures that a container exists and is started. Returns the ID of the started container or an error

func EnsureWithinContainer

func EnsureWithinContainer(commandName string) error

EnsureWithinContainer returns an error if it is executed from outside a container

func ErrorLogger

func ErrorLogger(logger log.FieldLogger, err error) *log.Entry

ErrorLogger will evaluate an error for known error types and return a logger with the appropriate fields pulled from that type of error.

func FileExists

func FileExists(path string) bool

FileExists returns whether the path described by the provided string exists

func FindInstance

func FindInstance(instanceName string) *iscenv.ISCInstance

FindInstance finds and returns the instance with the provided name

func FindInstanceAndLogger

func FindInstanceAndLogger(instanceName string) (*iscenv.ISCInstance, *log.Entry)

FindInstanceAndLogger finds and returns the instance with the provided name and a logger for that instance

func GetContainerForInstance

func GetContainerForInstance(instance *iscenv.ISCInstance) (*docker.Container, error)

GetContainerForInstance finds and returns the container that is backing the provided instance

func GetDocker0InterfaceIP

func GetDocker0InterfaceIP() (string, error)

GetDocker0InterfaceIP finds and returns the ip for the docker0 network interface

func GetDockerBindingPort

func GetDockerBindingPort(bindings []docker.PortBinding) (iscenv.ContainerPort, error)

GetDockerBindingPort returns a DockerPort that represents the first port from the provided bindings Assumes a single binding

func GetInstanceStartTime

func GetInstanceStartTime(instance *iscenv.ISCInstance) (time.Time, error)

GetInstanceStartTime gets and returns the start time of the provided instance

func GetInstances

func GetInstances() iscenv.ISCInstances

GetInstances will return a list of available ISC product Instances. This function will panic in the case that it cannot list the containers from Docker. Normally, these kinds of abrupt exits should be avoided outside of the actual executable command portions of the code. However, in this case the extreme nature of the failure, the rarity of occurrence, and the large amount of error handling that would need to be added throughout the code without the exit seems to justify its existence.

func InstanceLogger

func InstanceLogger(instance *iscenv.ISCInstance) *log.Entry

InstanceLogger creates and returns a logger for the provided instance

func InstanceLoggerArgs

func InstanceLoggerArgs(instanceName, instanceID string) *log.Entry

InstanceLoggerArgs returns an instance logger with the values as args

func IsUserRoot

func IsUserRoot() error

IsUserRoot determines if the current user is root

func NewRawTTYStdin

func NewRawTTYStdin() (tty *rawTTYStdin, err error)

NewRawTTYStdin creates and returns a new raw tty with stdin

func PluginLogger

func PluginLogger(id, method, path string) *log.Entry

PluginLogger creates and returns a logger with references to the provided plugin information

func Relog

func Relog(plog log.FieldLogger, preserveTimestamp bool, rlog map[string]interface{})

Relog will relog a single log message that has been Unmarshaled into a map[string]interface{} extraFields contains additional fields you wish to add to the log output. These will overwrite any fields from the original log message. preserveTimestamps will use the timestamps from the original log messages instead of the current time

func RelogStream

func RelogStream(plog log.FieldLogger, preserveTimestamp bool, r io.Reader)

RelogStream will given a JSON log stream, relog all of the message into the current process extraFields contains additional fields you wish to add to the log output. These will overwrite any fields from the original log message. preserveTimestamps will use the timestamps from the original log messages instead of the current time

func WaitForInstance

func WaitForInstance(instance *iscenv.ISCInstance, timeout time.Duration) error

WaitForInstance will wait for an instance until it is running or the timeout is reached

func WaitForInstanceForever

func WaitForInstanceForever(instance *iscenv.ISCInstance, c chan error)

WaitForInstanceForever ill wait for an instance until it is running

func WaitForPort

func WaitForPort(ip string, port string, timeout time.Duration) error

WaitForPort waits for a port to become available or until the timeout

func WaitForPortForever

func WaitForPortForever(ip string, port string, c chan error)

WaitForPortForever waits for a port to become available

Types

type DockerConfigError

type DockerConfigError struct {
	ConfigPath string
	Registry   string
	Err        error
}

DockerConfigError is an used for logging an error with a docker config

func NewDockerConfigError

func NewDockerConfigError(path, registry string, err error) *DockerConfigError

NewDockerConfigError creates and returns a new DockerConfigError

func (*DockerConfigError) Error

func (dce *DockerConfigError) Error() string

Error returns the error string for the error associated with the DockerConfigError

type DockerExecError

type DockerExecError struct {
	ExitCode int
}

DockerExecError is used for representing a failed docker exec

func (DockerExecError) Error

func (dee DockerExecError) Error() string

Error will return an error string for a DockerExecError

type DockerStartOptions

type DockerStartOptions struct {
	// The name of the instance
	Name string

	// The full name of the container, if this is populated, it will not be calculated
	// TODO: This is fairly hacky and should be reworked in a future refactoring phase
	FullName string

	// The image repository from which the container will be created
	Repository string

	// The version of the image to use
	Version string

	// The port by which the external ports will be offset (or the starting offset for search if searching)
	PortOffset int64

	// Search for the next available port offset?
	PortOffsetSearch bool

	// Disable the port offset checks, only do this if you are creating additional supplementary containers that use an existing containers offset to offset a different port/set of ports
	// TODO: This is fairly hacky and should be reworked in a future refactoring phase
	DisablePortOffsetConflictCheck bool

	// The entrypoint for the container
	Entrypoint []string

	// The command for the container
	Command []string

	// Environment variables in standard docker format (ENV=VALUE)
	Environment []string

	// Volumes provided in the standard host:container:mode format
	Volumes []string

	// Copies files provided in the format host:container into the container before it starts
	Copies []string

	// The names of containers from which volumes will be used
	VolumesFrom []string

	// Containers to which this container should be linked
	ContainerLinks []string

	// Port mappings in standard <IP>:host:container format
	Ports []string

	// Labels to add to the container
	Labels map[string]string

	// Should the container be deleted if it already exists?
	Recreate bool

	// User to run the container as
	Username string
}

DockerStartOptions holds information used in starting a container

func (*DockerStartOptions) ContainerName

func (opts *DockerStartOptions) ContainerName() string

ContainerName returns the name that should be used for the container that is being managed

func (*DockerStartOptions) InternalVolumes

func (opts *DockerStartOptions) InternalVolumes() map[string]struct{}

InternalVolumes returns a map of the volumes internal to the container extracted from the DockerStartOptions list of volumes

func (*DockerStartOptions) ToCreateContainerOptions

func (opts *DockerStartOptions) ToCreateContainerOptions() *docker.CreateContainerOptions

ToCreateContainerOptions transforms a DockerStartOptions into CreateContainerOptions

func (*DockerStartOptions) ToDockerPortBindings

func (opts *DockerStartOptions) ToDockerPortBindings() map[docker.Port][]docker.PortBinding

ToDockerPortBindings returns a map of Ports to a slice of PortBindings

func (*DockerStartOptions) ToExposedPorts

func (opts *DockerStartOptions) ToExposedPorts() map[docker.Port]struct{}

ToExposedPorts returns a map of ports that are exposed by the contain

func (*DockerStartOptions) ToHostConfig

func (opts *DockerStartOptions) ToHostConfig() *docker.HostConfig

ToHostConfig transforms a DockerStartOptions into a HostConfig

func (*DockerStartOptions) VolumeBinds

func (opts *DockerStartOptions) VolumeBinds() []string

VolumeBinds returns a slice of volumes that should be bound from the DockerStartOptions

type ISCInstanceManager

type ISCInstanceManager struct {
	*isclib.Instance
	InstanceRunningHandler  InstanceStateFn
	PrimaryCommand          string
	PrimaryCommandNamespace string
}

ISCInstanceManager manages a instance within a container

func NewISCInstanceManager

func NewISCInstanceManager(instanceName string, ccontrolPath string, csessionPath string, primaryCommand string, primaryCommandNamespace string) (*ISCInstanceManager, error)

NewISCInstanceManager creates and returns an ISCInstanceManager

func (*ISCInstanceManager) Manage

func (eim *ISCInstanceManager) Manage() error

Manage starts and manages the lifecycle of the instance associated with the ISCInstanceManager

type InstanceError

type InstanceError struct {
	InstanceName string
	InstanceID   string
	Err          error
}

InstanceError is an used for logging an error with an instance

func NewInstanceError

func NewInstanceError(name, id string, err error) *InstanceError

NewInstanceError creates and returns a new InstanceError

func (*InstanceError) Error

func (ie *InstanceError) Error() string

Error returns the error string for the error associated with the InstanceError

type InstanceStateFn

type InstanceStateFn func(instance *isclib.Instance)

InstanceStateFn is a type that specifies a function signature for dealing with an instance's state

type PluginError

type PluginError struct {
	Plugin       string
	PluginMethod string
	PluginPath   string
	Err          error
}

PluginError is an used for logging an error with a plugin

func NewPluginError

func NewPluginError(plugin, method, path string, err error) *PluginError

NewPluginError creates and returns a new PluginError

func (*PluginError) Error

func (pe *PluginError) Error() string

Error returns the error string for the error associated with the PluginError

type StartPhase

type StartPhase uint

StartPhase represents a phase in the startup process

type StartStatus

type StartStatus struct {
	Phase           StartPhase       `json:"phase"`
	ActivePlugins   []string         `json:"activePlugins"`
	ExecutingPlugin string           `json:"executingPlugin"`
	InstanceState   *isclib.Instance `json:"instanceState"`
}

StartStatus represents information about the startup of an instance and the current phase it is in

func NewStartStatus

func NewStartStatus() *StartStatus

NewStartStatus creates and returns a new initialized StartStatus

func (*StartStatus) Update

func (ss *StartStatus) Update(phase StartPhase, state *isclib.Instance, executingPlugin string)

Update will update the start phase of the provided instance to the provided start phase

type TTYSizeChangeHandler

type TTYSizeChangeHandler func(height, width int)

TTYSizeChangeHandler is a type that specifies a function signature for dealing with tty size changes

Jump to

Keyboard shortcuts

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