rocket

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2021 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// EnvTag is the root tag used in template data for environment variables
	// eg PATH is .Env.PATH.
	EnvTag = "Env"

	// ParentEnvTag is the root tag for environment variables when the task is not trusted.
	ParentEnvTag = "ParentEnv"

	// RuntimeTag is the remplate data key to the run time data.
	RuntimeTag = "Runtime"

	// BuildTag is the data template key for build information about the hosting application.
	BuildTag = "Build"

	// VariableTag is the top key for variables in the template data.
	VariableTag = "Var"

	// AdditionalMissionTag is the data template key to additional mission information.
	AdditionalMissionTag = "Additional"

	// ConfigFile is the config file.
	ConfigFile = "configFile"

	// ConfigBaseName is the base name of the config file, not path or extensions.
	ConfigBaseName = "configBaseName"

	// ConfigDir is the config dir.
	ConfigDir = "configDir"

	// ConfigFileFullPath is the full path to the config.
	ConfigFileFullPath = "configFullPath"
)
View Source
const (
	// InputIO is the input file key.
	InputIO = providers.ResourceID("input")
	// OutputIO is the output file key.
	OutputIO = providers.ResourceID("output")
	// ErrorIO is the error file key.
	ErrorIO = providers.ResourceID("error")

	// Stdin is the Std in resource.
	Stdin = providers.ResourceID("stdin")
	// Stdout is the Std out resource.
	Stdout = providers.ResourceID("stdout")
	// Stderr is the Std error resource.
	Stderr = providers.ResourceID("stderr")
)

Variables

This section is empty.

Functions

func NewContextWithCapComm

func NewContextWithCapComm(ctx context.Context, capComm *CapComm) context.Context

NewContextWithCapComm creates a new context with capComm attached.

Types

type CapComm

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

CapComm handles all communication between mission control and the mission stages and tasks.

func GetCapCommContext

func GetCapCommContext(ctx context.Context) *CapComm

GetCapCommContext returns the capComm from the context.

func (*CapComm) AddAdditionalMissionData

func (capComm *CapComm) AddAdditionalMissionData(missionData TemplateData) *CapComm

AddAdditionalMissionData adds the additional mission data.

func (*CapComm) AddFileResource added in v0.1.0

func (capComm *CapComm) AddFileResource(ctx context.Context, name providers.ResourceID, filePath string, mode providers.IOMode) error

AddFileResource adds a key named file specificsation into the CapComm. The filePath follows standard template and environment variable expansion. The mode controls how the file will be used. Files can be added to sealed CapComm's.

func (*CapComm) AddResource added in v0.1.0

func (capComm *CapComm) AddResource(name providers.ResourceID, provider providers.ResourceProvider)

AddResource adds a resource to the capComm object.

func (*CapComm) AttachInputSpec added in v0.1.0

func (capComm *CapComm) AttachInputSpec(ctx context.Context, name providers.ResourceID, inputSpec InputSpec) error

AttachInputSpec adds a named input spec to the capCom resources.

func (*CapComm) AttachOutputSpec added in v0.1.0

func (capComm *CapComm) AttachOutputSpec(ctx context.Context, name providers.ResourceID, outputSpec OutputSpec) error

AttachOutputSpec attaches an output specification to the capComm.

func (*CapComm) AttachRedirect

func (capComm *CapComm) AttachRedirect(ctx context.Context, redirect Redirection) error

AttachRedirect attaches a redirection specification to the capComm Redirection covers in, out and error streams.

func (*CapComm) Copy

func (capComm *CapComm) Copy(noTrust bool) *CapComm

Copy creates a new unsealed CapComm instance and deep copies the current CapComm's values into it.

func (*CapComm) ExpandString

func (capComm *CapComm) ExpandString(ctx context.Context, name, value string) (string, error)

ExpandString expands a templated string using the capComm's template data.

func (*CapComm) ExportVariable added in v0.1.0

func (capComm *CapComm) ExportVariable(key, value string) *CapComm

func (*CapComm) FuncMap

func (capComm *CapComm) FuncMap() template.FuncMap

FuncMap returns the function mapping used by CapComm.

func (*CapComm) GetExecEnv

func (capComm *CapComm) GetExecEnv() []string

GetExecEnv converts the environment variables map into the string format needed for a exec Cmd.

func (*CapComm) GetResource added in v0.1.0

func (capComm *CapComm) GetResource(name providers.ResourceID) providers.ResourceProvider

GetResource a resource.

func (*CapComm) GetTemplateData

func (capComm *CapComm) GetTemplateData(ctx context.Context) TemplateData

GetTemplateData gts the data collection supplied to a template.

func (*CapComm) InputSpecToResourceProvider added in v0.1.0

func (capComm *CapComm) InputSpecToResourceProvider(ctx context.Context, inputSpec InputSpec) (providers.ResourceProvider, error)

func (*CapComm) Log added in v0.1.0

func (capComm *CapComm) Log() loggee.Logger

Log returns the cap com logger.

func (*CapComm) MergeBasicEnvMap

func (capComm *CapComm) MergeBasicEnvMap(env EnvMap) *CapComm

MergeBasicEnvMap adds environment variables into an unsealed CapComm.

func (*CapComm) MergeParams

func (capComm *CapComm) MergeParams(ctx context.Context, params []Param) error

MergeParams adds params into an unsealed CapComm instance.

func (*CapComm) MergeTemplateEnvs

func (capComm *CapComm) MergeTemplateEnvs(ctx context.Context, env EnvMap) error

MergeTemplateEnvs adds params into an unsealed CapComm instance.

func (*CapComm) OutputSpecToResourceProvider added in v0.1.0

func (capComm *CapComm) OutputSpecToResourceProvider(ctx context.Context, outputSpec OutputSpec) (providers.ResourceProvider, error)

func (*CapComm) Seal

func (capComm *CapComm) Seal() *CapComm

Seal prevents further editing of the capComm any attempt to edit will cause a panic (as this is a development bug).

func (*CapComm) WithMission

func (capComm *CapComm) WithMission(mission *Mission) *CapComm

WithMission attaches the mission to the CapComm.

type Delims

type Delims struct {
	// Left is the opening delimiter
	Left string `mapstructure:"left"`

	// Right is the closing delimiter
	Right string `mapstructure:"right"`
}

Delims are the delimiters to use to escape template functions.

type EnvMap

type EnvMap map[string]string

EnvMap is a map of environment variables to their values.

type ExecuteFunc

type ExecuteFunc = loggee.ActivityFunc

ExecuteFunc is the function signature of an activity that can be executed.

type Filter

type Filter struct {
	// IncludeOS is a list of operating systems to include
	IncludeOS []string `mapstructure:"includeOS"`
	// IncludeArch is a list of architectures to permit
	IncludeArch []string `mapstructure:"includeArch"`

	// ExcludeOS restricts an operating system from running
	ExcludeOS []string `mapstructure:"excludeOS"`

	// ExcludeArch restricts specific architectures from running
	ExcludeArch []string `mapstructure:"excludeArch"`

	// Skip prevents theactivity from running if true.
	Skip bool `mapstructure:"skip"`
}

Filter restricts running an activity The filter applis to the OS and Architecture of the machine running rocket. This allows OS specific scripts to be used.

type Getter

type Getter interface {
	// Get a value
	Get(key string) string

	// All returns all the entries
	All() map[string]string
}

Getter returns a value for an input key, iif the key is not found an empty string is returned.

type Include

type Include struct {
	Path string `mapstructure:"path"`
	URL  string `mapstructure:"url"`
}

type InputSpec added in v0.1.0

type InputSpec struct {
	// Variable name to import from
	Variable string `mapstructure:"variable"`

	Inline string `mapstructure:"inline"`

	// Path provides the path data.
	Path string `mapstructure:"path"`

	// URl provides the data.
	URL string `mapstructure:"url"`

	// Optional is true if resource can be missing.
	Optional bool `mapstructure:"optional"`

	// URLTimeout request timeout, default is 30 seconds.
	URLTimeout uint `mapstructure:"timeout"`

	// SkipExpand when true skips template expansion of the spec.
	SkipExpand bool `mapstructure:"skipExpand"`
}

type KeyValueGetter

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

KeyValueGetter is a value map with fallback to a parent Getter.

func NewKeyValueGetter

func NewKeyValueGetter(parent Getter) *KeyValueGetter

NewKeyValueGetter creates a new KeyValueGetter.

func (*KeyValueGetter) All

func (kvg *KeyValueGetter) All() map[string]string

All returns the values tp down, where child values override parent key values.

func (*KeyValueGetter) Get

func (kvg *KeyValueGetter) Get(key string) string

Get returns the value for a key.

type Mission

type Mission struct {
	// Mission name, defsaults to the config file name
	Name string `mapstructure:"name"`

	// Additional contains any additional parameters specified in the
	// configuration.  They are included in the template data set
	// but will be overridden by any other duplicate keys
	Additional map[string]interface{} `mapstructure:",remain"`

	// BasicEnv is a map of additional environment variables
	// They are not template expanded
	BasicEnv EnvMap `mapstructure:"basicEnv"`

	// Env is a map of additional environment variables
	// These are subject to template expansion after the params have been expanded
	Env EnvMap `mapstructure:"env"`

	// Params is a collection of parameters that can be used within
	// the child stages.  Parameters are template expanded and can use
	// Environment variables defined in Env
	Params []Param `mapstructure:"params"`

	// Sequences specify a list of stages to run.
	// If no sequences are provides all stages are run in the order they are defined.
	// If sequences are included in the mission one must be specified or the mission will fail
	Sequences map[string][]string `mapstructure:"sequences"`

	// Stages represents the stages of the mission
	// If no sequences are included in the file all stages are executed in ordinal order.
	// If a sequence is included in the mission file the launch mission call must specify the sequence to use.
	Stages []Stage `mapstructure:"stages"`

	// Version of the mission definition
	Version string `mapstructure:"version"`
}

Mission is activity to complete.

type MissionControl

type MissionControl interface {
	// RegisterTaskTypes we only want the best.
	RegisterTaskTypes(types ...TaskType)

	// LaunchMission loads and executes the mission
	// flightSequences may be specified, each sequence is run in the order specified
	// the coonfig file is the source name iof the config provided
	// if its empty the current working 'dir/default' will be used.
	LaunchMission(ctx context.Context, configFile string, spaceDust map[string]interface{}, flightSequences ...string) error

	// LaunchMissionWithParams loads and executes the mission with user supplied parameters
	// flightSequences may be specified, each sequence is run in the order specified
	// the coonfig file is the source name iof the config provided
	// if its empty the current working 'dir/default' will be used.
	// The supplied params are default values and do not override values defined in the mission
	LaunchMissionWithParams(ctx context.Context, configFile string,
		spaceDust map[string]interface{},
		params []Param,
		flightSequences ...string) error
}

MissionControl seeks out new civilizations in te CI space.

func Default

func Default() MissionControl

Default returns the default shared mission control.

func NewMissionControl

func NewMissionControl() MissionControl

NewMissionControl create a new mission control.

type OutputSpec

type OutputSpec struct {
	// Variable is an exported variable available to later tasks in the same stage
	Variable string `mapstructure:"variable"`

	// Output is a path to a file replacing STDOUT
	Path string `mapstructure:"path"`

	// AppendOutput specifies if output should append
	Append bool `mapstructure:"append"`

	// SkipExpand when true skips template expansion of the spec.
	SkipExpand bool `mapstructure:"skipExpand"`

	// OS File permissions
	FileMode uint `mapstructure:"fileMode"`
}

type Param

type Param struct {
	// Name is the name of the parameter
	// Name is mandatory
	Name string `mapstructure:"name"`

	// Value is the value of the parameter and is subject to expandion
	Value string `mapstructure:"value"`

	// Path is a path to file containing the value.
	// If both Path and Value are supplied the file will bee appended to the Valued
	// The combined value will undergo template expansion if SkipTemplate is false.
	Path string `mapstructure:"path"`

	// URL specifies the data should come from the response body or a web request.
	// The url body will be concatenated with the value and file values respectively.
	// The combined value will undergo template expansion if SkipTemplate is false.
	URL string `mapstructure:"url"`

	// SkipExpand skip templating the param
	SkipExpand bool `mapstructure:"skipExpand"`

	// Optional if true allows the file not to exist
	Optional bool `mapstructure:"optional"`
}

Param is an expandible parameter.

type PreMission

type PreMission struct {
	Mission  map[string]interface{} `mapstructure:",remain"`
	Includes []Include              `mapstructure:"includes"`
}

PreMission preprocesses missions before loading them.

type Redirection

type Redirection struct {
	// Input specification
	Input *InputSpec `mapstructure:"input"`

	// Output specification
	Output *OutputSpec `mapstructure:"output"`

	// Error specification
	Error *OutputSpec `mapstructure:"error"`

	// MergeErrorWithOutput specifies if error output should go to outputt
	// if specified Error and AppendError are ignored
	MergeErrorWithOutput bool `mapstructure:"merge"`

	// LogOutput if true will cause output to be logged rather than going to go to std output.
	// If an output file is specified it will be used instead.
	LogOutput bool `mapstructure:"logStdOut"`

	// DirectError when true causes the commands std error output to go direct to running processes std error
	// When DirectError is false std error output is logged.
	DirectError bool `mapstructure:"directStdErr"`
}

Redirection is provided to a task to interpret Redirection strings need to be expanded by the task.

type Runtime

type Runtime struct {
	// GOOS is the operating system the host application is running against
	GOOS string
	// GOARCH is the architecture the host application is running against
	GOARCH string
}

Runtime holds runtime data accessible to templates.

type Stage

type Stage struct {
	// Name of th stage.
	// If it is not provided it default to the ordinal ID of the stage within the mission
	Name string `mapstructure:"name"`

	// BasicEnv is a map of additional environment variables
	// They are not template expanded
	BasicEnv EnvMap `mapstructure:"basicEnv"`

	// Env is a map of additional environment variables
	// These are subject to template expansion after the params have been expanded
	Env EnvMap `mapstructure:"env"`

	// Filter is an optional filter on the stage
	// If the filter criteria are not met the stage will not be executed
	Filter *Filter `mapstructure:"filter"`

	// NoTrust indicates the stage should not inherit environment
	// variables or parameters from its parent.  This can be used with a run stage
	// where you do not want the process to receive API tokens etc
	NoTrust bool `mapstructure:"noTrust"`

	// Params is a collection of parameters that can be used within
	// the child stages.  Parameters are template expanded and can use
	// Environment variables defined in Env
	Params []Param `mapstructure:"params"`

	// Tasks is a collection of one or more tasks to complete
	// Tasks are executed sequentally
	Tasks []Task `mapstructure:"tasks"`

	// Try to run the stage but if it fails do no abort the whole run
	Try bool `mapstructure:"try"`
}

Stage is a collection of tasks that can share a common set of parameters. All tasks within a stage are executed sequently.

type Task

type Task struct {
	// Type is the type of the task.  The task type must have been rejiggered
	// with the mission control.  Tasks not registered will fail the mission.
	Type string `mapstructure:"type"`

	// Name of the task.
	// If it is not provided it default to the ordinal ID of the task within the stage
	Name string `mapstructure:"name"`

	// Definition contains the additional data required to process the task type
	Definition map[string]interface{} `mapstructure:",remain"`

	// BasicEnv is a map of additional environment variables
	// They are not template expanded
	BasicEnv EnvMap `mapstructure:"basicEnv"`

	// Env is a map of additional environment variables
	// These are subject to template expansion after the params have been expanded
	Env EnvMap `mapstructure:"env"`

	// Filter is an optional filter on the task
	// If the filter criteria are not met the task will not be executed
	Filter *Filter `mapstructure:"filter"`

	// NoTrust indicates the task should not inherit environment
	// variables or parameters from the parent.  This can be used with a run task
	// where you do not want the process to receive API tokens etc
	NoTrust bool `mapstructure:"noTrust"`

	// Params is a collection of parameters that can be used within
	// the child stages.  Parameters are template expanded and can use
	// Environment variables defined in Env
	Params []Param `mapstructure:"params"`

	// Try to run the task but if it fails do no abort the whole run
	Try bool `mapstructure:"try"`
}

Task is an activity that is executed.

type TaskType

type TaskType interface {

	// Type of the task
	Type() string

	// Prepare the task from the input details.
	Prepare(ctx context.Context, capComm *CapComm, task Task) (ExecuteFunc, error)
}

TaskType represents a specific task type.

type TemplateData

type TemplateData map[string]interface{}

TemplateData represents the data passed t a template.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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