pipelineyml

package
v1.3.2 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: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Version1dot1 = "1.1"
	Version1dot0 = "1.0"
	Version1     = "1"
)
View Source
const (
	RefOpOutput = "OUTPUT"

	RefOpExEscape = "escape"
)
View Source
const (
	Snippet            = "snippet"
	SnippetDisplayName = "嵌套流水线"
	SnippetDesc        = "嵌套流水线可以声明嵌套的其他 pipeline.yml"

	SnippetActionNameLinkAddr = "_"
)
View Source
const (
	TimeoutDuration4Forever = -1
)

Variables

View Source
var DefaultCronCompensator = CronCompensator{
	Enable:               false,
	LatestFirst:          true,
	StopIfLatterExecuted: true,
}

Functions

func CheckEnvs

func CheckEnvs(envs map[string]string) []error

func ConvertGraphPipelineYmlContent

func ConvertGraphPipelineYmlContent(data []byte) ([]byte, error)

ConvertGraphPipelineYmlContent: YAML(apistructs.PipelineYml) -> YAML(Spec)

func ConvertToGraphPipelineYml

func ConvertToGraphPipelineYml(data []byte) (*apistructs.PipelineYml, error)

ConvertToGraphPipelineYml: YAML(Spec) -> apistructs.PipelineYml

func DoRenderTemplateHandler

func DoRenderTemplateHandler(params map[string]interface{}, templateAction *apistructs.PipelineTemplateSpec,
	alias string, templateVersion apistructs.TemplateVersion,
	handler func(snippet string, params map[string]interface{}) (string, error)) (string, []apistructs.SnippetFormatOutputs, error)

func DoRenderTemplateNotReplaceParamsValue

func DoRenderTemplateNotReplaceParamsValue(params map[string]interface{}, templateAction *apistructs.PipelineTemplateSpec, alias string, templateVersion apistructs.TemplateVersion) (string, []apistructs.SnippetFormatOutputs, error)

func DoRenderTemplateWithFormat

func DoRenderTemplateWithFormat(params map[string]interface{}, templateAction *apistructs.PipelineTemplateSpec, alias string, templateVersion apistructs.TemplateVersion) (string, []apistructs.SnippetFormatOutputs, error)

func GenerateYml

func GenerateYml(s *Spec) ([]byte, error)

GenerateYml 根据 spec 重新生成 yaml 文本,一般用于对 spec 进行调整后重新生成 yaml 文本

func GetParamDefaultValue

func GetParamDefaultValue(paramType string) interface{}

GetParamDefaultValue get default param value by type

func GetVersion

func GetVersion(data []byte) (string, error)

func IsCron

func IsCron(s *Spec) bool

func ListAction

func ListAction(s *Spec) map[ActionAlias]*Action

func ListNextCronTime

func ListNextCronTime(cronExpr string, ops ...CronVisitorOption) ([]time.Time, error)

func RenderLabels added in v1.3.0

func RenderLabels(input []byte, labels map[string]string) ([]byte, error)

func RenderSecrets

func RenderSecrets(input []byte, secrets map[string]string) ([]byte, error)

RenderSecrets 将 ((xxx)) 替换为 secrets 中的值

input: ((a))((b))((c)) secrets: a=1,b=2 result: 12((c)) err: secret not found: ((c))

func ReplacePipelineParams

func ReplacePipelineParams(pipeline string, params map[string]interface{}) string

func UpgradeYmlFromV1

func UpgradeYmlFromV1(v1 []byte) ([]byte, error)

UpgradeYmlFromV1 根据传入的 v1 yaml content 给出 v1.1 yaml content

Types

type Action

type Action struct {
	Alias       ActionAlias            `yaml:"alias,omitempty"`
	Description string                 `yaml:"description,omitempty"`
	Version     string                 `yaml:"version,omitempty"`
	Params      map[string]interface{} `yaml:"params,omitempty"`
	Labels      map[string]string      `yaml:"labels,omitempty"`

	Workspace string                       `yaml:"workspace,omitempty"`
	Image     string                       `yaml:"image,omitempty"`
	Commands  []string                     `yaml:"commands,omitempty"`
	Loop      *apistructs.PipelineTaskLoop `yaml:"loop,omitempty"`

	Timeout int64 `yaml:"timeout,omitempty"` // unit: second

	Resources Resources `yaml:"resources,omitempty"`

	Type ActionType `yaml:"-"`

	Caches []ActionCache `yaml:"caches,omitempty"` // action 构建缓存

	SnippetConfig *SnippetConfig `yaml:"snippet_config,omitempty"` // snippet 类型的 action 的配置

	If string `yaml:"if,omitempty"` // 条件执行

	// TODO 在未来版本中,可能去除 stage,依赖关系则必须通过 Needs 来声明。
	// 目前不开放给用户使用。由 parser 自动赋值。
	// Needs 显式声明依赖的 actions。隐式依赖关系是下一个 stage 依赖之前所有 stage 里的 action。
	// Needs 可以绕开 stage 限制,以 DAG 方式声明依赖关系。
	// Needs 一旦声明,只包含声明的值,不会注入其他依赖。
	Needs []ActionAlias `yaml:"-"`

	// TODO 该字段目前是兼容字段。
	// 在 1.1 版本中,Needs = NeedNamespaces
	// 在 1.0 版本中,Needs <= NeedNamespaces
	// 目前不开放给用户使用。由 parser 自动赋值。
	// NeedNamespaces 显式声明依赖的 namespaces。隐式依赖关系是下一个 stage 依赖之前所有 stage 的 namespaces。
	// NeedNamespaces 一旦声明,只包含声明的值,不会注入其他依赖。
	NeedNamespaces []string `yaml:"-"`

	// TODO 该字段目前是兼容字段,在未来版本中可以通过该字段扩展上下文。
	// 目前不开放给用户使用。由 parser 自动赋值。
	// Namespaces 显式声明 action 的命名空间,每个命名空间在流水线上下文目录下是唯一的,可以是目录或者文件。
	// 隐式命名空间为一个 alias,对应流水线上下文目录下的一个目录。
	// Namespaces 即使声明,同时会注入默认值 alias,也就是说每个 action 至少会有一个 namespace。
	Namespaces []string `yaml:"namespaces,omitempty"`
}

func GetAction

func GetAction(s *Spec, alias ActionAlias) (*Action, error)

func (*Action) GetActionTypeVersion

func (action *Action) GetActionTypeVersion() string

example: git, git@1.0, git@1.1

type ActionAlias

type ActionAlias string

func (ActionAlias) String

func (a ActionAlias) String() string

type ActionCache

type ActionCache struct {
	// 缓存生成的 key 或者是用户指定的 key
	// 用户指定的话 需要 {{basePath}}/路径/{{endPath}} 来自定义 key
	// 用户没有指定 key 有一定的生成规则, 具体生成规则看 prepare.go 的 setActionCacheStorageAndBinds 方法
	Key  string `yaml:"key,omitempty"`
	Path string `yaml:"path,omitempty"` // 指定那个目录被缓存, 只能是由 / 开始的绝对路径
}

type ActionType

type ActionType string

func (ActionType) IsCustom

func (t ActionType) IsCustom() bool

func (ActionType) IsSnippet

func (t ActionType) IsSnippet() bool

func (ActionType) String

func (t ActionType) String() string

type CronCompensator

type CronCompensator struct {
	Enable               bool `yaml:"enable"`
	LatestFirst          bool `yaml:"latest_first"`
	StopIfLatterExecuted bool `yaml:"stop_if_latter_executed"`
}

type CronVisitor

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

func NewCronVisitor

func NewCronVisitor(ops ...CronVisitorOption) *CronVisitor

func (*CronVisitor) Visit

func (v *CronVisitor) Visit(s *Spec)

type CronVisitorOption

type CronVisitorOption func(*CronVisitor)

func WithCronStartEndTime

func WithCronStartEndTime(cronStartTime, cronEndTime *time.Time) CronVisitorOption

func WithListNextScheduleCount

func WithListNextScheduleCount(count int) CronVisitorOption

type EnvInsertVisitor

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

func NewEnvInsertVisitor

func NewEnvInsertVisitor(envs map[string]string) *EnvInsertVisitor

func (*EnvInsertVisitor) Visit

func (v *EnvInsertVisitor) Visit(s *Spec)

type EnvVisitor

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

func NewEnvVisitor

func NewEnvVisitor(envs map[string]string) *EnvVisitor

func (*EnvVisitor) Visit

func (v *EnvVisitor) Visit(s *Spec)

type HandleResult

type HandleResult struct {
	Errs  []error
	Warns []string
}

func (*HandleResult) AppendError

func (r *HandleResult) AppendError(err error)

func (*HandleResult) AppendWarn

func (r *HandleResult) AppendWarn(warn string)

type LabelsVisitor added in v1.3.0

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

func NewLabelsVisitor added in v1.3.0

func NewLabelsVisitor(data []byte, labels map[string]string) *LabelsVisitor

func (*LabelsVisitor) Visit added in v1.3.0

func (v *LabelsVisitor) Visit(s *Spec)

yaml global text replacement

type MergeTrigger

type MergeTrigger struct {
	Branches []string `yaml:"branches,omitempty"`
}

type NetworkHookInfo

type NetworkHookInfo struct {
	Hook   string                 `json:"hook"`   // hook type
	Client string                 `json:"client"` // use network client
	Labels map[string]interface{} `json:"labels"` // additional information
}

describe the use of network hook in the pipeline

type Option

type Option func(*PipelineYml)

func WithActionTypeMapping

func WithActionTypeMapping(mapping map[string]string) Option

func WithAliasesToCheckRefOp

func WithAliasesToCheckRefOp(globalSnippetConfigLabels map[string]string, aliases ...ActionAlias) Option

WithAliasesToCheckRefOp 设置哪些 action alias 需要检查 ref op

func WithAllowMissingCustomScriptOutputs

func WithAllowMissingCustomScriptOutputs(allow bool) Option

WithAllowMissingCustomScriptOutputs 设置是否允许 custom-script 的 outputs 不存在,即忽略错误。 Default: false,默认不忽略。 custom-script 的 outputs 在运行时才能确定,因此在 precheck 时该参数应该设置为 true。

func WithEnvs

func WithEnvs(envs map[string]string) Option

func WithFlatParams

func WithFlatParams(flatParams bool) Option

func WithRefOpOutputs

func WithRefOpOutputs(outputs Outputs) Option

WithRefOpOutputs 设置可用的 ref op outputs

func WithRefs

func WithRefs(refs Refs) Option

WithRefs 设置可用的 refs

func WithRunParams

func WithRunParams(runParams []apistructs.PipelineRunParamWithValue) Option

func WithSecrets

func WithSecrets(secrets map[string]string) Option

func WithSecretsRecursiveRenderTimes

func WithSecretsRecursiveRenderTimes(times int) Option

func WithTriggerLabels added in v1.3.0

func WithTriggerLabels(triggerLabels map[string]string) Option

type Outputs

type Outputs map[ActionAlias]map[string]string

type ParamsVisitor

type ParamsVisitor struct {
	Data              []byte
	RunPipelineParams []apistructs.PipelineRunParam
}

func NewParamsVisitor

func NewParamsVisitor(data []byte, runPipelineParam []apistructs.PipelineRunParam) *ParamsVisitor

func (*ParamsVisitor) Visit

func (v *ParamsVisitor) Visit(s *Spec)

type PipelineOutput

type PipelineOutput struct {
	Name string `json:"name,omitempty" yaml:"name,omitempty"` // 名称
	Desc string `json:"desc,omitempty" yaml:"desc,omitempty"` // 描述
	Ref  string `json:"ref,omitempty" yaml:"ref,omitempty"`   // 引用那个 action 的值
}

type PipelineParam

type PipelineParam struct {
	Name     string      `json:"name,omitempty" yaml:"name,omitempty"`         // 名称
	Required bool        `json:"required,omitempty" yaml:"required,omitempty"` // 是否必须
	Default  interface{} `json:"default,omitempty" yaml:"default,omitempty"`   // 默认值
	Desc     string      `json:"desc,omitempty" yaml:"desc,omitempty"`         // 描述
	Type     string      `json:"type,omitempty" yaml:"type,omitempty"`         // 类型
}

type PipelineYml

type PipelineYml struct {
	SnippetCaches []SnippetPipelineYmlCache // snippet 缓存
	// contains filtered or unexported fields
}

func New

func New(b []byte, ops ...Option) (_ *PipelineYml, err error)

func (*PipelineYml) Errors

func (y *PipelineYml) Errors() []error

func (*PipelineYml) NeedUpgrade

func (y *PipelineYml) NeedUpgrade() bool

func (*PipelineYml) Spec

func (y *PipelineYml) Spec() *Spec

func (*PipelineYml) UpgradedYmlContent

func (y *PipelineYml) UpgradedYmlContent() []byte

func (*PipelineYml) Warns

func (y *PipelineYml) Warns() []string

type PushTrigger

type PushTrigger struct {
	Branches []string `yaml:"branches,omitempty"`
	Tags     []string `yaml:"tags,omitempty"`
}

type RefOp

type RefOp struct {
	Ori string // ${alias:OPERATION:key}
	Ref string // ref: alias or namespace
	Op  string // OPERATION
	Key string // key
	Ex  string // Executor

	IsAlias           bool // 是否是 alias
	IsNamespace       bool // 是否是 namespace
	RefStageIndex     int  // ref 所属 stage index
	CurrentStageIndex int  // 当前 action 的 stage index
}

RefOp split from ${alias:OPERATION:key}

type RefOpVisitor

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

func NewRefOpVisitor

func NewRefOpVisitor(aliases []ActionAlias, availableRefs Refs, availableOutputs Outputs, allowMissingCustomScriptOutputs bool, globalSnippetConfigLabels map[string]string) *RefOpVisitor

commitDetail 用作 snippet 校验 outputs bdl 用作 snippet 校验 outputs

func (*RefOpVisitor) Visit

func (v *RefOpVisitor) Visit(s *Spec)

type Refs

type Refs map[string]string

type Resources

type Resources struct {
	CPU     float64           `yaml:"cpu,omitempty"`
	MaxCPU  float64           `yaml:"max_cpu,omitempty"`
	Mem     int               `yaml:"mem,omitempty"`
	Disk    int               `yaml:"disk,omitempty"`
	Network map[string]string `yaml:"network,omitempty"`
}

type SecretNotFoundSecret

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

func NewSecretNotFoundSecret

func NewSecretNotFoundSecret(data []byte, secrets map[string]string) *SecretNotFoundSecret

func (*SecretNotFoundSecret) Visit

func (v *SecretNotFoundSecret) Visit(s *Spec)

type SecretVisitor

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

SecretVisitor 占位符统一在 yaml 中进行文本渲染,不渲染结构体,保证引号统一处理

func NewSecretVisitor

func NewSecretVisitor(data []byte, secrets map[string]string, recursiveRenderTimes int) *SecretVisitor

func (*SecretVisitor) Visit

func (v *SecretVisitor) Visit(s *Spec)

yaml 全局文本替换

type SnippetConfig

type SnippetConfig struct {
	Source string            `yaml:"source,omitempty"` // 来源 gittar dice test
	Name   string            `yaml:"name,omitempty"`   // 名称
	Labels map[string]string `yaml:"labels,omitempty"` // 额外标签
}

func HandleSnippetConfigLabel

func HandleSnippetConfigLabel(snippetConfig *SnippetConfig, globalSnippetConfigLabels map[string]string) SnippetConfig

HandleSnippetConfigLabel polish snippet config label

type SnippetPipelineYmlCache

type SnippetPipelineYmlCache struct {
	SnippetConfig SnippetConfig
	PipelineYaml  *apistructs.PipelineYml
}

type Spec

type Spec struct {
	Version string `yaml:"version"`

	On       *TriggerConfig                `yaml:"on,omitempty"`
	Triggers []*apistructs.PipelineTrigger `yaml:"triggers,omitempty"` // todo Solve the problem that quotation marks will be automatically added after yaml is saved
	Storage  *StorageConfig                `yaml:"storage,omitempty"`

	Envs map[string]string `yaml:"envs,omitempty"`

	Cron            string           `yaml:"cron,omitempty"`
	CronCompensator *CronCompensator `yaml:"cron_compensator,omitempty"`

	Stages []*Stage `yaml:"stages"`

	Params []*PipelineParam `yaml:"params,omitempty"` // 流水线输入

	Outputs []*PipelineOutput `yaml:"outputs,omitempty"` // 流水线输出

	// describe the use of network hooks in the pipeline
	Lifecycle []*NetworkHookInfo `yaml:"lifecycle,omitempty"`
	// contains filtered or unexported fields
}

Spec defines pipeline.yml.

func (*Spec) Accept

func (s *Spec) Accept(v Visitor)

func (*Spec) LoopStagesActions

func (s *Spec) LoopStagesActions(loopDoing func(stage int, action *Action))

遍历 spec 中的 stages 的 actions

func (*Spec) ToSimplePipelineYmlActionSlice

func (s *Spec) ToSimplePipelineYmlActionSlice() [][]*apistructs.PipelineYmlAction

type Stage

type Stage struct {
	Actions []typedActionMap `yaml:"stage"`
}

Stage represents a stage. Stages executes in series; Actions under a same stage executes in parallel.

type StageVisitor

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

func NewStageVisitor

func NewStageVisitor(flatParams bool) *StageVisitor

func (*StageVisitor) Visit

func (v *StageVisitor) Visit(s *Spec)

type StorageConfig

type StorageConfig struct {
	Context string `json:"context"`
}

type TimeoutVisitor

type TimeoutVisitor struct{}

func NewTimeoutVisitor

func NewTimeoutVisitor() *TimeoutVisitor

func (*TimeoutVisitor) Visit

func (v *TimeoutVisitor) Visit(s *Spec)

type TriggerConfig

type TriggerConfig struct {
	Push  *PushTrigger  `yaml:"push,omitempty"`
	Merge *MergeTrigger `yaml:"merge,omitempty"`
}

type VersionVisitor

type VersionVisitor struct{}

func NewVersionVisitor

func NewVersionVisitor() *VersionVisitor

func (*VersionVisitor) Visit

func (v *VersionVisitor) Visit(s *Spec)

type Visitable

type Visitable interface {
	Accept(v Visitor)
}

type Visitor

type Visitor interface {
	Visit(s *Spec)
}

Directories

Path Synopsis
All struct fields are required, unless "Optional" explicitly declared.
All struct fields are required, unless "Optional" explicitly declared.

Jump to

Keyboard shortcuts

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