wharfyml

package
v0.8.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: May 5, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package wharfyml contains code for parsing and validating .wharf-ci.yml files.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInputNameCollision      = errors.New("input variable name is already used")
	ErrInputUnknownType        = errors.New("unknown input type")
	ErrUseOfUndefinedInput     = errors.New("use of undefined input variable")
	ErrInputChoiceUnknownValue = errors.New("default value is missing from values array")
)

Errors related to parsing environments.

View Source
var (
	ErrStepEmpty             = errors.New("missing a step type")
	ErrStepMultipleStepTypes = errors.New("contains multiple step types")
)

Errors related to parsing steps.

View Source
var (
	ErrStepTypeUnknown   = errors.New("unknown step type")
	ErrMissingBuiltinVar = errors.New("missing built-in var")
)

Errors related to parsing step types.

View Source
var (
	ErrInvalidFieldType = errors.New("invalid field type")
	ErrKeyCollision     = errors.New("map key appears more than once")
	ErrKeyEmpty         = errors.New("map key must not be empty")
	ErrKeyNotString     = errors.New("map key must be string")
	ErrMissingDoc       = errors.New("empty document")
	ErrTooManyDocs      = errors.New("only 1 document is allowed")
)

Generic errors related to parsing.

View Source
var (
	ErrMissingRequired = errors.New("missing required field")
)

Errors related to parsing map of nodes.

View Source
var (
	ErrStageEmpty = errors.New("stage is missing steps")
)

Errors related to parsing stages.

View Source
var (
	ErrStageEnvEmpty = errors.New("environment name cannot be empty")
)

Errors related to parsing environments.

View Source
var (
	ErrUnsupportedVarSubType = errors.New("unsupported variable substitution value")
)

Errors specific to performing variable substitution on nodes.

View Source
var (
	ErrUseOfUndefinedEnv = errors.New("use of undefined environment")
)

Errors specific to parsing definitions.

Functions

func Parse

func Parse(reader io.Reader, args Args) (def Definition, errSlice Errors)

Parse will parse the YAML content as a .wharf-ci.yml definition structure. Multiple errors may be returned, one for each validation or parsing error.

func ParseFile

func ParseFile(path string, args Args) (Definition, Errors)

ParseFile will parse the file at the given path. Multiple errors may be returned, one for each validation or parsing error.

Types

type Args

type Args struct {
	Env                string
	VarSource          varsub.Source
	SkipStageFiltering bool
	Inputs             map[string]any
}

Args specify arguments used when parsing the .wharf-ci.yml file, such as what environment to use for variable substitution.

type Definition

type Definition struct {
	Inputs    Inputs
	Envs      map[string]Env
	Env       *Env
	Stages    []Stage
	VarSource varsub.Source
}

Definition is the .wharf-ci.yml build definition structure.

func (*Definition) ListAllSteps

func (d *Definition) ListAllSteps() []Step

ListAllSteps aggregates steps from all stages into a single slice.

Makes Definition comply to the StepLister interface.

type Env

type Env struct {
	Source Pos
	Name   string
	Vars   map[string]VarSubNode
}

Env is an environments definition. Used in the root of the definition.

func (Env) VarSource

func (e Env) VarSource() varsub.Source

VarSource returns a varsub.Source compliant value of the environment variables.

type EnvRef

type EnvRef struct {
	Source Pos
	Name   string
}

EnvRef is a reference to an environments definition. Used in stages.

type Errors

type Errors []error

Errors is a slice of errors.

func ParseVarFiles

func ParseVarFiles(currentDir string) (varsub.Source, Errors)

ParseVarFiles produces a varsub.Source of *yaml.Node values. The files it checks depends on your OS.

For GNU/Linux:

/etc/iver-wharf/wharf-cmd/wharf-vars.yml
$XDG_CONFIG_HOME/iver-wharf/wharf-cmd/wharf-vars.yml
(if $XDG_CONFIG_HOME is unset) $HOME/.config/iver-wharf/wharf-cmd/wharf-vars.yml

For Windows:

%APPDATA%\iver-wharf\wharf-cmd\wharf-vars.yml

For Darwin (Mac OS X):

$HOME/Library/Application Support/iver-wharf/wharf-cmd/wharf-vars.yml

In addition, this function also checks the current directory and parent directories above it, recursively, for a dotfile variant (.wharf-vars.yml):

./.wharf-vars.yml
../.wharf-vars.yml
../../.wharf-vars.yml
../../..(etc)/.wharf-vars.yml

type Input

type Input interface {
	InputTypeName() string
	InputVarName() string
	DefaultValue() any
	ParseValue(value any) (any, error)
	Pos() Pos
}

Input is an interface that is implemented by all input types.

type InputChoice

type InputChoice struct {
	Source  Pos
	Name    string
	Values  []string
	Default string
}

InputChoice represents a choice of multiple string inputs.

func (InputChoice) DefaultValue

func (i InputChoice) DefaultValue() any

DefaultValue returns the default value for this input variable.

func (InputChoice) InputTypeName

func (InputChoice) InputTypeName() string

InputTypeName returns the name of this input type.

func (InputChoice) InputVarName

func (i InputChoice) InputVarName() string

InputVarName returns the name of this input variable.

func (InputChoice) ParseValue

func (i InputChoice) ParseValue(value any) (any, error)

ParseValue will try to parse the value and return the input-compatible value for this input variable type, or returns an error if the type isn't valid.

func (InputChoice) Pos

func (i InputChoice) Pos() Pos

Pos returns the position of where this variable was defined.

type InputNumber

type InputNumber struct {
	Source  Pos
	Name    string
	Default float64
}

InputNumber represents a number (integer or float) input value.

func (InputNumber) DefaultValue

func (i InputNumber) DefaultValue() any

DefaultValue returns the default value for this input variable.

func (InputNumber) InputTypeName

func (InputNumber) InputTypeName() string

InputTypeName returns the name of this input type.

func (InputNumber) InputVarName

func (i InputNumber) InputVarName() string

InputVarName returns the name of this input variable.

func (InputNumber) ParseValue

func (i InputNumber) ParseValue(value any) (any, error)

ParseValue will try to parse the value and return the input-compatible value for this input variable type, or returns an error if the type isn't valid.

func (InputNumber) Pos

func (i InputNumber) Pos() Pos

Pos returns the position of where this variable was defined.

type InputPassword

type InputPassword struct {
	Source  Pos
	Name    string
	Default string
}

InputPassword represents a string (text) input value, but where the value should be concealed in user interfaces.

func (InputPassword) DefaultValue

func (i InputPassword) DefaultValue() any

DefaultValue returns the default value for this input variable.

func (InputPassword) InputTypeName

func (InputPassword) InputTypeName() string

InputTypeName returns the name of this input type.

func (InputPassword) InputVarName

func (i InputPassword) InputVarName() string

InputVarName returns the name of this input variable.

func (InputPassword) ParseValue

func (i InputPassword) ParseValue(value any) (any, error)

ParseValue will try to parse the value and return the input-compatible value for this input variable type, or returns an error if the type isn't valid.

func (InputPassword) Pos

func (i InputPassword) Pos() Pos

Pos returns the position of where this variable was defined.

type InputString

type InputString struct {
	Source  Pos
	Name    string
	Default string
}

InputString represents a string (text) input value.

func (InputString) DefaultValue

func (i InputString) DefaultValue() any

DefaultValue returns the default value for this input variable.

func (InputString) InputTypeName

func (InputString) InputTypeName() string

InputTypeName returns the name of this input type.

func (InputString) InputVarName

func (i InputString) InputVarName() string

InputVarName returns the name of this input variable.

func (InputString) ParseValue

func (i InputString) ParseValue(value any) (any, error)

ParseValue will try to parse the value and return the input-compatible value for this input variable type, or returns an error if the type isn't valid.

func (InputString) Pos

func (i InputString) Pos() Pos

Pos returns the position of where this variable was defined.

type Inputs

type Inputs map[string]Input

Inputs is a map of Input field definitions, keyed on their names.

func (Inputs) DefaultsVarSource

func (i Inputs) DefaultsVarSource() varsub.Source

DefaultsVarSource returns a varsub.Source of the default values from this .wharf-ci.yml's input definitions.

type Pos

type Pos struct {
	Line   int
	Column int
}

Pos represents a position. Used to declare where an object was defined in the .wharf-ci.yml file. The first line and column starts at 1. The zero value is used to represent an undefined position.

func (Pos) String

func (p Pos) String() string

String implements fmt.Stringer

type PosError

type PosError struct {
	Err    error
	Source Pos
}

PosError is an error type that holds metadata about where the error occurred (line and column).

func (PosError) Error

func (err PosError) Error() string

Error implements the error interface.

func (PosError) Is

func (err PosError) Is(target error) bool

Is implements the interface to support errors.Is.

func (PosError) Unwrap

func (err PosError) Unwrap() error

Unwrap implements the interface to support errors.Unwrap.

type Stage

type Stage struct {
	Pos     Pos
	Name    string
	Envs    []EnvRef
	EnvsPos Pos
	Steps   []Step
}

Stage holds the name, environment filter, and list of steps for this Wharf build stage.

type Step

type Step struct {
	Pos  Pos
	Name string
	Type StepType
}

Step holds the step type and name of this Wharf build step.

type StepContainer

type StepContainer struct {
	// Step type metadata
	Meta StepTypeMeta

	// Required fields
	Image string
	Cmds  []string

	// Optional fields
	OS                    string
	Shell                 string
	SecretName            string
	ServiceAccount        string
	CertificatesMountPath string
}

StepContainer represents a step type for running commands inside a Docker container.

func (StepContainer) StepTypeName

func (StepContainer) StepTypeName() string

StepTypeName returns the name of this step type.

type StepDocker

type StepDocker struct {
	// Step type metadata
	Meta StepTypeMeta

	// Required fields
	File string
	Tag  string

	// Optional fields
	Destination string
	Name        string
	Group       string
	Context     string
	Secret      string
	Registry    string
	AppendCert  bool
	Push        bool
	Args        []string
	SecretName  string
	SecretArgs  []string
}

StepDocker represents a step type for building and pushing Docker images.

func (StepDocker) StepTypeName

func (StepDocker) StepTypeName() string

StepTypeName returns the name of this step type.

type StepHelm

type StepHelm struct {
	// Step type metadata
	Meta StepTypeMeta

	// Required fields
	Chart     string
	Name      string
	Namespace string

	// Optional fields
	Repo         string
	Set          map[string]string
	Files        []string
	ChartVersion string
	HelmVersion  string
	Cluster      string
}

StepHelm represents a step type for installing a Helm chart into a Kubernetes cluster.

func (StepHelm) StepTypeName

func (StepHelm) StepTypeName() string

StepTypeName returns the name of this step type.

type StepHelmPackage

type StepHelmPackage struct {
	// Step type metadata
	Meta StepTypeMeta

	// Optional fields
	Version     string
	ChartPath   string
	Destination string
}

StepHelmPackage represents a step type for building and uploading a Helm chart to a chart registry.

func (StepHelmPackage) StepTypeName

func (StepHelmPackage) StepTypeName() string

StepTypeName returns the name of this step type.

type StepKubectl

type StepKubectl struct {
	// Step type metadata
	Meta StepTypeMeta

	// Required fields
	File  string
	Files []string

	// Optional fields
	Namespace string
	Action    string
	Force     bool
	Cluster   string
}

StepKubectl represents a step type for running kubectl commands on some Kubernetes manifest files.

func (StepKubectl) StepTypeName

func (StepKubectl) StepTypeName() string

StepTypeName returns the name of this step type.

type StepNuGetPackage

type StepNuGetPackage struct {
	// Step type metadata
	Meta StepTypeMeta

	// Required fields
	Version     string
	ProjectPath string
	Repo        string

	// Optional fields
	SkipDuplicate         bool
	CertificatesMountPath string
}

StepNuGetPackage represents a step type used for building .NET NuGet packages.

func (StepNuGetPackage) StepTypeName

func (StepNuGetPackage) StepTypeName() string

StepTypeName returns the name of this step type.

type StepType

type StepType interface {
	StepTypeName() string
}

StepType is an interface that is implemented by all step types.

type StepTypeMeta

type StepTypeMeta struct {
	StepName string
	Source   Pos
	FieldPos map[string]Pos
}

StepTypeMeta contains metadata about a step type.

type VarFile

type VarFile struct {
	Path  string
	IsRel bool
}

VarFile is a place and kind definition of a variable file.

func ListPossibleVarsFiles

func ListPossibleVarsFiles(currentDir string) []VarFile

ListPossibleVarsFiles returns all paths where we look for wharf-vars.yml and .wharf-vars.yml files.

Returned paths include the filename.

The ordering of the returned filenames are in the order of which file should have priority over the other; with the file of highest priority that should override all the others, first.

func (VarFile) PrettyPath

func (f VarFile) PrettyPath(currentDir string) string

PrettyPath returns a formatted version of the path, based on if its relative, and using "~" as shorthand for the user's home directory.

type VarSubNode

type VarSubNode struct {
	Node *yaml.Node
}

VarSubNode is a custom varsub variable type that envelops a YAML node. Mostly only used internally inside the wharfyml package.

func (VarSubNode) String

func (v VarSubNode) String() string

String implements the fmt.Stringer interface.

Jump to

Keyboard shortcuts

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