config

package
v0.9.7 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2025 License: GPL-3.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GitSshCommandVar = "GIT_SSH_COMMAND"
	GitSshPassphrase = "GIT_SSH_PASSPHRASE"
)
View Source
const EIRCTL_DOCKER_HOST string = `EIRCTL_DOCKER_HOST`

EIRCTL_DOCKER_HOST is the environment variable name to point to the docker.sock for DinD mounting if not specified it will default to /var/run/docker.sock

Variables

View Source
var (
	ErrIncorrectlyFormattedGit   = errors.New("incorrectly formatted git import, must satisfy this regex `^git::(ssh|https?|file)://(.+?)//([^?]+)(?:\\?ref=([^&]+))?$`")
	ErrGitTagBranchRevisionWrong = errors.New("tag or branch or revision was not found")
	ErrGitOperation              = errors.New("git operation failed")
)
View Source
var DefaultContainerExcludes = []string{"PATH", "HOME", "TMPDIR"}
View Source
var DefaultFileNames = []string{"eirctl.yaml", "tasks.yaml"}

DefaultFileNames is default names for tasks' files

View Source
var ErrBuildContextIncorrect = errors.New("build context properties are incorrect")
View Source
var ErrConfigNotFound = errors.New("config file not found")

ErrConfigNotFound occurs when requested config file does not exists

View Source
var ErrImportKeyClash = errors.New("imported file contains a clash")
View Source
var ErrStageBuildFailure = errors.New("stage build failed")
View Source
var ErrValidation = errors.New("validation failed")

Functions

func IsGit added in v0.7.1

func IsGit(raw string) bool

func SSHKeySigner added in v0.9.0

func SSHKeySigner(key []byte) (ssh.Signer, error)

Types

type Config

type Config struct {
	SourceFile string
	Import     []string
	Contexts   map[string]*runner.ExecutionContext
	Pipelines  map[string]*scheduler.ExecutionGraph
	Tasks      map[string]*task.Task
	Watchers   map[string]*watch.Watcher

	Quiet, Debug, Verbose, DryRun, Summary bool
	Output                                 output.OutputEnum

	Variables *variables.Variables
	// Options are computed cli or other API inputs
	//
	Options struct {
		GraphOrientationLeftRight bool
		InitDir                   string
		InitNoPrompt              bool
	}
	// Generate Options
	Generate *Generator
}

Config is a eirctl internal config structure

func NewConfig

func NewConfig() *Config

NewConfig creates new config instance

type ConfigDefinition

type ConfigDefinition struct {
	// Import is a list of additional resources to bring into the main config
	// these can be remote or local resources
	Import []string `mapstructure:"import" yaml:"import" json:"import,omitempty" jsonschema:"anyOf_required=import"`
	// Contexts is a map of contexts to use
	// for specific tasks
	Contexts map[string]*ContextDefinition `mapstructure:"contexts" yaml:"contexts" json:"contexts,omitempty" jsonschema:"anyOf_required=contexts"`
	// Pipelines are a set of tasks wrapped in additional run conditions
	// e.g. depends on or allow failure
	Pipelines map[string][]*PipelineDefinition `mapstructure:"pipelines" yaml:"pipelines" json:"pipelines,omitempty" jsonschema:"anyOf_required=pipelines"`
	// Tasks are the most basic building blocks of eirctl
	Tasks    map[string]*TaskDefinition    `mapstructure:"tasks" yaml:"tasks" json:"tasks,omitempty" jsonschema:"anyOf_required=tasks"`
	Watchers map[string]*WatcherDefinition `mapstructure:"watchers" yaml:"watchers" json:"watchers,omitempty"`
	Debug    bool                          `json:"debug,omitempty"`
	DryRun   bool                          `json:"dry_run,omitempty"`
	Summary  bool                          `json:"summary,omitempty"`
	Verbose  bool                          `json:"verbose,omitempty"`
	// Output sets globally the output type for all tasks and pipelines
	//
	Output string `mapstructure:"output" yaml:"output" json:"output,omitempty" jsonschema:"enum=raw,enum=cockpit,enum=prefixed"`
	// Variables are the top most variables and will be merged and overwritten with lower level
	// specifications.
	// e.g. variable of Version=123
	// will be overwritten by a variables specified in this order, lowest takes the highest precedence
	// - context
	// - pipeline
	// - task
	// - commandline.
	// Variables can be used inside templating using the text/template go package
	Variables EnvVarMapType `mapstructure:"variables" yaml:"variables" json:"variables,omitempty"`
	// Generator defines the options for the desired CI yaml generation
	// Currently these are just map[string]any so that the user can specify the desired behaviour
	// NOTE: will provide no build time safety
	Generator *Generator `mapstructure:"ci_meta,omitempty" yaml:"ci_meta,omitempty" json:"ci_meta,omitempty"`
}

ConfigDefinition holds the top most config definition this can be parsed from a yaml, json, toml files/mediaTypes

Note: works the same way for local/remote config resources correct content-type or file extension must be specified to successfully decode/unmarshal into type

type ConfigFunc added in v0.7.1

type ConfigFunc func(cl *Loader, file string) (bool, *ConfigDefinition, error)

type ContextDefinition

type ContextDefinition struct {
	SourceFile string `jsonschema:"-"`
	Dir        string `mapstructure:"dir" yaml:"dir" json:"dir,omitempty"`
	// Up runs once at the beginning of the usage of the context
	// These are run in the mvdn.sh on the host
	Up []string `mapstructure:"up" yaml:"up" json:"up,omitempty"`
	// Down runs once at the end of the usage of the context
	// These are run in the mvdn.sh on the host
	Down []string `mapstructure:"down" yaml:"down" json:"down,omitempty"`
	// Before runs any commands prior to the tasks' commands
	// These are run in the mvdn.sh on the host
	Before []string `mapstructure:"before" yaml:"before" json:"before,omitempty"`
	// After runs after the commads of the task that use this context have run
	// NB: these are run irrespective of the state of the task, this can be useful
	// for clean up operations and similar.
	// These are run in the mvdn.sh on the host
	After []string `mapstructure:"after" yaml:"after" json:"after,omitempty"`
	// Env is supplied from config file definition and is merged with the
	// current process environment variables list
	//
	// User supplied env map will overwrite any keys inside the process env
	// TODO: check this is desired behaviour
	Env EnvVarMapType `mapstructure:"env" yaml:"env" json:"env,omitempty"` // jsonschema:"anyof_type=string;integer;number;bool"
	// Envfile is a special block for use in executables that support file mapping
	// e.g. podman or docker
	//
	// Note: Envfile in the container context will ignore the generate flag
	// it will however respect all the other directives of include/exclude and modify operations
	Envfile *utils.Envfile `mapstructure:"envfile" yaml:"envfile,omitempty" json:"envfile,omitempty"`
	// Variables
	Variables EnvVarMapType `mapstructure:"variables" yaml:"variables" json:"variables,omitempty"`
	// Executable block holds the exec info
	Executable *utils.Binary `mapstructure:"executable" yaml:"executable" json:"executable,omitempty"`
	// Quote is the quote char to use when parsing commands into executables like docker
	Quote string `mapstructure:"quote" yaml:"quote" json:"quote,omitempty"`
	// Container is the specific context for containers
	// only available to docker API compliant implementations
	//
	// e.g. docker and podman
	//
	// The aim is to remove some of the boilerplate away from the existing more
	// generic context and introduce a specific context for tasks run in containers.
	//
	// Example:
	//
	// “`yaml
	// container:
	//   image:
	//     name: alpine
	//     # entrypoint: ""
	//     # shell: sh # default sh
	//     # args: nil
	// “`
	Container *utils.Container `mapstructure:"container" yaml:"container,omitempty" json:"container,omitempty"`
}

type EnvVarMapType

type EnvVarMapType map[string]string

EnvVarMapType is the custom reflection type for schema generation

func (EnvVarMapType) JSONSchema

func (EnvVarMapType) JSONSchema() *jsonschema.Schema

type Generator

type Generator struct {
	// Version sets the version of eirctl to use for generation of default tasks, defaults to the current version of the binary
	Version       string         `mapstructure:"version" yaml:"version,omitempty" json:"version,omitempty"`
	TargetOptions map[string]any `mapstructure:"targetOpts" yaml:"targetOpts,omitempty" json:"targetOpts,omitempty"`
}

type GitSource added in v0.7.1

type GitSource struct {
	SshConfig *SSHConfigAuth
	// contains filtered or unexported fields
}

func NewGitSource added in v0.7.1

func NewGitSource(raw string) (*GitSource, error)

NewGitSource converts an import string of type git to a parseable git clone and checkout object

func (*GitSource) Clone added in v0.7.1

func (gs *GitSource) Clone() (err error)

Clone calls the git clone operation

func (*GitSource) Config added in v0.7.1

func (gs *GitSource) Config() (*ConfigDefinition, error)

func (*GitSource) GitCheckoutStr added in v0.7.1

func (gs *GitSource) GitCheckoutStr() string

func (*GitSource) Tag added in v0.7.1

func (gs *GitSource) Tag() string

func (*GitSource) WithRepo added in v0.7.1

func (gs *GitSource) WithRepo(repo *git.Repository)

func (*GitSource) YamlPath added in v0.7.1

func (gs *GitSource) YamlPath() string

type Loader

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

Loader reads and parses config files

It recursively imports file/urls/git-paths via the import statement

func NewConfigLoader

func NewConfigLoader(dst *Config) Loader

NewConfigLoader is Loader constructor

func (*Loader) Dir

func (c *Loader) Dir() string

Dir

func (*Loader) Load

func (cl *Loader) Load(file string) (*Config, error)

Load loads and parses requested config file

func (*Loader) LoadGlobalConfig

func (cl *Loader) LoadGlobalConfig() (*Config, error)

LoadGlobalConfig load global config file - ~/.eirctl/config.yaml

func (*Loader) ResolveDefaultConfigFile

func (cl *Loader) ResolveDefaultConfigFile() (file string, err error)

func (*Loader) Validate added in v0.6.1

func (cl *Loader) Validate() (*Config, error)

Validate checks the built config for any missed references

func (*Loader) WithDir

func (c *Loader) WithDir(dir string) *Loader

func (*Loader) WithStrictDecoder

func (c *Loader) WithStrictDecoder() *Loader

type PipelineDefinition

type PipelineDefinition struct {
	SourceFile string `jsonschema:"-"`
	// Name is the friendly name to give to pipeline
	Name string `mapstructure:"name" yaml:"name" json:"name,omitempty"`
	// Condition evaluates whether to run this task or not within a given Schedule (Pipeline).
	// This always runs in the default Executor and does not inherit any pipeline or task variables and environment.
	//
	// The condition must be a valid shell syntax and returns a non-zero (0) exit code for the task to be skipped inside a pipeline.
	Condition string `mapstructure:"condition" yaml:"condition" json:"condition,omitempty"`
	// Task is the pointer to the task to run
	// it has to match the key in tasks map
	Task string `mapstructure:"task" yaml:"task,omitempty" json:"task,omitempty" jsonschema:"oneof_required=task"`
	// Pipeline is the name of the pipeline to run
	// Task and Pipeline are mutually exclusive
	// if both are specified task will win
	Pipeline string `mapstructure:"pipeline" yaml:"pipeline,omitempty" json:"pipeline,omitempty" jsonschema:"oneof_required=pipeline"`
	// DependsOn
	DependsOn schema.StringSlice `mapstructure:"depends_on" yaml:"depends_on,omitempty" json:"depends_on,omitempty" jsonschema:"oneof_type=string;array"`
	// AllowFailure
	AllowFailure bool `mapstructure:"allow_failure" yaml:"allow_failure,omitempty" json:"allow_failure,omitempty"`
	// Dir is the place where to run the task(s) in.
	// If empty - currentDir is used
	Dir string `mapstructure:"dir" yaml:"dir,omitempty" json:"dir,omitempty"`
	// Env is the Key: Value map of env vars to inject into the tasks within this pipeline
	Env EnvVarMapType `mapstructure:"env" yaml:"env,omitempty" json:"env,omitempty"`
	// EnvFile definition to set on the stage (eirctl pipeline)
	//
	// If a list is supplied than the order in which they are supplied will be respected
	// later elements in the list will overwrite keys specified previously
	Envfile *utils.Envfile `mapstructure:"envfile" yaml:"envfile,omitempty" json:"envfile,omitempty"`
	// Variables is the Key: Value map of vars vars to inject into the tasks
	Variables EnvVarMapType `mapstructure:"variables" yaml:"variables,omitempty" json:"variables,omitempty"`
	// Generator PipelineLevel
	Generator map[string]any `mapstructure:"ci_meta,omitempty" yaml:"ci_meta,omitempty" json:"ci_meta,omitempty"`
}

type SSHConfigAuth added in v0.7.1

type SSHConfigAuth struct {
	IdentityFile string
	ConfigFile   string
	User         string
	Port         string
	Hostname     string
}

type TaskDefinition

type TaskDefinition struct {
	SourceFile  string `jsonschema:"-"`
	Name        string `mapstructure:"name" yaml:"name,omitempty" json:"name,omitempty"`
	Description string `mapstructure:"description" yaml:"description,omitempty" json:"description,omitempty"`
	Condition   string `mapstructure:"condition" yaml:"condition,omitempty" json:"condition,omitempty"`
	// Command is the actual command to run in either a specified executable or
	// in mvdn.shell
	Command schema.StringSlice `mapstructure:"command" yaml:"command" json:"command" jsonschema:"oneof_type=string;array"`
	// After runs after the commads of the task have completed
	// If a task errors these are not run
	After []string `mapstructure:"after" yaml:"after,omitempty" json:"after,omitempty"`
	// Before runs before the commads of the task have run
	Before []string `mapstructure:"before" yaml:"before,omitempty" json:"before,omitempty"`
	// Context is the pointer to the key in the context map
	// it must exist else it will fallback to default context
	Context string `mapstructure:"context" yaml:"context,omitempty" json:"context,omitempty"`
	// Variations is per execution env var mutator
	// the number of variations in the list defines the number of times the command will be run
	// if using the default executor, see `ResetContext` if you need
	Variations []map[string]string `mapstructure:"variations" yaml:"variations,omitempty" json:"variations,omitempty"`
	// Dir to run the command from
	// If empty defaults to current directory
	Dir          string         `mapstructure:"dir" yaml:"dir,omitempty" json:"dir,omitempty"`
	Timeout      *time.Duration `mapstructure:"timeout" yaml:"timeout,omitempty" json:"timeout,omitempty"`
	AllowFailure bool           `mapstructure:"allow_failure" yaml:"allow_failure,omitempty" json:"allow_failure,omitempty"`
	Interactive  bool           `mapstructure:"interactive" yaml:"interactive,omitempty" json:"interactive,omitempty"`
	Artifacts    *task.Artifact `mapstructure:"artifacts" yaml:"artifacts,omitempty" json:"artifacts,omitempty"`
	// Env key=value map that will overwrite everything set at a higher level
	Env EnvVarMapType `mapstructure:"env" yaml:"env,omitempty" json:"env,omitempty"`
	// EnvFile is an object points to a path of an env file.
	//
	// This file is read dynamically each time before the task execution.
	// Any keys specified in the `env` key=value map will overwrite those set in the env file.
	//
	// The precedence of environment setting can be summarized as below
	// Context < Pipeline < Task
	//
	// This means that whilst all env vars will be merged downwards to the task
	// i.e. key specified at a task level will overwrite those set at any level above.
	//
	// Setting a key in an envfile with the same name will be overwritten by an `env.key`.
	Envfile *utils.Envfile `mapstructure:"envfile" yaml:"envfile,omitempty" json:"envfile,omitempty"`
	// Variables merged with others if any already priovided
	// These will overwrite any previously set keys
	Variables EnvVarMapType `mapstructure:"variables" yaml:"variables,omitempty" json:"variables,omitempty"`
	// ResetContext ensures each invocation of the variation is run with a Reset on the executor.
	// Currently only applies to a default executor and when run in variations.
	ResetContext bool `mapstructure:"reset_context" yaml:"reset_context,omitempty" json:"reset_context,omitempty" jsonschema:"default=false"`
	// Generator is the CI meta properties that will only be used during a generate process
	Generator map[string]any `mapstructure:"ci_meta,omitempty" yaml:"ci_meta,omitempty" json:"ci_meta,omitempty"`
	// Required specifies any required inputs into the task
	Required *task.RequiredInput `yaml:"required,omitempty" json:"required,omitempty"`
}

type WatcherDefinition

type WatcherDefinition struct {
	Events    []string          `mapstructure:"events" yaml:"events" json:"events"`
	Watch     []string          `mapstructure:"watch" yaml:"watch" json:"watch"`
	Exclude   []string          `mapstructure:"exclude" yaml:"exclude,omitempty" json:"exclude,omitempty"`
	Task      string            `mapstructure:"task" yaml:"task" json:"task"`
	Variables map[string]string `mapstructure:"variables" yaml:"variables,omitempty" json:"variables,omitempty"`
}

Jump to

Keyboard shortcuts

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