Documentation
¶
Overview ¶
Package action provides implementations of discovering and running actions.
Index ¶
- Constants
- func CobraImpl(a *Action, streams cli.Streams) (*cobra.Command, error)
- func ConvertInputToTplVars(input Input, ac *DefAction) map[string]interface{}
- func ForwardAllSignals(ctx context.Context, cli driver.ContainerRunner, cid string, ...)
- func WithDefaultRunEnvironment(m Manager, a *Action)
- type Action
- func (a *Action) ActionDef() *DefAction
- func (a *Action) Clone() *Action
- func (a *Action) DefinitionEncoded() ([]byte, error)
- func (a *Action) Dir() string
- func (a *Action) EnsureLoaded() (err error)
- func (a *Action) Execute(ctx context.Context) error
- func (a *Action) Filepath() string
- func (a *Action) GetInput() Input
- func (a *Action) ImageBuildInfo(image string) *types.BuildDefinition
- func (a *Action) JSONSchema() jsonschema.Schema
- func (a *Action) Reset()
- func (a *Action) SetInput(input Input) (err error)
- func (a *Action) SetRunEnvironment(env RunEnvironment)
- func (a *Action) ValidateInput(inp Input) error
- type Argument
- type ArgumentsList
- type ChainImageBuildResolver
- type ConfigImages
- type ContainerNameProvider
- type ContainerRunEnvironment
- type DecorateWithFn
- type DefAction
- type Definition
- type Discovery
- type EnvSlice
- type ImageBuildResolver
- type Input
- type LaunchrConfigImageBuildResolver
- type LoadContext
- type LoadProcessor
- type Loader
- type Manager
- type Option
- type OptionsList
- type RunEnvironment
- type RunEnvironmentFlags
- type RunInfo
- type StrSlice
- type StrSliceOrStr
- type TypeArgs
- type TypeOpts
Constants ¶
const ConfigImagesKey = "images"
ConfigImagesKey is a field name in launchr config file.
Variables ¶
This section is empty.
Functions ¶
func CobraImpl ¶ added in v0.0.9
CobraImpl returns cobra command implementation for an action command.
func ConvertInputToTplVars ¶ added in v0.1.2
ConvertInputToTplVars creates a map with input variables suitable for template engine.
func ForwardAllSignals ¶
func ForwardAllSignals(ctx context.Context, cli driver.ContainerRunner, cid string, sigc <-chan os.Signal)
ForwardAllSignals forwards signals to the container
The channel you pass in must already be setup to receive any signals you want to forward.
func WithDefaultRunEnvironment ¶ added in v0.1.2
WithDefaultRunEnvironment adds a default RunEnvironment for an action.
Types ¶
type Action ¶
Action is an action definition with a contextual id (name), working directory path and a runtime context such as input arguments and options.
func (*Action) ActionDef ¶ added in v0.1.2
ActionDef returns action definition with replaced variables.
func (*Action) DefinitionEncoded ¶ added in v0.1.2
DefinitionEncoded returns encoded action file content.
func (*Action) EnsureLoaded ¶ added in v0.1.2
EnsureLoaded loads an action file with replaced arguments and options.
func (*Action) ImageBuildInfo ¶ added in v0.1.2
func (a *Action) ImageBuildInfo(image string) *types.BuildDefinition
ImageBuildInfo implements ImageBuildResolver.
func (*Action) JSONSchema ¶ added in v0.1.2
func (a *Action) JSONSchema() jsonschema.Schema
JSONSchema returns json schema of an action.
func (*Action) Reset ¶ added in v0.1.2
func (a *Action) Reset()
Reset unsets loaded action to force reload.
func (*Action) SetInput ¶ added in v0.1.2
SetInput saves arguments and options for later processing in run, templates, etc.
func (*Action) SetRunEnvironment ¶ added in v0.1.2
func (a *Action) SetRunEnvironment(env RunEnvironment)
SetRunEnvironment sets environment to run the action.
func (*Action) ValidateInput ¶ added in v0.1.2
ValidateInput validates arguments and options according to a specified json schema in action definition.
type Argument ¶
type Argument struct { Name string `yaml:"name"` Title string `yaml:"title"` Description string `yaml:"description"` Type jsonschema.Type `yaml:"type"` RawMap map[string]interface{} }
Argument stores command arguments declaration.
func (*Argument) JSONSchema ¶ added in v0.1.2
JSONSchema returns argument json schema definition.
func (*Argument) UnmarshalYAML ¶ added in v0.1.2
UnmarshalYAML implements yaml.Unmarshaler to parse Argument.
type ArgumentsList ¶
type ArgumentsList []*Argument
ArgumentsList is used for custom yaml parsing of arguments list.
func (*ArgumentsList) JSONSchema ¶ added in v0.1.2
func (l *ArgumentsList) JSONSchema() (map[string]interface{}, []string)
JSONSchema collects all arguments json schema definition and also returns fields that are required.
func (*ArgumentsList) UnmarshalYAML ¶
func (l *ArgumentsList) UnmarshalYAML(nodeList *yaml.Node) (err error)
UnmarshalYAML implements yaml.Unmarshaler to parse for ArgumentsList.
type ChainImageBuildResolver ¶ added in v0.1.2
type ChainImageBuildResolver []ImageBuildResolver
ChainImageBuildResolver is a image build resolver that takes first available image in the chain.
func (ChainImageBuildResolver) ImageBuildInfo ¶ added in v0.1.2
func (r ChainImageBuildResolver) ImageBuildInfo(image string) *types.BuildDefinition
ImageBuildInfo implements ImageBuildResolver.
type ConfigImages ¶ added in v0.1.0
type ConfigImages map[string]*types.BuildDefinition
ConfigImages is a container to parse launchr config in yaml format.
type ContainerNameProvider ¶ added in v0.3.0
ContainerNameProvider provides an ability to generate a random container name
func (ContainerNameProvider) Get ¶ added in v0.3.0
func (p ContainerNameProvider) Get(name string) string
Get generates a new container name
type ContainerRunEnvironment ¶ added in v0.1.2
type ContainerRunEnvironment interface { RunEnvironment // SetContainerNameProvider sets container name provider. SetContainerNameProvider(ContainerNameProvider) // AddImageBuildResolver adds an image build resolver to a chain. AddImageBuildResolver(ImageBuildResolver) }
ContainerRunEnvironment is an interface for container run environments.
type DecorateWithFn ¶ added in v0.1.2
DecorateWithFn is a type alias for functions accepted in a Manager.Decorate interface method.
func WithContainerRunEnvironmentConfig ¶ added in v0.1.2
func WithContainerRunEnvironmentConfig(cfg launchr.Config, prefix string) DecorateWithFn
WithContainerRunEnvironmentConfig configures a ContainerRunEnvironment.
type DefAction ¶ added in v0.1.2
type DefAction struct { Title string `yaml:"title"` Description string `yaml:"description"` Arguments ArgumentsList `yaml:"arguments"` Options OptionsList `yaml:"options"` Command StrSliceOrStr `yaml:"command"` Image string `yaml:"image"` Build *types.BuildDefinition `yaml:"build"` ExtraHosts StrSlice `yaml:"extra_hosts"` Env EnvSlice `yaml:"env"` User string `yaml:"user"` }
DefAction holds action configuration
func (*DefAction) JSONSchema ¶ added in v0.1.2
func (a *DefAction) JSONSchema() jsonschema.Schema
JSONSchema returns jsonschema for the arguments and options of the action.
func (*DefAction) UnmarshalYAML ¶ added in v0.1.2
UnmarshalYAML implements yaml.Unmarshaler to parse action definition.
type Definition ¶ added in v0.1.2
Definition is a representation of an action file
func CreateFromYaml ¶
func CreateFromYaml(r io.Reader) (*Definition, error)
CreateFromYaml creates an action file definition from yaml configuration. It returns pointer to Definition or nil on error.
func CreateFromYamlTpl ¶
func CreateFromYamlTpl(b []byte) (*Definition, error)
CreateFromYamlTpl creates an action file definition from yaml configuration as CreateFromYaml but considers that it has unescaped template values.
func (*Definition) Content ¶ added in v0.1.2
func (d *Definition) Content() ([]byte, error)
Content implements Loader interface.
func (*Definition) Load ¶ added in v0.1.2
func (d *Definition) Load(_ LoadContext) (*Definition, error)
Load implements Loader interface.
func (*Definition) LoadRaw ¶ added in v0.1.2
func (d *Definition) LoadRaw() (*Definition, error)
LoadRaw implements Loader interface.
func (*Definition) UnmarshalYAML ¶ added in v0.1.2
func (d *Definition) UnmarshalYAML(node *yaml.Node) (err error)
UnmarshalYAML implements yaml.Unmarshaler to parse action definition.
type Discovery ¶
Discovery finds action files and parses them.
func NewYamlDiscovery ¶
NewYamlDiscovery creates an instance of action discovery.
type EnvSlice ¶
type EnvSlice []string
EnvSlice is an array of env vars or key-value.
func (*EnvSlice) UnmarshalYAML ¶
UnmarshalYAML implements yaml.Unmarshaler to parse env []string or map[string]string.
type ImageBuildResolver ¶ added in v0.1.2
type ImageBuildResolver interface { // ImageBuildInfo takes image as name and provides build definition for that. ImageBuildInfo(image string) *types.BuildDefinition }
ImageBuildResolver is an interface to resolve image build info from its source.
type LaunchrConfigImageBuildResolver ¶ added in v0.1.2
type LaunchrConfigImageBuildResolver struct {
// contains filtered or unexported fields
}
LaunchrConfigImageBuildResolver is a resolver of image build in launchr config file.
func (LaunchrConfigImageBuildResolver) ImageBuildInfo ¶ added in v0.1.2
func (r LaunchrConfigImageBuildResolver) ImageBuildInfo(image string) *types.BuildDefinition
ImageBuildInfo implements ImageBuildResolver.
type LoadContext ¶ added in v0.2.1
type LoadContext struct {
Action *Action
}
LoadContext stores relevant and isolated data needed for processors.
type LoadProcessor ¶
type LoadProcessor interface { // Process gets an input action file data and returns a processed result. Process(LoadContext, []byte) ([]byte, error) }
LoadProcessor is an interface for processing input on load.
func NewPipeProcessor ¶
func NewPipeProcessor(p ...LoadProcessor) LoadProcessor
NewPipeProcessor creates a new processor containing several processors that handles input consequentially.
type Loader ¶
type Loader interface { // Content returns the raw file content. Content() ([]byte, error) // Load parses Content to a Definition with substituted values. Load(LoadContext) (*Definition, error) // LoadRaw parses Content to a Definition raw values. Template strings are escaped. LoadRaw() (*Definition, error) }
Loader is an interface for loading an action file.
type Manager ¶ added in v0.0.9
type Manager interface { launchr.Service // All returns all actions copied and decorated. All() map[string]*Action // AllRef returns all original action values from the storage. // Use it only if you need to read-only actions without allocations. It may be unsafe to read/write the map. // If you need to run actions, use Get or All, it will provide configured for run Action. AllRef() map[string]*Action // Get returns a copy of an action from the manager with default decorators. Get(id string) (*Action, bool) // GetRef returns an original action value from the storage. GetRef(id string) (*Action, bool) // Decorate decorates an action with given behaviors and returns its copy. // If functions withFn are not provided, default functions are applied. Decorate(a *Action, withFn ...DecorateWithFn) *Action // Add saves an action in the manager. Add(*Action) // DefaultRunEnvironment provides the default action run environment. DefaultRunEnvironment() RunEnvironment // Run executes an action in foreground. Run(ctx context.Context, a *Action) (RunInfo, error) // RunBackground executes an action in background. RunBackground(ctx context.Context, a *Action) (RunInfo, chan error) // RunInfoByAction returns all running actions by action id. RunInfoByAction(aid string) []RunInfo // RunInfoByID returns an action matching run id. RunInfoByID(id string) (RunInfo, bool) }
Manager handles actions and its execution.
func NewManager ¶ added in v0.0.9
func NewManager(withFns ...DecorateWithFn) Manager
NewManager constructs a new action manager.
type Option ¶
type Option struct { Name string `yaml:"name"` Shorthand string `yaml:"shorthand"` // @todo test definition, validate, catch panic if overlay, add to readme. Title string `yaml:"title"` Description string `yaml:"description"` Type jsonschema.Type `yaml:"type"` Default interface{} `yaml:"default"` Required bool `yaml:"required"` // @todo that conflicts with json schema object definition RawMap map[string]interface{} }
Option stores command options declaration.
func (*Option) JSONSchema ¶ added in v0.1.2
JSONSchema returns json schema definition of an option.
func (*Option) UnmarshalYAML ¶ added in v0.1.2
UnmarshalYAML implements yaml.Unmarshaler to parse Option.
type OptionsList ¶
type OptionsList []*Option
OptionsList is used for custom yaml parsing of options list.
func (*OptionsList) JSONSchema ¶ added in v0.1.2
func (l *OptionsList) JSONSchema() (map[string]interface{}, []string)
JSONSchema collects all options json schema definition and also returns fields that are required.
func (*OptionsList) UnmarshalYAML ¶
func (l *OptionsList) UnmarshalYAML(nodeList *yaml.Node) (err error)
UnmarshalYAML implements yaml.Unmarshaler to parse OptionsList.
type RunEnvironment ¶ added in v0.1.2
type RunEnvironment interface { // Init prepares the run environment. Init() error // Execute runs action a in the environment and operates with IO through streams. Execute(ctx context.Context, a *Action) error // Close does wrap up operations. Close() error }
RunEnvironment is a common interface for all action run environments.
func NewContainerEnvironment ¶ added in v0.1.2
func NewContainerEnvironment(t driver.Type) RunEnvironment
NewContainerEnvironment creates a new action container run environment.
func NewDockerEnvironment ¶ added in v0.1.2
func NewDockerEnvironment() RunEnvironment
NewDockerEnvironment creates a new action Docker environment.
type RunEnvironmentFlags ¶ added in v0.3.0
type RunEnvironmentFlags interface { RunEnvironment // FlagsDefinition provides definitions for action environment specific flags. FlagsDefinition() OptionsList // UseFlags sets environment configuration. UseFlags(flags TypeOpts) error }
RunEnvironmentFlags is an interface to define environment specific runtime configuration.
type StrSlice ¶
type StrSlice []string
StrSlice is an array of strings for command execution.
func (*StrSlice) UnmarshalYAML ¶
UnmarshalYAML implements yaml.Unmarshaler to parse a string or a list of strings.
type StrSliceOrStr ¶ added in v0.1.2
type StrSliceOrStr []string
StrSliceOrStr is an array of strings for command execution.
func (*StrSliceOrStr) UnmarshalYAML ¶ added in v0.1.2
func (l *StrSliceOrStr) UnmarshalYAML(n *yaml.Node) (err error)
UnmarshalYAML implements yaml.Unmarshaler to parse a string or a list of strings.