action

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2023 License: Apache-2.0 Imports: 30 Imported by: 12

Documentation

Overview

Package action provides implementations of discovering and running actions.

Index

Constants

View Source
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

func CobraImpl(cmd *Command, appCli cli.Streams, cfg launchr.Config, group *cobra.Group) (*cobra.Command, error)

CobraImpl returns cobra command implementation for an action command.

func ConfigImage added in v0.1.0

func ConfigImage(cfg launchr.Config, image string) *types.BuildDefinition

ConfigImage extends launchr.Config functionality and parses images definition.

func ConvertInputToMap added in v0.0.9

func ConvertInputToMap(cmd *Command, conf *Action) map[string]interface{}

ConvertInputToMap 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.

Types

type Action

type Action struct {
	Version string        `yaml:"version"`
	Action  *ActionConfig `yaml:"action"`
}

Action is a representation of an action yaml file

func CreateFromYaml

func CreateFromYaml(r io.Reader) (*Action, error)

CreateFromYaml creates action definition from yaml configuration. It returns pointer to Action or nil on error.

func CreateFromYamlTpl

func CreateFromYamlTpl(b []byte) (*Action, error)

CreateFromYamlTpl creates action definition from yaml configuration as CreateFromYaml but considers that it has unescaped template values.

func (*Action) Content added in v0.0.9

func (a *Action) Content() ([]byte, error)

Content implements Loader interface.

func (*Action) Load added in v0.0.9

func (a *Action) Load() (*Action, error)

Load implements Loader interface.

func (*Action) LoadRaw added in v0.0.9

func (a *Action) LoadRaw() (*Action, error)

LoadRaw implements Loader interface.

type ActionConfig added in v0.0.9

type ActionConfig struct {
	Title       string                 `yaml:"title"`
	Description string                 `yaml:"description"`
	Arguments   ArgumentsList          `yaml:"arguments"`
	Options     OptionsList            `yaml:"options"`
	Command     StrSlice               `yaml:"command"`
	Image       string                 `yaml:"image"`
	Build       *types.BuildDefinition `yaml:"build"`
	ExtraHosts  []string               `yaml:"extra_hosts"`
	Env         EnvSlice               `yaml:"env"`
}

ActionConfig holds action configuration

func (*ActionConfig) BuildDefinition added in v0.0.9

func (a *ActionConfig) BuildDefinition(wd string) *types.BuildDefinition

BuildDefinition provides resolved image build info

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.

type ArgumentsList

type ArgumentsList []*Argument

ArgumentsList is used for custom yaml parsing of arguments list.

func (*ArgumentsList) UnmarshalYAML

func (l *ArgumentsList) UnmarshalYAML(nodeList *yaml.Node) (err error)

UnmarshalYAML implements yaml.Unmarshaler to parse for ArgumentsList.

type Command

type Command struct {
	WorkingDir  string
	Filepath    string
	CommandName string

	Loader Loader

	InputArgs    map[string]string
	InputOptions map[string]interface{}
	// contains filtered or unexported fields
}

Command is an action with a contextual name, working directory path and a runtime context such as input arguments and options.

func (*Command) Action

func (cmd *Command) Action() *ActionConfig

Action returns action with replaces variables.

func (*Command) ActionRaw added in v0.0.9

func (cmd *Command) ActionRaw() ([]byte, error)

ActionRaw returns encoded action.

func (*Command) Compile

func (cmd *Command) Compile() error

Compile loads an action with replaced arguments and options.

func (*Command) Dir

func (cmd *Command) Dir() string

Dir returns an action file directory.

func (*Command) SetArgsInput

func (cmd *Command) SetArgsInput(args []string)

SetArgsInput saves passed cobra arguments for later processing in run, templates, etc.

func (*Command) SetOptsInput

func (cmd *Command) SetOptsInput(options map[string]interface{})

SetOptsInput saves passed cobra flags for later processing in run, templates, etc.

func (*Command) ValidateInput

func (cmd *Command) ValidateInput() error

ValidateInput validates arguments and options according to a specified json schema in action definition.

type ConfigImages added in v0.1.0

type ConfigImages map[string]*types.BuildDefinition

ConfigImages is a container to parse launchr config with yaml.

type Discovery

type Discovery interface {
	Discover() ([]*Command, error)
}

Discovery finds action files and parses them.

func NewYamlDiscovery

func NewYamlDiscovery(fs fs.FS) Discovery

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

func (l *EnvSlice) UnmarshalYAML(n *yaml.Node) (err error)

UnmarshalYAML implements yaml.Unmarshaler to parse env []string or map[string]string.

type Executor

type Executor interface {
	Exec(ctx context.Context, cli cli.Streams, cmd *Command) error
	Close() error
}

Executor is a common interface for all container executors.

func NewContainerExecutor

func NewContainerExecutor(t driver.Type) (Executor, error)

NewContainerExecutor creates a new action executor in container environment.

func NewDockerExecutor

func NewDockerExecutor() (Executor, error)

NewDockerExecutor creates a new action executor in Docker environment.

type LoadProcessor

type LoadProcessor interface {
	Process([]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() ([]byte, error)
	Load() (*Action, error)
	LoadRaw() (*Action, error)
}

Loader is an interface for loading an action file.

type Manager added in v0.0.9

type Manager interface {
	launchr.Service
	Add(*Command)
	All() map[string]*Command
}

Manager handles actions.

func NewManager added in v0.0.9

func NewManager() Manager

NewManager constructs a new action manager.

type Option

type Option struct {
	Name        string          `yaml:"name"`
	Title       string          `yaml:"title"`
	Description string          `yaml:"description"`
	Type        jsonschema.Type `yaml:"type"`
	Default     interface{}     `yaml:"default"`
	Required    bool            `yaml:"required"`
	RawMap      map[string]interface{}
}

Option stores command options declaration.

type OptionsList

type OptionsList []*Option

OptionsList is used for custom yaml parsing of options list.

func (*OptionsList) UnmarshalYAML

func (l *OptionsList) UnmarshalYAML(nodeList *yaml.Node) (err error)

UnmarshalYAML implements yaml.Unmarshaler to parse for OptionsList.

type StrSlice

type StrSlice []string

StrSlice is an array of strings for command execution.

func (*StrSlice) UnmarshalYAML

func (l *StrSlice) UnmarshalYAML(n *yaml.Node) (err error)

UnmarshalYAML implements yaml.Unmarshaler to parse a string or a list of strings.

Jump to

Keyboard shortcuts

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