pipeline

package
v0.0.0-...-1ae172a Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BuiltinPlugins = []types.PipelinePlugin{
	{
		Name:    "构建代码镜像",
		Key:     types.BuiltinPluginBuildCodeToImage,
		Version: "1.1",
		Url:     types.PipelinePluginBuiltinUrl,
		Params: types.PipelinePluginParams{
			Params: []*types.PipelinePluginParamsSpec{
				{
					ParamName: "code_url",
					From:      types.PluginParamsFromEnv,
					FromName:  "PIPELINE_CODE_URL",
					Default:   "",
				},
				{
					ParamName: "code_api_url",
					From:      types.PluginParamsFromEnv,
					FromName:  "PIPELINE_CODE_API_URL",
					Default:   "",
				},
				{
					ParamName: "code_type",
					From:      types.PluginParamsFromEnv,
					FromName:  "PIPELINE_CODE_TYPE",
					Default:   "",
				},
				{
					ParamName: "code_branch",
					From:      types.PluginParamsFromEnv,
					FromName:  "PIPELINE_CODE_BRANCH",
					Default:   "",
				},
				{
					ParamName: "code_commit_id",
					From:      types.PluginParamsFromEnv,
					FromName:  "PIPELINE_CODE_COMMIT_ID",
					Default:   "",
				},
				{
					ParamName: "code_secret",
					From:      types.PluginParamsFromCodeSecret,
					FromName:  "",
					Default:   nil,
				},
				{
					ParamName: "code_build",
					From:      types.PluginParamsFromJob,
					FromName:  "code_build",
					Default:   true,
				},
				{
					ParamName: "code_build_type",
					From:      types.PluginParamsFromJob,
					FromName:  "code_build_type",
					Default:   "file",
				},
				{
					ParamName: "code_build_image",
					From:      types.PluginParamsFromPipelineResource,
					FromName:  "code_build_image",
					Default:   nil,
				},
				{
					ParamName: "code_build_file",
					From:      types.PluginParamsFromJob,
					FromName:  "code_build_file",
					Default:   "build.sh",
				},
				{
					ParamName: "code_build_script",
					From:      types.PluginParamsFromJob,
					FromName:  "code_build_script",
					Default:   "",
				},
				{
					ParamName: "code_build_exec",
					From:      types.PluginParamsFromJob,
					FromName:  "code_build_exec",
					Default:   "",
				},
				{
					ParamName: "image_build_registry",
					From:      types.PluginParamsFromImageRegistry,
					FromName:  "image_build_registry",
					Default:   nil,
				},
				{
					ParamName: "image_registry_id",
					From:      types.PluginParamsFromJob,
					FromName:  "image_build_registry",
					Default:   0,
				},
				{
					ParamName: "image_builds",
					From:      types.PluginParamsFromJob,
					FromName:  "image_builds",
					Default:   nil,
				},
			},
		},
		ResultEnv: types.PipelinePluginResultEnv{
			EnvPath: []*types.PipelinePluginResultEnvPath{
				{
					ResultName: "images",
					EnvName:    "CODE_BUILD_IMAGES",
				},
				{
					ResultName: "image_registry",
					EnvName:    "CODE_BUILD_REGISTRY",
				},
				{
					ResultName: "image_registry_id",
					EnvName:    "CODE_BUILD_REGISTRY_ID",
				},
			},
		},
	},
	{
		Name:    "执行shell脚本",
		Key:     types.BuiltinPluginExecuteShell,
		Version: "1.0",
		Url:     types.PipelinePluginBuiltinUrl,
		Params: types.PipelinePluginParams{
			Params: []*types.PipelinePluginParamsSpec{
				{
					ParamName: "resource",
					From:      types.PluginParamsFromPipelineResource,
					FromName:  "resource",
					Default:   nil,
				},
				{
					ParamName: "port",
					From:      types.PluginParamsFromJob,
					FromName:  "port",
					Default:   "22",
				},
				{
					ParamName: "script",
					From:      types.PluginParamsFromJob,
					FromName:  "script",
					Default:   "",
				},
				{
					ParamName: "shell",
					From:      types.PluginParamsFromJob,
					FromName:  "shell",
					Default:   "bash",
				},
				{
					ParamName: "env",
					From:      types.PluginParamsFromPipelineEnv,
					FromName:  "",
					Default:   nil,
				},
			},
		},
	},
	{
		Name:    "升级空间应用",
		Key:     types.BuiltinPluginUpgradeApp,
		Version: "1.0",
		Url:     types.PipelinePluginBuiltinUrl,
		Params: types.PipelinePluginParams{
			Params: []*types.PipelinePluginParamsSpec{
				{
					ParamName: "project",
					From:      types.PluginParamsFromJob,
					FromName:  "project",
					Default:   "",
				},
				{
					ParamName: "images",
					From:      types.PluginParamsFromEnv,
					FromName:  "CODE_BUILD_IMAGES",
					Default:   "",
				},
				{
					ParamName: "apps",
					From:      types.PluginParamsFromJob,
					FromName:  "apps",
					Default:   nil,
				},
				{
					ParamName: "with_install",
					From:      types.PluginParamsFromJob,
					FromName:  "with_install",
					Default:   true,
				},
			},
		},
	},
	{
		Name:    "版本发布",
		Key:     types.BuiltinPluginRelease,
		Version: "1.1",
		Url:     types.PipelinePluginBuiltinUrl,
		Params: types.PipelinePluginParams{
			Params: []*types.PipelinePluginParamsSpec{
				{
					ParamName: "workspace_id",
					From:      types.PluginParamsFromEnv,
					FromName:  "PIPELINE_WORKSPACE_ID",
					Default:   "",
				},
				{
					ParamName: "code_url",
					From:      types.PluginParamsFromEnv,
					FromName:  "PIPELINE_CODE_URL",
					Default:   "",
				},
				{
					ParamName: "code_api_url",
					From:      types.PluginParamsFromEnv,
					FromName:  "PIPELINE_CODE_API_URL",
					Default:   "",
				},
				{
					ParamName: "code_type",
					From:      types.PluginParamsFromEnv,
					FromName:  "PIPELINE_CODE_TYPE",
					Default:   "",
				},
				{
					ParamName: "code_branch",
					From:      types.PluginParamsFromEnv,
					FromName:  "PIPELINE_CODE_BRANCH",
					Default:   "",
				},
				{
					ParamName: "code_commit_id",
					From:      types.PluginParamsFromEnv,
					FromName:  "PIPELINE_CODE_COMMIT_ID",
					Default:   "",
				},
				{
					ParamName: "code_secret",
					From:      types.PluginParamsFromCodeSecret,
					FromName:  "",
					Default:   nil,
				},
				{
					ParamName: "version",
					From:      types.PluginParamsFromJob,
					FromName:  "version",
					Default:   nil,
				},
				{
					ParamName: "images",
					From:      types.PluginParamsFromEnv,
					FromName:  "CODE_BUILD_IMAGES",
					Default:   "",
				},
				{
					ParamName: "image_registry",
					From:      types.PluginParamsFromImageRegistry,
					FromName:  "",
					Default:   nil,
				},
			},
		},
		ResultEnv: types.PipelinePluginResultEnv{
			EnvPath: []*types.PipelinePluginResultEnvPath{
				{
					ResultName: "version",
					EnvName:    "RELEASE_VERSION",
				},
				{
					ResultName: "images",
					EnvName:    "CODE_BUILD_IMAGES",
				},
			},
		},
	},
	{
		Name:    "部署K8s资源",
		Key:     types.BuiltinPluginDeployK8s,
		Version: "1.1",
		Url:     types.PipelinePluginBuiltinUrl,
		Params: types.PipelinePluginParams{
			Params: []*types.PipelinePluginParamsSpec{
				{
					ParamName: "cluster",
					From:      types.PluginParamsFromJob,
					FromName:  "cluster",
					Default:   "",
				},
				{
					ParamName: "env",
					From:      types.PluginParamsFromPipelineEnv,
					FromName:  "",
					Default:   nil,
				},
				{
					ParamName: "images",
					From:      types.PluginParamsFromEnv,
					FromName:  "CODE_BUILD_IMAGES",
					Default:   "",
				},
				{
					ParamName: "namespace",
					From:      types.PluginParamsFromJob,
					FromName:  "namespace",
					Default:   "default",
				},
				{
					ParamName: "yaml",
					From:      types.PluginParamsFromJob,
					FromName:  "yaml",
					Default:   "",
				},
			},
		},
	},
}
View Source
var InitGlobalResources = []*types.PipelineResource{
	{
		Name:        "kubespace/golang:1.16",
		Type:        "image",
		Value:       "registry.cn-hangzhou.aliyuncs.com/kubespace/golang:1.17",
		Global:      true,
		Description: "内置golang编译镜像",
		CreateUser:  "admin",
		UpdateUser:  "admin",
	},
	{
		Name:        "kubespace/node:17.9.0",
		Type:        "image",
		Value:       "registry.cn-hangzhou.aliyuncs.com/kubespace/node:17.9.0",
		Global:      true,
		Description: "内置node编译镜像",
		CreateUser:  "admin",
		UpdateUser:  "admin",
	},
	{
		Name:        "kubespace/python:3.8",
		Type:        "image",
		Value:       "registry.cn-hangzhou.aliyuncs.com/kubespace/python:3.8",
		Global:      true,
		Description: "内置python编译镜像",
		CreateUser:  "admin",
		UpdateUser:  "admin",
	},
}

Functions

This section is empty.

Types

type JobLog

type JobLog struct {
	DB *gorm.DB
}

func NewJobLogManager

func NewJobLogManager(db *gorm.DB) *JobLog

func (*JobLog) UpdateLog

func (l *JobLog) UpdateLog(jobId uint, log string) error

type JobRunListCondition

type JobRunListCondition struct {
	WithSpacelet *bool    `json:"with_spacelet"`
	StatusIn     []string `json:"status_in"`
	SpaceletIds  []uint   `json:"spacelet_ids"`
}

type ListPipelineCondition

type ListPipelineCondition struct {
	WorkspaceId *uint
}

type ListPipelineRunCondition

type ListPipelineRunCondition struct {
	PipelineId      uint
	LastBuildNumber int
	Status          string
	Limit           int
}

type ManagerPipeline

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

func NewPipelineManager

func NewPipelineManager(db *gorm.DB) *ManagerPipeline

func (*ManagerPipeline) CreatePipeline

func (p *ManagerPipeline) CreatePipeline(pipeline *types.Pipeline, stages []*types.PipelineStage, triggers []*types.PipelineTrigger) (*types.Pipeline, error)

func (*ManagerPipeline) Delete

func (p *ManagerPipeline) Delete(pipelineId uint) error

func (*ManagerPipeline) GetById

func (p *ManagerPipeline) GetById(pipelineId uint) (*types.Pipeline, error)

func (*ManagerPipeline) List

func (*ManagerPipeline) Stages

func (p *ManagerPipeline) Stages(pipelineId uint) ([]*types.PipelineStage, error)

func (*ManagerPipeline) UpdatePipeline

func (p *ManagerPipeline) UpdatePipeline(pipeline *types.Pipeline, stages []*types.PipelineStage, triggers []*types.PipelineTrigger) (*types.Pipeline, error)

type PipelineCodeCacheManager

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

func NewPipelineCodeCacheManager

func NewPipelineCodeCacheManager(db *gorm.DB) *PipelineCodeCacheManager

func (*PipelineCodeCacheManager) CreateOrUpdate

func (r *PipelineCodeCacheManager) CreateOrUpdate(workspaceObj *types.PipelineWorkspace) error

CreateOrUpdate 根据流水线是否有代码自动触发,对代码仓库进行分支缓存

func (*PipelineCodeCacheManager) GetById

func (*PipelineCodeCacheManager) GetByWorkspaceId

func (r *PipelineCodeCacheManager) GetByWorkspaceId(workspaceId uint) (*types.PipelineCodeCache, error)

func (*PipelineCodeCacheManager) Update

type PipelinePluginManager

type PipelinePluginManager struct {
	DB *gorm.DB
}

func NewPipelinePluginManager

func NewPipelinePluginManager(db *gorm.DB) *PipelinePluginManager

func (*PipelinePluginManager) Get

func (p *PipelinePluginManager) Get(pluginId uint) (*types.PipelinePlugin, error)

func (*PipelinePluginManager) GetByKey

func (p *PipelinePluginManager) GetByKey(pluginKey string) (*types.PipelinePlugin, error)

func (*PipelinePluginManager) Init

func (p *PipelinePluginManager) Init()

type PipelineRunManager

type PipelineRunManager struct {
	DB            *gorm.DB
	PluginManager *PipelinePluginManager
	// contains filtered or unexported fields
}

func NewPipelineRunManager

func NewPipelineRunManager(db *gorm.DB, pluginManager *PipelinePluginManager, listwatcherConfig *listwatcherconfig.ListWatcherConfig) *PipelineRunManager

func (*PipelineRunManager) CreatePipelineRun

func (p *PipelineRunManager) CreatePipelineRun(pipelineRun *types.PipelineRun, stagesRun []*types.PipelineRunStage) (*types.PipelineRun, error)

func (*PipelineRunManager) Get

func (p *PipelineRunManager) Get(pipelineRunId uint) (*types.PipelineRun, error)

func (*PipelineRunManager) GetEnvBeforeStageRun

func (p *PipelineRunManager) GetEnvBeforeStageRun(stageRun *types.PipelineRunStage) (envs map[string]interface{}, err error)

func (*PipelineRunManager) GetJobRun

func (p *PipelineRunManager) GetJobRun(jobRunId uint) (*types.PipelineRunJob, error)

func (*PipelineRunManager) GetJobRunLog

func (p *PipelineRunManager) GetJobRunLog(jobRunId uint, withLog bool) (*types.PipelineRunJobLog, error)

func (*PipelineRunManager) GetLastBuildNumber

func (p *PipelineRunManager) GetLastBuildNumber(pipelineId uint) (uint, error)

func (*PipelineRunManager) GetLastPipelineRun

func (p *PipelineRunManager) GetLastPipelineRun(pipelineId uint) (*types.PipelineRun, error)

func (*PipelineRunManager) GetStageRun

func (p *PipelineRunManager) GetStageRun(stageId uint) (*types.PipelineRunStage, error)

func (*PipelineRunManager) GetStageRunEnv

func (p *PipelineRunManager) GetStageRunEnv(stageRun *types.PipelineRunStage) types.Map

func (*PipelineRunManager) GetStageRunJobs

func (p *PipelineRunManager) GetStageRunJobs(stageRunId uint) (types.PipelineRunJobs, error)

func (*PipelineRunManager) GetStageRunStatus

func (p *PipelineRunManager) GetStageRunStatus(stageRun *types.PipelineRunStage) string

GetStageRunStatus 根据stage的所有任务的状态返回该stage的状态

  1. 如果有doing的job,stage状态为doing;
  2. 如果所有job的状态为error/ok/wait,则 a. job中有error的,则stage为error; b. 所有job都为ok,则stage为ok; c. job中有ok,有wait,则stage为doing;

func (*PipelineRunManager) ListJobRun

func (*PipelineRunManager) ListPipelineRun

func (p *PipelineRunManager) ListPipelineRun(cond ListPipelineRunCondition) ([]*types.PipelineRun, error)

func (*PipelineRunManager) NextStageRun

func (p *PipelineRunManager) NextStageRun(pipelineRunId uint, stageId uint) (*types.PipelineRunStage, error)

func (*PipelineRunManager) NotifyJobRun

func (p *PipelineRunManager) NotifyJobRun(jobRun *types.PipelineRunJob) error

func (*PipelineRunManager) ReexecStage

func (p *PipelineRunManager) ReexecStage(
	pipelineRunId,
	stageRunId uint,
	customParams map[string]interface{},
	jobParams map[uint]map[string]interface{}) (*types.PipelineRun, *types.PipelineRunStage, error)

ReexecStage 重新执行已执行完成的阶段

func (*PipelineRunManager) StagesRun

func (p *PipelineRunManager) StagesRun(pipelineRunId uint) ([]*types.PipelineRunStage, error)

func (*PipelineRunManager) UpdateJobRun

func (p *PipelineRunManager) UpdateJobRun(id uint, jobRun *types.PipelineRunJob) error

func (*PipelineRunManager) UpdatePipelineRun

func (p *PipelineRunManager) UpdatePipelineRun(pipelineRun *types.PipelineRun) error

func (*PipelineRunManager) UpdatePipelineStageRun

func (p *PipelineRunManager) UpdatePipelineStageRun(updateStageObj *UpdateStageObj) (*types.PipelineRun, *types.PipelineRunStage, error)

func (*PipelineRunManager) UpdateStageJobRunParams

func (p *PipelineRunManager) UpdateStageJobRunParams(stageRun *types.PipelineRunStage, jobRuns []*types.PipelineRunJob) error

func (*PipelineRunManager) UpdateStageRun

func (p *PipelineRunManager) UpdateStageRun(stageRun *types.PipelineRunStage) error

type PipelineTriggerCondition

type PipelineTriggerCondition struct {
	Id          uint
	WorkspaceId uint
	PipelineId  uint
}

type PipelineTriggerEventManager

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

func NewPipelineTriggerEventManager

func NewPipelineTriggerEventManager(db *gorm.DB, listwatcherConfig *listwatcherconfig.ListWatcherConfig) *PipelineTriggerEventManager

func (*PipelineTriggerEventManager) Create

func (*PipelineTriggerEventManager) Get

func (*PipelineTriggerEventManager) Update

type PipelineTriggerManager

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

func NewPipelineTriggerManager

func NewPipelineTriggerManager(db *gorm.DB, listwatcherConfig *listwatcherconfig.ListWatcherConfig) *PipelineTriggerManager

func (*PipelineTriggerManager) Get

func (*PipelineTriggerManager) List

func (*PipelineTriggerManager) Update

func (r *PipelineTriggerManager) Update(id uint, updates *types.PipelineTrigger) error

func (*PipelineTriggerManager) UpdateTriggerTime

func (r *PipelineTriggerManager) UpdateTriggerTime(triggerTime time.Time, condition *PipelineTriggerCondition) error

type Release

type Release struct {
	DB *gorm.DB
}

func NewReleaseManager

func NewReleaseManager(db *gorm.DB) *Release

func (*Release) Add

func (l *Release) Add(workspaceId uint, version string, jobRunId uint) error

func (*Release) ExistsRelease

func (l *Release) ExistsRelease(workspaceId uint, version string) (bool, error)

func (*Release) GetLatestRelease

func (l *Release) GetLatestRelease(workspaceId uint) (*types.PipelineWorkspaceRelease, error)

type ResourceManager

type ResourceManager struct {
	*manager.CommonManager
}

func NewResourceManager

func NewResourceManager(db *gorm.DB) *ResourceManager

func (*ResourceManager) Create

func (*ResourceManager) Delete

func (r *ResourceManager) Delete(resource *types.PipelineResource) error

func (*ResourceManager) Get

func (r *ResourceManager) Get(resourceId uint) (*types.PipelineResource, error)

func (*ResourceManager) Init

func (r *ResourceManager) Init()

func (*ResourceManager) List

func (r *ResourceManager) List(workspaceId uint) ([]types.PipelineResource, error)

func (*ResourceManager) Update

type UpdateStageObj

type UpdateStageObj struct {
	StageRunId     uint
	StageRunStatus string
	StageExecTime  *time.Time
	StageRunJobs   types.PipelineRunJobs
	CustomParams   types.Map
}

type WorkspaceManager

type WorkspaceManager struct {
	*manager.CommonManager
	PipelineManager *ManagerPipeline
}

func NewWorkspaceManager

func NewWorkspaceManager(db *gorm.DB, pipelineManager *ManagerPipeline) *WorkspaceManager

func (*WorkspaceManager) Create

func (w *WorkspaceManager) Create(workspace *types.PipelineWorkspace, defaultPipelines []*types.Pipeline) (*types.PipelineWorkspace, error)

func (*WorkspaceManager) Delete

func (w *WorkspaceManager) Delete(workspace *types.PipelineWorkspace) error

Delete 删除流水线空间下所有资源

func (*WorkspaceManager) Get

func (w *WorkspaceManager) Get(workspaceId uint) (*types.PipelineWorkspace, error)

func (*WorkspaceManager) List

func (*WorkspaceManager) Update

Jump to

Keyboard shortcuts

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