dukkha

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2021 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GlobalInterfaceTypeHandler rs.InterfaceTypeHandler = globalTypeManager

Functions

func RegisterRenderer

func RegisterRenderer(name string, create RendererCreateFunc)

func RegisterTask

func RegisterTask(k ToolKind, tk TaskKind, create TaskCreateFunc)

func RegisterTool

func RegisterTool(k ToolKind, create ToolCreateFunc)

func ResolveEnv

func ResolveEnv(t rs.Field, mCtx RenderingContext, envFieldName string) error

Types

type ConfigResolvingContext

type ConfigResolvingContext interface {
	Context

	ShellManager
	ToolManager
	TaskManager
	RendererManager
}

func NewConfigResolvingContext

func NewConfigResolvingContext(
	parent context.Context,
	ifaceTypeHandler rs.InterfaceTypeHandler,
	globalEnv map[string]string,
) ConfigResolvingContext

type Context

type Context interface {
	TaskExecContext

	SetRuntimeOptions(opts RuntimeOptions)
	RunTask(ToolKey, TaskKey) error
}

Context for user facing tasks

type Env

type Env []*EnvEntry

func (Env) Clone

func (orig Env) Clone() Env

type EnvEntry

type EnvEntry struct {
	rs.BaseField `yaml:"-"`

	Name  string `yaml:"name"`
	Value string `yaml:"value"`
}

type EnvValues

type EnvValues interface {
	GlobalValues

	SetMatrixFilter(*matrix.Filter)
	MatrixFilter() *matrix.Filter

	MatrixArch() string
	MatrixKernel() string
	MatrixLibc() string

	AddEnv(override bool, env ...*EnvEntry)
	AddListEnv(env ...string)
}

type ExecSpecGetFunc

type ExecSpecGetFunc func(toExec []string, isFilePath bool) (env Env, cmd []string, err error)

type ExecValues

type ExecValues interface {
	SetOutputPrefix(s string)
	OutputPrefix() string

	SetTaskColors(prefixColor, outputColor termenv.Color)
	PrefixColor() termenv.Color
	OutputColor() termenv.Color

	CurrentTool() ToolKey
	CurrentTask() TaskKey

	SetTask(k ToolKey, tK TaskKey)
}

type GlobalValues

type GlobalValues interface {
	SetCacheDir(dir string)
	OverrideDefaultGitBranch(branch string)

	WorkingDir() string
	CacheDir() string

	GitBranch() string
	GitWorkTreeClean() bool
	GitTag() string
	GitDefaultBranch() string
	GitCommit() string

	HostKernel() string
	HostKernelVersion() string
	HostArch() string
	HostOS() string
	HostOSVersion() string
}

type Renderer

type Renderer interface {
	rs.Field

	// Init the renderer and add itself to the context
	Init(ctx ConfigResolvingContext) error

	RenderYaml(rc RenderingContext, rawData interface{}) (result interface{}, err error)
}

Renderer to handle rendering suffix

type RendererCreateFunc

type RendererCreateFunc func(name string) Renderer

type RendererManager

type RendererManager interface {
	AllRenderers() map[string]Renderer
	AddRenderer(name string, renderer Renderer)
}

RendererManager to manage renderers

type RenderingContext

type RenderingContext interface {
	context.Context

	expand.Environ

	GlobalValues
	EnvValues

	// AddValues will merge provided values into existing values
	AddValues(values map[string]interface{}) error

	Env() map[string]string

	Values() map[string]interface{}

	rs.InterfaceTypeHandler
	rs.RenderingHandler
}

type ReplaceEntries

type ReplaceEntries map[string]*ReplaceEntry

type ReplaceEntry

type ReplaceEntry struct {
	Data []byte
	Err  error
}

type RunTaskOrRunCmd

type RunTaskOrRunCmd interface{}

type RuntimeOptions added in v0.4.0

type RuntimeOptions struct {
	FailFast            bool
	ColorOutput         bool
	TranslateANSIStream bool
	RetainANSIStyle     bool
	Workers             int
}

RuntimeOptions for task execution

type Shell

type Shell interface {
	rs.Field

	GetExecSpec(toExec []string, isFilePath bool) (env Env, cmd []string, err error)
}

type ShellManager

type ShellManager interface {
	AddShell(name string, impl Shell)
}

type ShellUser

type ShellUser interface {
	GetShell(name string) (Shell, bool)
	AllShells() map[string]Shell
}

type Task

type Task interface {
	rs.Field

	// Kind of the tool managing this task (e.g. docker)
	ToolKind() ToolKind

	// Name of the tool managing this task (e.g. my-tool)
	ToolName() ToolName

	// Kind of the task (e.g. build)
	Kind() TaskKind

	// Name of the task (e.g. foo)
	Name() TaskName

	// Key of this task
	Key() TaskKey

	// GetMatrixSpecs for matrix execution
	//
	// The implementation MUST be safe to be used concurrently
	GetMatrixSpecs(rc RenderingContext) ([]matrix.Entry, error)

	// GetExecSpecs generate commands using current field values
	//
	// The implementation MUST be safe to be used concurrently
	GetExecSpecs(rc TaskExecContext, options TaskMatrixExecOptions) ([]TaskExecSpec, error)

	// GetHookExecSpecs generate hook run target
	//
	// The implementation MUST be safe to be used concurrently
	GetHookExecSpecs(ctx TaskExecContext, state TaskExecStage) ([]RunTaskOrRunCmd, error)

	// DoAfterFieldsResolved is a helper function to ensure no data race
	//
	// The implementation MUST be safe to be used concurrently
	DoAfterFieldsResolved(
		rc RenderingContext,
		depth int,
		do func() error,
		fieldNames ...string,
	) error

	ContinueOnError() bool
}

type TaskCreateFunc

type TaskCreateFunc func(toolName string) Task

type TaskExecContext

type TaskExecContext interface {
	context.Context

	RenderingContext
	ShellUser
	ToolUser
	TaskUser

	DeriveNew() Context

	Cancel()

	TranslateANSIStream() bool
	RetainANSIStyle() bool
	ColorOutput() bool
	FailFast() bool
	ClaimWorkers(n int) int

	ExecValues
}

type TaskExecOptions

type TaskExecOptions interface {
	NextMatrixExecOptions(useShell bool, shellName string, toolCmd []string) TaskMatrixExecOptions
}

func CreateTaskExecOptions

func CreateTaskExecOptions(id, totalMatrix int) TaskExecOptions

type TaskExecSpec

type TaskExecSpec struct {
	// Delay execution
	Delay time.Duration

	// StdoutAsReplace to replace same string in following TaskExecSpecs
	// use output to stdout of this exec
	StdoutAsReplace string

	// ShowStdout when StdoutAsReplace is set
	ShowStdout bool

	FixStdoutValueForReplace func(data []byte) []byte

	// StderrAsReplace to replace same string in following TaskExecSpecs
	// use output to stderr of this exec
	StderrAsReplace string

	// ShowStderr when StderrAsReplace is set
	ShowStderr bool

	FixStderrValueForReplace func(data []byte) []byte

	Chdir string

	// EnvSuggest to provide environment variables when not set by user
	EnvSuggest Env
	// EnvOverride to override existing environment variables
	EnvOverride Env

	Command []string

	AlterExecFunc func(
		replace ReplaceEntries,
		stdin io.Reader, stdout, stderr io.Writer,
	) (RunTaskOrRunCmd, error)

	Stdin io.Reader

	IgnoreError bool

	// UseShell if true, write command to local script cache
	// and execute with the target shell (as referenced by ShellName)
	UseShell bool

	// ShellName to reference a shell to execute command
	// when `UseShell` is true
	//
	// the availability of the shells denpends on `shells` in dukkha config
	// a special shell name is `embedded`, which will use the built-in shell
	// for command evaluation
	ShellName string
}

type TaskExecStage

type TaskExecStage uint8
const (
	StageBefore TaskExecStage = iota + 1

	StageBeforeMatrix
	StageAfterMatrixSuccess
	StageAfterMatrixFailure
	StageAfterMatrix

	StageAfterSuccess
	StageAfterFailure
	StageAfter
)

func (TaskExecStage) String

func (s TaskExecStage) String() string

type TaskKey

type TaskKey struct {
	Kind TaskKind
	Name TaskName
}

func (TaskKey) String

func (k TaskKey) String() string

type TaskKind

type TaskKind string

type TaskManager

type TaskManager interface {
	AddToolSpecificTasks(kind ToolKind, name ToolName, tasks []Task)
}

type TaskMatrixExecOptions

type TaskMatrixExecOptions interface {
	ID() int
	Total() int

	UseShell() bool
	ShellName() string
	ToolCmd() []string

	Seq() int

	IsLast() bool
}

type TaskName

type TaskName string

type TaskReference

type TaskReference struct {
	ToolKind ToolKind
	ToolName ToolName
	TaskKind TaskKind
	TaskName TaskName

	MatrixFilter *matrix.Filter
}

func ParseTaskReference

func ParseTaskReference(taskRef string, defaultToolName ToolName) (*TaskReference, error)

ParseTaskReference parse task ref

<tool-kind>{:<tool-name>}:<task-kind>(<task-name>, ...)

e.g. buildah:build(dukkha) # use default matrix

buildah:build(dukkha, {kernel: [linux]}) # use custom matrix
buildah:in-docker:build(dukkha, {kernel: [linux]}) # with tool-name

func (*TaskReference) TaskKey

func (t *TaskReference) TaskKey() TaskKey

func (*TaskReference) ToolKey

func (t *TaskReference) ToolKey() ToolKey

type TaskUser

type TaskUser interface {
	GetToolSpecificTasks(k ToolKey) ([]Task, bool)
	AllToolSpecificTasks() map[ToolKey][]Task
}

type Tool

type Tool interface {
	rs.Field

	// Kind of the tool, e.g. golang, docker
	Kind() ToolKind

	Name() ToolName

	Key() ToolKey

	GetCmd() []string

	GetEnv() Env

	UseShell() bool

	ShellName() string

	GetTask(TaskKey) (Task, bool)

	AllTasks() map[TaskKey]Task

	Init(kind ToolKind, cachdDir string) error

	ResolveTasks(tasks []Task) error

	Run(taskCtx TaskExecContext) error

	DoAfterFieldsResolved(
		mCtx TaskExecContext,
		depth int,
		do func() error,
		fieldNames ...string,
	) error
}

nolint:revive

type ToolCreateFunc

type ToolCreateFunc func() Tool

type ToolKey

type ToolKey struct {
	Kind ToolKind
	Name ToolName
}

func (ToolKey) String

func (k ToolKey) String() string

type ToolKind

type ToolKind string

type ToolManager

type ToolManager interface {
	AddTool(k ToolKey, t Tool)
}

type ToolName

type ToolName string

type ToolUser

type ToolUser interface {
	AllTools() map[ToolKey]Tool
	GetTool(k ToolKey) (Tool, bool)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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