config

package
v0.11.27 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: GPL-3.0 Imports: 40 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

View Source
const MaxImportFileSize = 10 * 1024 * 1024

MaxImportFileSize is the maximum size of an imported file (10MB)

Variables

View Source
var (
	ErrCacheWriterFailed      = errors.New("failed to create cache writer")
	ErrCacheDirCreationFailed = errors.New("failed to create cache dir")
	ErrCacheStreamCopyFailed  = errors.New("failed to copy buffer for cache")
	ErrFailedToGetFromCache   = errors.New("failed to get from cache")
	ErrFailedToReadFromCache  = errors.New("failed to read from cache location")
	ErrFailedToParse          = errors.New("failed to unmarshal from stream")
	ErrFileNotInCache         = errors.New("file does not exist in cache")
	ErrFailedToWriteImport    = errors.New("failed to write import")
)
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 ErrHashMismatch = errors.New("integrity hash mismatch")

ErrHashMismatch occurs when a downloaded file's hash does not match the expected hash

View Source
var ErrImportFileFailed = errors.New("import file failed")

ErrImportFileFailed occurs when a file import entry fails to be fetched or written

View Source
var ErrImportKeyClash = errors.New("imported file contains a clash")
View Source
var ErrPathTraversal = errors.New("dest path traverses outside project root")

ErrPathTraversal occurs when a dest path escapes the project root

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)

func VerifyHash added in v0.9.12

func VerifyHash(content []byte, hashTyp schema.HashType, expectedDigest string) error

VerifyHash checks that the SHA-256 hash of content matches the expected hash. expectedHash must be in the format "algorithm:hex_digest", e.g. "sha256:236d1b7e77d01309bf704065c74b3e4baf589dac240a7b199c4c22e9fc4630e6" Currently only sha256 is supported.

Types

type Cache added in v0.11.5

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

Cache struct manages the storage and retrieval of configuration items/import files in a globally accessible cache directory

func NewCache added in v0.11.5

func NewCache() *Cache

func (*Cache) Get added in v0.11.5

func (c *Cache) Get(file schema.ImportEntry) (*ConfigDefinition, error)

Get returns a successful io.Reader if content exists else an error

func (*Cache) Store added in v0.11.5

func (c *Cache) Store(fullPath string, content io.Reader) error

Store creates a cache entry in the provided path in base62 encoded string for the path writes the contents from io.Reader by copying the reader NB: the caller needs to pass in a multiplexed or teed reader in first as the stream will be emptied once read

func (*Cache) WithFsOps added in v0.11.5

func (c *Cache) WithFsOps(fo fsOps) *Cache

func (*Cache) WithWriteImport added in v0.11.5

func (c *Cache) WithWriteImport(wi func(entry schema.ImportEntry, content io.ReadCloser) error) *Cache

type CacheOpt added in v0.11.5

type CacheOpt func(*Cache)

type Config

type Config struct {
	SourceFile string
	Import     ImportList
	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.
	// Supports both plain strings (backward compatible config imports) and
	// objects with src/hash/dest fields. Entries with a dest field are treated
	// as file imports and written to disk; all others are config imports.
	Import ImportList `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 schema.ImportEntry) (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(entry schema.ImportEntry) (*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(writeImport func(entry schema.ImportEntry, content io.ReadCloser) error, cacheStore func(fullPath string, content io.Reader) error) (*ConfigDefinition, error)

func (*GitSource) File added in v0.9.12

func (gs *GitSource) File() (io.ReadCloser, 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 ImportList added in v0.9.12

type ImportList []schema.ImportEntry

ImportList is a list of ImportEntry items supporting heterogeneous YAML (strings and objects).

func (ImportList) JSONSchema added in v0.9.12

func (ImportList) JSONSchema() *jsonschema.Schema

JSONSchema provides the JSON schema for ImportList, allowing both string and object items.

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, extraImports ...string) (*Config, error)

Load loads and parses requested config file.

The first argument is the primary config file. Any additional imports are loaded afterwards and merged with override precedence, matching the behaviour of CLI-supplied `--import` entries.

NOTE: it then recursively builds a full config definition based on all the imports

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 VariablesVarMapType `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
	// The legacy string fields preserve API compatibility. Effective selections
	// are stored as ordered slices so quoted paths and repeated directives retain
	// their original boundaries and precedence.
	UserKnownHostsFile    string
	SystemKnownHostsFile  string
	UserKnownHostsFiles   []string
	SystemKnownHostsFiles []string
	StrictHostKeyChecking 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 VariablesVarMapType `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 VariablesVarMapType added in v0.11.1

type VariablesVarMapType map[string]any

EnvVarMapType is the custom reflection type for schema generation

func (VariablesVarMapType) JSONSchema added in v0.11.1

func (VariablesVarMapType) JSONSchema() *jsonschema.Schema

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