Documentation
¶
Index ¶
- Constants
- func NewContextWithCapComm(ctx context.Context, capComm *CapComm) context.Context
- type Blueprint
- type BlueprintInfo
- type CapComm
- func (capComm *CapComm) AddAdditionalMissionData(missionData TemplateData) *CapComm
- func (capComm *CapComm) AddFileResource(ctx context.Context, name providers.ResourceID, filePath string, ...) error
- func (capComm *CapComm) AddResource(name providers.ResourceID, provider providers.ResourceProvider)
- func (capComm *CapComm) AttachInputSpec(ctx context.Context, name providers.ResourceID, inputSpec InputSpec) error
- func (capComm *CapComm) AttachOutputSpec(ctx context.Context, name providers.ResourceID, outputSpec OutputSpec) error
- func (capComm *CapComm) AttachRedirect(ctx context.Context, redirect Redirection) error
- func (capComm *CapComm) Copy(noTrust bool) *CapComm
- func (capComm *CapComm) ExpandString(ctx context.Context, name, value string) (string, error)
- func (capComm *CapComm) ExportVariable(key, value string) *CapComm
- func (capComm *CapComm) FuncMap() template.FuncMap
- func (capComm *CapComm) GetExecEnv() []string
- func (capComm *CapComm) GetResource(name providers.ResourceID) providers.ResourceProvider
- func (capComm *CapComm) GetTemplateData(ctx context.Context) TemplateData
- func (capComm *CapComm) InputSpecToResourceProvider(ctx context.Context, inputSpec InputSpec) (providers.ResourceProvider, error)
- func (capComm *CapComm) Log() loggee.Logger
- func (capComm *CapComm) MergeBasicEnvMap(env EnvMap) *CapComm
- func (capComm *CapComm) MergeParams(ctx context.Context, params []Param) error
- func (capComm *CapComm) MergeTemplateEnvs(ctx context.Context, env EnvMap) error
- func (capComm *CapComm) OutputSpecToResourceProvider(ctx context.Context, outputSpec OutputSpec) (providers.ResourceProvider, error)
- func (capComm *CapComm) Seal() *CapComm
- func (capComm *CapComm) WithMission(mission *Mission) *CapComm
- type Delims
- type EnvMap
- type ExecuteFunc
- type Filter
- type Getter
- type Include
- type InputSpec
- type Inventory
- type KeyValueGetter
- type Location
- type Mission
- type MissionController
- type MustHaveParams
- type Option
- type OutputSpec
- type Param
- type PreMission
- type Redirection
- type Runbook
- type Runtime
- type Stage
- type Task
- type TaskType
- type TemplateData
Constants ¶
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" // MissionFileParamName is param name of the mission file. MissionFileParamName = "missionFile" // MissionBaseParamName is the base name of the mission file, without path or extensions. MissionBaseParamName = "missionBaseName" // MissionDirURLParamName is the full url to the directory containing the mission. MissionDirURLParamName = "missionDirURL" // MissionDirParamName is the file system path to the file. MissionDirParamName = "missionDir" // MissionDirAbsParamName is the file system absolute path to the file. MissionDirAbsParamName = "missionDirAbs" // MissionURLParamName is the full url to the mission file. MissionURLParamName = "missionURL" // WorkingDirectoryParamName is the name of the working dir. WorkingDirectoryParamName = "workingDir" )
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 ¶
Types ¶
type Blueprint ¶ added in v0.2.1
type Blueprint struct {
// Name of the blueprint.
Name string `mapstructure:"name"`
// Location is the location of the blueprint, set at read time
Location string `mapstructure:"-"`
// Description is a free text description of the blueprint
Description string `mapstructure:"description"`
// Location of runbook pro forma
Runbook *Location `mapstructure:"runbook"`
// Location of the mission
Mission Location `mapstructure:"mission"`
// Params is a list of parameters needed for the runbook.
Params []Param `mapstructure:"params"`
}
Blueprint is a ready to assemble mission.
type BlueprintInfo ¶ added in v0.2.1
type BlueprintInfo struct {
// Name of the blueprint.
Name string `mapstructure:"name"`
// Version of the blueprint
Version string `json:"version,omitempty" yaml:"version,omitempty" mapstructure:"version"`
// Location is the location of the blueprint
Location string `mapstructure:"location"`
// Description is a free text description of the blueprint
Description string `json:"description,omitempty" yaml:"description,omitempty" mapstructure:"description"`
}
BlueprintInfo contains information about a blueprint.
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 ¶
GetCapCommContext returns the capComm from the context.
func NewCapComm ¶ added in v0.1.2
NewCapComm returns a cap comm object that is suitable for using for testing.
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 runbook 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 runbook to the capComm.
func (*CapComm) AttachRedirect ¶
func (capComm *CapComm) AttachRedirect(ctx context.Context, redirect Redirection) error
AttachRedirect attaches a redirection runbook to the capComm Redirection covers in, out and error streams.
func (*CapComm) Copy ¶
Copy creates a new unsealed CapComm instance and deep copies the current CapComm's values into it.
func (*CapComm) ExpandString ¶
ExpandString expands a templated string using the capComm's template data.
func (*CapComm) ExportVariable ¶ added in v0.1.0
ExportVariable exports the passed variable to all capComm's sharing the same parent as the receiver.
func (*CapComm) GetExecEnv ¶
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)
InputSpecToResourceProvider creates a resource provider from the supplied input runbook.
func (*CapComm) MergeBasicEnvMap ¶
MergeBasicEnvMap adds environment variables into an unsealed CapComm.
func (*CapComm) MergeParams ¶
MergeParams adds params into an unsealed CapComm instance.
func (*CapComm) MergeTemplateEnvs ¶
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)
OutputSpecToResourceProvider creates a resource provider from a output specificsation.
func (*CapComm) Seal ¶
Seal prevents further editing of the capComm any attempt to edit will cause a panic (as this is a development bug).
func (*CapComm) WithMission ¶
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 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 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 to the input file.
Path string `mapstructure:"path"`
// URl provides a url to th input 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 runbook.
SkipExpand bool `mapstructure:"skipExpand"`
}
InputSpec is a resource input specificsation. Input data can be provided from inline valuses, exported stage variables, local files or a web url.
type Inventory ¶ added in v0.2.1
type Inventory struct {
Items []string `mapstructure:"items"`
}
Inventory is a list of blueprints.
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 Location ¶ added in v0.2.1
type Location struct {
// Inline detail
Inline string `mapstructure:"inline"`
// Path provides the path to the item, relative to the blueprints location
Path string `mapstructure:"path"`
}
Location is a location of input data.
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"`
// Must is a slice of params that must be defined prior to the mission starting
// Iif any are missing the mission will fail.
Must MustHaveParams `mapstructure:"must"`
// 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 MissionController ¶ added in v0.2.1
type MissionController interface {
// Set option sets options on the mission controller
SetOptions(options ...Option) error
// 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.
// Location is used to indicate where the config was read from, if blank the current working directory is assumed.
LaunchMission(ctx context.Context, location string, spaceDust map[string]interface{}, flightSequences ...string) error
LaunchMissionWithParams(ctx context.Context, location string,
spaceDust map[string]interface{},
params []Param,
flightSequences ...string) error
// Assemble locates a blueprint from the assembly sources, loads the runbook and builds the assembly following the runbook.
Assemble(ctx context.Context, blueprint string, sources []string, specLocation string, params []Param) error
// GetRunbook gets the runbook for a blueprint
GetRunbook(ctx context.Context, blueprintName string, sources []string) (string, error)
// ListBlueprints builds a list of all blueprints found in the passed sources
ListBlueprints(ctx context.Context, sources []string) ([]BlueprintInfo, error)
}
MissionController seeks out new civilizations in te CI space.
func NewMissionControl ¶
func NewMissionControl() MissionController
NewMissionControl create a new mission control.
type MustHaveParams ¶ added in v0.2.1
type MustHaveParams []string
MustHaveParams is a slice of param names that must be definedbefore a mission, stage or activity starts. The list is checked prior too processing the activities own set of param definitions.
type Option ¶ added in v0.2.1
type Option interface {
Name() string
}
Option is the interface supported by all mission options.
func LoggerOption ¶ added in v0.2.1
LoggerOption sets specifies the logger to use with the 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 runbook.
SkipExpand bool `mapstructure:"skipExpand"`
// OS File permissions
FileMode uint `mapstructure:"fileMode"`
}
OutputSpec defines the method of outputtting for a given resource. The choice is either variables or files.
type Param ¶
type Param struct {
// Name is the name of the parameter
// Name is mandatory
Name string `mapstructure:"name"`
// Description is a free text description of the parameter
Description string `mapstructure:"description"`
// Value is the value of the parameter. If SkipExpand is false the value will
// be transformed using template expansion.
Value string `mapstructure:"value"`
// Path is the location of a resource that can provide the parameter's value.
// Paths may be either a local file system path or a url to file or http(s) resource.
// If both Path and Value are supplied the resource value will be appended to the Value.
// Template expressions can be used in the path. The template is expanded to get the
// location of the resource.
//
// If the resource is successfully located it is appended to the Value property.
// If SkipExpand is false the combined value will be processed as a template to
// obtain the final value. If SkipExpand is true the combined value will be used without
// any additional expansion.
Path string `mapstructure:"path"`
// SkipExpand skip templating the param
SkipExpand bool `mapstructure:"skipExpand"`
// Optional if true allows the file not to exist
Optional bool `mapstructure:"optional"`
// Print if true will display the value of the parameter once expanded to the log
Print bool `mapstructure:"print"`
}
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 runbook
Input *InputSpec `mapstructure:"input"`
// Output runbook
Output *OutputSpec `mapstructure:"output"`
// Error runbook
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 Runbook ¶ added in v0.2.1
type Runbook struct {
// Name of the runbook.
Name string `mapstructure:"name"`
// Blueprint is the name of the blue print
Blueprint string `mapstructure:"blueprint"`
// Params is a list of parameters needed for the runbook.
Params []Param `mapstructure:"params"`
FlightSequence []string `mapstructure:"sequence"`
}
Runbook is a list of parameters required to complete a blueprint assembly.
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
// UserName runtime username
UserName string
}
Runtime holds runtime data accessible to templates.
type Stage ¶
type Stage struct {
// Name of the 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"`
// Dir is the directory to execute the stage in
Dir string `mapstructure:"dir"`
// 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"`
// Must is a slice of params that must be defined prior to the stage starting
// Iif any are missing the mission will fail.
Must MustHaveParams `mapstructure:"must"`
// 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"`
// Dir is the directory to execute the task in
Dir string `mapstructure:"dir"`
// 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"`
// Must is a slice of params that must be defined prior to the task starting
// Iif any are missing the mission will fail.
Must MustHaveParams `mapstructure:"must"`
// 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.