common

package
v0.0.0-...-5447720 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const ArtifactWebhook = "/api/v4/artifacts/webhook"
View Source
const BashDetectShell = `` /* 401-byte string literal not displayed */
View Source
const DefaultDockerWorkspace = "/workspace" // docker executor worspace dir
View Source
const DefaultLivessTimeout = 1800 // pod 生产时间
View Source
const DefaultMetricsServerPort = 9252 //prometheus metrics 端口
View Source
const DefaultNetworkClientTimeout = 60 * time.Minute // http 底层 timeout 超时时间
View Source
const DefaultOutputLimit = 4 * 1024 * 1024 // 日志文件大小 4MB
View Source
const DefaultTracePatchLimit = 1024 * 1024 // 每次上传日志大小 1MB
View Source
const ForceTraceSentInterval = 30 * time.Second // 30s 强制解锁
View Source
const KubernetesPollAttempts = 100 // 尝试获得 Pod 详情次数
View Source
const KubernetesPollInterval = 10 * time.Second // 每次查询 pod 详情 间隔时间
View Source
const NAME = "super-runner"
View Source
const PluginsInput = "/api/v4/plugins/input"

api

View Source
const PluginsOutput = "/api/v4/plugins/output"
View Source
const SSHConnectRetries = 3 // ssh 重试次数
View Source
const SSHRetryInterval = 3 //ssh 间隔时间
View Source
const UpdateInterval = 3 * time.Second // 每隔 3s 监控一个job 状态及上传日志
View Source
const UpdateRetryInterval = 3 * time.Second // 30s 重试间隔时间
View Source
const VERSION = "2020-12-08"

Variables

This section is empty.

Functions

func RegisterExecutor

func RegisterExecutor(executor string, provider ExecutorProvider)

Types

type BuildError

type BuildError struct {
	Inner error
}

func (*BuildError) Error

func (b *BuildError) Error() string

type Docker

type Docker struct {
	DNS             []string       `toml:"dns,omitempty" json:"dns" long:"dns" env:"DOCKER_DNS" description:"A list of DNS servers for the container to use"`
	DockerWorkspace string         `toml:"workspace"`
	Privileged      bool           `` /* 138-byte string literal not displayed */
	Volumes         []DockerVolume `` /* 284-byte string literal not displayed */
}

type DockerVolume

type DockerVolume struct {
	Name     string `toml:"name"`
	Source   string `toml:"source"`
	Target   string `toml:"target"`
	ReadOnly bool   `toml:"read_only"`
}

type Execution

type Execution struct {
	Language    string   `json:"language"`
	PackagePath string   `json:"package_path"`
	Demands     []string `json:"demands"`
	Artifacts   []string `json:"artifacts,omitempty"`
	Target      string   `json:"target"`
}

type Executor

type Executor interface {
	Prepare(job Job) error
	Run() error
	Wait() error
	SendError(err error)
	Cleanup() error
}

type ExecutorProvider

type ExecutorProvider interface {
	CanCreate() bool
	Create() Executor
}

func GetExecutor

func GetExecutor(executorStr string) ExecutorProvider

type FailuresCollector

type FailuresCollector interface {
	RecordFailure(reason JobFailureReason, runnerDescription string)
}

prometheus 异常收集器

type GitConfig

type GitConfig struct {
	Name     string `toml:"name"`
	Password string `toml:"password"`
}

type Image

type Image struct {
	Name       string   `json:"name"`
	Alias      string   `json:"alias,omitempty"`
	Command    []string `json:"command,omitempty"`
	Entrypoint []string `json:"entrypoint,omitempty"`
}

type Job

type Job struct {
	Runner RunnerConfig
	JobResponse
	Trace   JobTrace
	JobName string
}

func (*Job) Run

func (j *Job) Run() error

type JobCredentials

type JobCredentials struct {
	ID         string
	Token      string
	Pipeline   string
	StageIndex int
	JobIndex   int
}

JobCredentials 是 job 请求的凭证,带上 pipeline,stageIndex,jobIndex 方便后端定位

type JobFailureReason

type JobFailureReason string // job 失败的原因(系统级别简要分析)
const (
	NoneFailure         JobFailureReason = ""
	ScriptFailure       JobFailureReason = "script_failure"
	RunnerSystemFailure JobFailureReason = "runner_system_failure"
	JobExecutionTimeout JobFailureReason = "job_execution_timeout"
)

type JobInfo

type JobInfo struct {
	Pipeline       string       `json:"pipeline"`
	PipelineNumber int          `json:"pipeline_number"`
	ProjectID      int          `json:"project_id"`
	Stage          string       `json:"stage"`
	StageIndex     int          `json:"stage_index"`
	JobName        string       `json:"job_name"`
	JobNumber      int          `json:"job_number"`
	JobIndex       int          `json:"job_index"`
	Timestamp      int64        `json:"timestamp"`
	Image          Image        `json:"image"`
	Services       Services     `json:"services,omitempty"`
	Volumes        []Volume     `json:"volumes,omitempty"`
	Variables      JobVariables `json:"variables,omitempty"`
	Plugins        Plugins      `json:"plugins"`
	Timeout        int32        `json:"timeout,omitempty"`
}

type JobLogger

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

func NewBuildLogger

func NewBuildLogger(log JobTrace, entry *logrus.Entry) JobLogger

func (*JobLogger) Debugln

func (e *JobLogger) Debugln(args ...interface{})

func (*JobLogger) Errorln

func (e *JobLogger) Errorln(args ...interface{})

func (*JobLogger) Infoln

func (e *JobLogger) Infoln(args ...interface{})

func (*JobLogger) Println

func (e *JobLogger) Println(args ...interface{})

func (*JobLogger) SendRawLog

func (e *JobLogger) SendRawLog(args ...interface{})

func (*JobLogger) SoftErrorln

func (e *JobLogger) SoftErrorln(args ...interface{})

func (*JobLogger) Warningln

func (e *JobLogger) Warningln(args ...interface{})

func (*JobLogger) WithFields

func (e *JobLogger) WithFields(fields logrus.Fields) JobLogger

func (*JobLogger) WriterLevel

func (e *JobLogger) WriterLevel(level logrus.Level) *io.PipeWriter

type JobRequest

type JobRequest struct {
	Info  VersionInfo `json:"info,omitempty"`
	Token string      `json:"token,omitempty"`
}

type JobResponse

type JobResponse struct {
	ID      string  `json:"id"`
	Token   string  `json:"token"`
	JobInfo JobInfo `json:"job_info"`
}

JobResponse 为解析 json 的结构体

type JobResultRequest

type JobResultRequest struct {
	Info    VersionInfo `json:"info,omitempty"`
	Token   string      `json:"token,omitempty"`
	JobInfo JobInfo     `json:"job_info"`
	Data    ResultData  `json:"result_data"`
}

type JobState

type JobState string // job 状态标识
const (
	Pending JobState = "pending"
	Running JobState = "running"
	Failed  JobState = "failed"
	Success JobState = "success"
)

type JobTrace

type JobTrace interface {
	io.Writer
	Success()
	Fail(err error, failureReason JobFailureReason)
	SetCancelFunc(cancelFunc context.CancelFunc)
	SetFailuresCollector(fc FailuresCollector)
	SetMasked(values []string)
	IsStdout() bool
}

Job 日志跟踪接口

type JobVariable

type JobVariable struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

func ParseVariable

func ParseVariable(text string) (variable JobVariable, err error)

func (JobVariable) String

func (b JobVariable) String() string

type JobVariables

type JobVariables []JobVariable

func (JobVariables) Expand

func (b JobVariables) Expand() (variables JobVariables)

func (JobVariables) ExpandValue

func (b JobVariables) ExpandValue(value string) string

func (JobVariables) Get

func (b JobVariables) Get(key string) string

func (JobVariables) StringList

func (b JobVariables) StringList() (variables []string)

type KafkaConfig

type KafkaConfig struct {
	Read   Read   `toml:"read"`
	Writer Writer `toml:"writer"`
}

type Kubernetes

type Kubernetes struct {
	Config      string   `toml:"config,omitempty"`
	Namespace   string   `toml:"namespace,omitempty"`
	DNS         []string `toml:"dns,omitempty"`
	HelperImage string   `toml:"helper_image,omitempty"`
}

type MinioConfig

type MinioConfig struct {
	URL             string `toml:"url"`
	ArtifactsBucket string `toml:"artifacts_bucket"`
	PluginsBucket   string `toml:"plugins_bucket"`
	LogsBucket      string `toml:"logs_bucket"`
	AccessKey       string `toml:"access_key"`
	SecretKey       string `toml:"secret_key"`
}

type PluginInfo

type PluginInfo struct {
	PluginName    string       `json:"plugin_name"`
	PluginMd5     string       `json:"plugin_md5"`
	PluginVersion string       `json:"plugin_version"`
	PluginAuthor  string       `json:"plugin_author"`
	Execution     Execution    `json:"execution"`
	Variables     JobVariables `json:"variables,omitempty"`
}

type PluginRequest

type PluginRequest struct {
	Pipeline    string `json:"pipeline"`
	StageIndex  int    `json:"stage_index"`
	JobIndex    int    `json:"job_index"`
	PluginIndex int    `json:"plugin_index"` // 该job 的 plugin 下标
	Token       string `json:"job_token"`    // job 的 token

}

type PluginResponse

type PluginResponse struct {
	ID         int        `json:"id"`
	Token      string     `json:"token"`
	PluginInfo PluginInfo `json:"plugin_info"`
}

type Plugins

type Plugins struct {
	Count int `json:"count"`
}

type Read

type Read struct {
	BrokerList string `toml:"brokerList"`
	Topic      string `toml:"topic"`
	GroupID    string `toml:"groupID"`
}

type ResultData

type ResultData struct {
	Status      string `json:"status"`
	Code        string `json:"code"`
	Message     string `json:"message"`
	MinioLogURL string `json:"minio_log_url"`
}

type RunnerConfig

type RunnerConfig struct {
	Name          string      `toml:"name"`
	Executor      string      `toml:"executor"`
	Concurrent    int         `toml:"concurrent"`
	OutputLimit   int         `` /* 126-byte string literal not displayed */
	LogLevel      string      `toml:"log_level"`
	Log           string      `toml:"log"`
	TempLogDir    string      `toml:"temp_log_dir"`
	ListenAddress string      `toml:"listen_address,omitempty" json:"listen_address"`
	KafkaConfig   KafkaConfig `toml:"kafka"`
	Kubernetes    Kubernetes  `toml:"kubernetes"`
	MinioConfig   MinioConfig `toml:"minio"`
	Docker        Docker      `toml:"docker"`
	GitConfig     GitConfig   `toml:"git"`
	RunnerCredentials
}

func (*RunnerConfig) GetListenAddress

func (config *RunnerConfig) GetListenAddress() (string, error)

获取 ListenAddress 配置地址

func (*RunnerConfig) LoadConfig

func (config *RunnerConfig) LoadConfig(configFile string) error

解析配置文件

type RunnerCredentials

type RunnerCredentials struct {
	URL   string `toml:"url" json:"url" short:"u" long:"url" env:"CI_SERVER_URL" required:"true" description:"Runner URL"`
	Token string `toml:"token" json:"token" short:"t" long:"token" env:"CI_SERVER_TOKEN" required:"true" description:"Runner token"`
}

func (*RunnerCredentials) GetToken

func (c *RunnerCredentials) GetToken() string

func (*RunnerCredentials) GetURL

func (c *RunnerCredentials) GetURL() string

type Services

type Services []Image

type UpdateJobInfo

type UpdateJobInfo struct {
	ID            string
	State         JobState
	FailureReason JobFailureReason
}

UpdateJobInfo 是更新 job 状态的内容

type UpdateJobRequest

type UpdateJobRequest struct {
	Info          VersionInfo      `json:"info,omitempty"`
	Token         string           `json:"token,omitempty"`
	State         JobState         `json:"state,omitempty"`
	FailureReason JobFailureReason `json:"failure_reason,omitempty"`
}

UpdateJobRequest 更新 job 的 request 内容

type UpdateState

type UpdateState int // 日志内容上传的状态标识
const (
	UpdateSucceeded UpdateState = iota
	UpdateNotFound
	UpdateAbort
	UpdateFailed
	UpdateRangeMismatch
)

type VersionInfo

type VersionInfo struct {
	Name         string `json:"name,omitempty"`
	Version      string `json:"version,omitempty"`
	Revision     string `json:"revision,omitempty"`
	Platform     string `json:"platform,omitempty"`
	Architecture string `json:"architecture,omitempty"`
	Executor     string `json:"executor,omitempty"`
}

type Volume

type Volume struct {
	Name      string `json:"name"`
	MountPath string `json:"mount_path"`
	ReadOnly  bool   `json:"read_only"`
	HostPath  string `json:"host_path"`
}

type Writer

type Writer struct {
	BrokerList string `toml:"brokerList"`
	Topic      string `toml:"topic"`
}

Jump to

Keyboard shortcuts

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