common

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: May 22, 2016 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Pending BuildState = "pending"
	Running            = "running"
	Failed             = "failed"
	Success            = "success"
)
View Source
const (
	DockerPullPolicyAlways       DockerPullPolicy = "always"
	DockerPullPolicyNever                         = "never"
	DockerPullPolicyIfNotPresent                  = "if-not-present"
)
View Source
const CheckInterval = 3
View Source
const DefaultExecTimeout = 1800
View Source
const DefaultOutputLimit = 4096 // 4MB in kilobytes
View Source
const DefaultTimeout = 7200
View Source
const DefaultWaitForServicesTimeout = 30
View Source
const ForceTraceSentInterval = 30 * time.Second
View Source
const HealthCheckInterval = 3600
View Source
const HealthyChecks = 3
View Source
const NotHealthyCheckInterval = 300
View Source
const ReloadConfigInterval = 3
View Source
const ShutdownTimeout = 30
View Source
const UpdateInterval = 3 * time.Second
View Source
const UpdateRetryInterval = 3 * time.Second

Variables

View Source
var BRANCH = "HEAD"
View Source
var BUILT = "now"
View Source
var NAME = "gitlab-ci-multi-runner"
View Source
var REVISION = "HEAD"
View Source
var VERSION = "dev"

Functions

func ExtendedVersion added in v1.2.0

func ExtendedVersion() string

func GetCommands

func GetCommands() []cli.Command

func GetDefaultShell

func GetDefaultShell() string

func GetExecutors

func GetExecutors() []string

func GetShells

func GetShells() []string

func RegisterCommand

func RegisterCommand(command cli.Command)

func RegisterCommand2

func RegisterCommand2(name, usage string, data Commander, flags ...cli.Flag)

func RegisterExecutor

func RegisterExecutor(executor string, provider ExecutorProvider)

func RegisterShell

func RegisterShell(shell Shell)

func VersionLine added in v1.2.0

func VersionLine() string

func VersionPrinter added in v1.2.0

func VersionPrinter(c *cli.Context)

Types

type Build

type Build struct {
	GetBuildResponse `yaml:",inline"`

	Trace        BuildTrace
	BuildAbort   chan os.Signal `json:"-" yaml:"-"`
	RootDir      string         `json:"-" yaml:"-"`
	BuildDir     string         `json:"-" yaml:"-"`
	CacheDir     string         `json:"-" yaml:"-"`
	Hostname     string         `json:"-" yaml:"-"`
	Runner       *RunnerConfig  `json:"runner"`
	ExecutorData ExecutorData

	// Unique ID for all running builds on this runner
	RunnerID int `json:"runner_id"`

	// Unique ID for all running builds on this runner and this project
	ProjectRunnerID int `json:"project_runner_id"`
}

func (*Build) FullProjectDir

func (b *Build) FullProjectDir() string

func (*Build) GetAllVariables

func (b *Build) GetAllVariables() BuildVariables

func (*Build) GetDefaultVariables

func (b *Build) GetDefaultVariables() BuildVariables

func (*Build) ProjectSlug

func (b *Build) ProjectSlug() (string, error)

func (*Build) ProjectUniqueDir

func (b *Build) ProjectUniqueDir(sharedDir bool) string

func (*Build) ProjectUniqueName

func (b *Build) ProjectUniqueName() string

func (*Build) Run

func (b *Build) Run(globalConfig *Config, trace BuildTrace) (err error)

func (*Build) StartBuild

func (b *Build) StartBuild(rootDir, cacheDir string, sharedDir bool)

func (*Build) String

func (b *Build) String() string

type BuildArtifacts

type BuildArtifacts struct {
	Filename string `json:"filename,omitempty"`
	Size     int64  `json:"size,omitempty"`
}

type BuildCredentials

type BuildCredentials struct {
	ID        int    `long:"id" env:"CI_BUILD_ID" description:"The build ID to upload artifacts for"`
	Token     string `long:"token" env:"CI_BUILD_TOKEN" required:"true" description:"Build token"`
	URL       string `long:"url" env:"CI_SERVER_URL" required:"true" description:"GitLab CI URL"`
	TLSCAFile string `` /* 129-byte string literal not displayed */
}

type BuildInfo

type BuildInfo struct {
	ID        int             `json:"id,omitempty"`
	Sha       string          `json:"sha,omitempty"`
	RefName   string          `json:"ref,omitempty"`
	Token     string          `json:"token"`
	Name      string          `json:"name"`
	Stage     string          `json:"stage"`
	Tag       bool            `json:"tag"`
	Artifacts *BuildArtifacts `json:"artifacts_file"`
}

type BuildOptions

type BuildOptions map[string]interface{}

func (*BuildOptions) Decode

func (m *BuildOptions) Decode(result interface{}, keys ...string) error

func (*BuildOptions) Get

func (m *BuildOptions) Get(keys ...string) (interface{}, bool)

func (*BuildOptions) GetString

func (m *BuildOptions) GetString(keys ...string) (result string, ok bool)

func (*BuildOptions) GetSubOptions added in v1.1.1

func (m *BuildOptions) GetSubOptions(keys ...string) (result BuildOptions, ok bool)

func (*BuildOptions) Sanitize added in v1.1.1

func (m *BuildOptions) Sanitize() (err error)

type BuildState

type BuildState string

type BuildTrace

type BuildTrace interface {
	io.Writer
	Success()
	Fail(err error)
	Notify(abort func())
	IsStdout() bool
}

type BuildVariable

type BuildVariable struct {
	Key      string `json:"key"`
	Value    string `json:"value"`
	Public   bool   `json:"public"`
	Internal bool   `json:"-"`
	File     bool   `json:"-"`
}

func ParseVariable

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

func (BuildVariable) String

func (b BuildVariable) String() string

type BuildVariables

type BuildVariables []BuildVariable

func (BuildVariables) Expand

func (b BuildVariables) Expand() (variables BuildVariables)

func (BuildVariables) ExpandValue

func (b BuildVariables) ExpandValue(value string) string

func (BuildVariables) Get

func (b BuildVariables) Get(key string) string

func (BuildVariables) PublicOrInternal

func (b BuildVariables) PublicOrInternal() (variables BuildVariables)

func (BuildVariables) StringList

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

type CacheConfig

type CacheConfig struct {
	Type           string `toml:"Type,omitempty" long:"type" env:"CACHE_TYPE" description:"Select caching method: s3, to use S3 buckets"`
	ServerAddress  string `toml:"ServerAddress,omitempty" long:"s3-server-address" env:"S3_SERVER_ADDRESS" description:"S3 Server Address"`
	AccessKey      string `toml:"AccessKey,omitempty" long:"s3-access-key" env:"S3_ACCESS_KEY" description:"S3 Access Key"`
	SecretKey      string `toml:"SecretKey,omitempty" long:"s3-secret-key" env:"S3_SECRET_KEY" description:"S3 Secret Key"`
	BucketName     string `toml:"BucketName,omitempty" long:"s3-bucket-name" env:"S3_BUCKET_NAME" description:"S3 bucket name"`
	BucketLocation string `toml:"BucketLocation,omitempty" long:"s3-bucket-location" env:"S3_BUCKET_LOCATION" description:"S3 location"`
	Insecure       bool   `toml:"Insecure,omitempty" long:"s3-insecure" env:"S3_CACHE_INSECURE" description:"Use insecure mode (without https)"`
}

type Commander

type Commander interface {
	Execute(c *cli.Context)
}

type Config

type Config struct {
	Concurrent int             `toml:"concurrent" json:"concurrent"`
	User       string          `toml:"user,omitempty" json:"user"`
	Runners    []*RunnerConfig `toml:"runners" json:"runners"`
	ModTime    time.Time       `toml:"-"`
	Loaded     bool            `toml:"-"`
}

func NewConfig

func NewConfig() *Config

func (*Config) LoadConfig

func (c *Config) LoadConfig(configFile string) error

func (*Config) SaveConfig

func (c *Config) SaveConfig(configFile string) error

func (*Config) StatConfig

func (c *Config) StatConfig(configFile string) error

type DeleteRunnerRequest

type DeleteRunnerRequest struct {
	Token string `json:"token,omitempty"`
}

type DockerConfig

type DockerConfig struct {
	docker_helpers.DockerCredentials
	Hostname               string           `toml:"hostname,omitempty" json:"hostname" long:"hostname" env:"DOCKER_HOSTNAME" description:"Custom container hostname"`
	Image                  string           `toml:"image" json:"image" long:"image" env:"DOCKER_IMAGE" description:"Docker image to be used"`
	Privileged             bool             `` /* 138-byte string literal not displayed */
	CapAdd                 []string         `toml:"cap_add" json:"cap_add" long:"cap-add" env:"DOCKER_CAP_ADD" description:"Add Linux capabilities"`
	CapDrop                []string         `toml:"cap_drop" json:"cap_drop" long:"cap-drop" env:"DOCKER_CAP_DROP" description:"Drop Linux capabilities"`
	Devices                []string         `toml:"devices" json:"devices" long:"devices" env:"DOCKER_DEVICES" description:"Add a host device to the container"`
	DisableCache           bool             `` /* 142-byte string literal not displayed */
	Volumes                []string         `toml:"volumes,omitempty" json:"volumes" long:"volumes" env:"DOCKER_VOLUMES" description:"Bind mount a volumes"`
	CacheDir               string           `` /* 129-byte string literal not displayed */
	ExtraHosts             []string         `` /* 137-byte string literal not displayed */
	NetworkMode            string           `` /* 143-byte string literal not displayed */
	Links                  []string         `toml:"links,omitempty" json:"links" long:"links" env:"DOCKER_LINKS" description:"Add link to another container"`
	Services               []string         `` /* 136-byte string literal not displayed */
	WaitForServicesTimeout int              `` /* 197-byte string literal not displayed */
	AllowedImages          []string         `` /* 142-byte string literal not displayed */
	AllowedServices        []string         `` /* 152-byte string literal not displayed */
	PullPolicy             DockerPullPolicy `` /* 154-byte string literal not displayed */
}

type DockerMachine

type DockerMachine struct {
	IdleCount      int      `long:"idle-nodes" env:"MACHINE_IDLE_COUNT" description:"Maximum idle machines"`
	IdleTime       int      `toml:"IdleTime,omitzero" long:"idle-time" env:"MACHINE_IDLE_TIME" description:"Minimum time after node can be destroyed"`
	MaxBuilds      int      `` /* 128-byte string literal not displayed */
	MachineDriver  string   `long:"machine-driver" env:"MACHINE_DRIVER" description:"The driver to use when creating machine"`
	MachineName    string   `long:"machine-name" env:"MACHINE_NAME" description:"The template for machine name (needs to include %s)"`
	MachineOptions []string `long:"machine-options" env:"MACHINE_OPTIONS" description:"Additional machine creation options"`
}

type DockerPullPolicy

type DockerPullPolicy string

func (DockerPullPolicy) Get

Get returns one of the predefined values or returns an error if the value can't match the predefined

type DownloadState

type DownloadState int
const (
	DownloadSucceeded DownloadState = iota
	DownloadForbidden
	DownloadFailed
	DownloadNotFound
)

type Executor

type Executor interface {
	Prepare(globalConfig *Config, config *RunnerConfig, build *Build) error
	ShellScript() *ShellScript
	Run(cmd ExecutorCommand) error
	Finish(err error)
	Cleanup()
}

func NewExecutor

func NewExecutor(executor string) Executor

type ExecutorCommand added in v1.2.0

type ExecutorCommand struct {
	Script     string
	Predefined bool
	Abort      chan interface{}
}

type ExecutorData

type ExecutorData interface{}

type ExecutorProvider

type ExecutorProvider interface {
	CanCreate() bool
	Create() Executor
	Acquire(config *RunnerConfig) (ExecutorData, error)
	Release(config *RunnerConfig, data ExecutorData) error
	GetFeatures(features *FeaturesInfo)
}

func GetExecutor

func GetExecutor(executor string) ExecutorProvider

type FeaturesInfo

type FeaturesInfo struct {
	Variables bool `json:"variables"`
	Image     bool `json:"image"`
	Services  bool `json:"services"`
	Artifacts bool `json:"features"`
	Cache     bool `json:"cache"`
}

type GetBuildRequest

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

type GetBuildResponse

type GetBuildResponse struct {
	ID              int            `json:"id,omitempty"`
	ProjectID       int            `json:"project_id,omitempty"`
	Commands        string         `json:"commands,omitempty"`
	RepoURL         string         `json:"repo_url,omitempty"`
	Sha             string         `json:"sha,omitempty"`
	RefName         string         `json:"ref,omitempty"`
	BeforeSha       string         `json:"before_sha,omitempty"`
	AllowGitFetch   bool           `json:"allow_git_fetch,omitempty"`
	Timeout         int            `json:"timeout,omitempty"`
	Variables       BuildVariables `json:"variables"`
	Options         BuildOptions   `json:"options"`
	Token           string         `json:"token"`
	Name            string         `json:"name"`
	Stage           string         `json:"stage"`
	Tag             bool           `json:"tag"`
	DependsOnBuilds []BuildInfo    `json:"depends_on_builds"`
	TLSCAChain      string         `json:"-"`
}

type Network

type Network interface {
	GetBuild(config RunnerConfig) (*GetBuildResponse, bool)
	RegisterRunner(config RunnerCredentials, description, tags string) *RegisterRunnerResponse
	DeleteRunner(config RunnerCredentials) bool
	VerifyRunner(config RunnerCredentials) bool
	UpdateBuild(config RunnerConfig, id int, state BuildState, trace string) UpdateState
	DownloadArtifacts(config BuildCredentials, artifactsFile string) DownloadState
	UploadRawArtifacts(config BuildCredentials, reader io.Reader, baseName string) UploadState
	UploadArtifacts(config BuildCredentials, artifactsFile string) UploadState
	ProcessBuild(config RunnerConfig, id int) BuildTrace
}

type ParallelsConfig

type ParallelsConfig struct {
	BaseName         string `toml:"base_name" json:"base_name" long:"base-name" env:"PARALLELS_BASE_NAME" description:"VM name to be used"`
	TemplateName     string `` /* 142-byte string literal not displayed */
	DisableSnapshots bool   `` /* 174-byte string literal not displayed */
}

type RegisterRunnerRequest

type RegisterRunnerRequest struct {
	Info        VersionInfo `json:"info,omitempty"`
	Token       string      `json:"token,omitempty"`
	Description string      `json:"description,omitempty"`
	Tags        string      `json:"tag_list,omitempty"`
}

type RegisterRunnerResponse

type RegisterRunnerResponse struct {
	Token string `json:"token,omitempty"`
}

type RunnerConfig

type RunnerConfig struct {
	Name        string `toml:"name" json:"name" short:"name" long:"description" env:"RUNNER_NAME" description:"Runner name"`
	Limit       int    `` /* 130-byte string literal not displayed */
	OutputLimit int    `toml:"output_limit,omitzero" long:"output-limit" env:"RUNNER_OUTPUT_LIMIT" description:"Maximum build trace size"`

	RunnerCredentials
	RunnerSettings
}

func (*RunnerConfig) GetVariables

func (c *RunnerConfig) GetVariables() BuildVariables

func (*RunnerConfig) String

func (c *RunnerConfig) String() string

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"`
	TLSCAFile string `` /* 177-byte string literal not displayed */
}

func (*RunnerCredentials) Log

func (c *RunnerCredentials) Log() *log.Entry

func (*RunnerCredentials) ShortDescription

func (c *RunnerCredentials) ShortDescription() string

func (*RunnerCredentials) UniqueID

func (c *RunnerCredentials) UniqueID() string

type RunnerSettings

type RunnerSettings struct {
	Executor  string `` /* 140-byte string literal not displayed */
	BuildsDir string `` /* 135-byte string literal not displayed */
	CacheDir  string `` /* 135-byte string literal not displayed */

	Environment []string `` /* 148-byte string literal not displayed */

	Shell string `toml:"shell,omitempty" json:"shell" long:"shell" env:"RUNNER_SHELL" description:"Select bash, cmd or powershell"`

	SSH        *ssh.Config       `toml:"ssh" json:"ssh" group:"ssh executor" namespace:"ssh"`
	Docker     *DockerConfig     `toml:"docker" json:"docker" group:"docker executor" namespace:"docker"`
	Parallels  *ParallelsConfig  `toml:"parallels" json:"parallels" group:"parallels executor" namespace:"parallels"`
	VirtualBox *VirtualBoxConfig `toml:"virtualbox" json:"virtualbox" group:"virtualbox executor" namespace:"virtualbox"`
	Cache      *CacheConfig      `toml:"cache" json:"cache" group:"cache configuration" namespace:"cache"`
	Machine    *DockerMachine    `toml:"machine" json:"machine" group:"docker machine provider" namespace:"machine"`
}

type Shell

type Shell interface {
	GetName() string
	GetSupportedOptions() []string
	GenerateScript(info ShellScriptInfo) (*ShellScript, error)
	GetFeatures(features *FeaturesInfo)
	IsDefault() bool
}

func GetShell

func GetShell(shell string) Shell

type ShellScript

type ShellScript struct {
	Environment   []string
	DockerCommand []string
	PreScript     string
	BuildScript   string
	AfterScript   string
	PostScript    string
	Command       string
	Arguments     []string
	PassFile      bool
	Extension     string
}

func GenerateShellScript

func GenerateShellScript(info ShellScriptInfo) (*ShellScript, error)

func (*ShellScript) GetCommandWithArguments

func (s *ShellScript) GetCommandWithArguments() []string

func (*ShellScript) String

func (s *ShellScript) String() string

type ShellScriptInfo

type ShellScriptInfo struct {
	Shell         string
	Build         *Build
	Type          ShellType
	User          string
	RunnerCommand string
}

type ShellType

type ShellType int
const (
	NormalShell ShellType = iota
	LoginShell
)

type UpdateBuildRequest

type UpdateBuildRequest struct {
	Info  VersionInfo `json:"info,omitempty"`
	Token string      `json:"token,omitempty"`
	State BuildState  `json:"state,omitempty"`
	Trace string      `json:"trace,omitempty"`
}

type UpdateState

type UpdateState int
const (
	UpdateSucceeded UpdateState = iota
	UpdateAbort
	UpdateFailed
)

type UploadState

type UploadState int
const (
	UploadSucceeded UploadState = iota
	UploadTooLarge
	UploadForbidden
	UploadFailed
)

type VerifyRunnerRequest

type VerifyRunnerRequest struct {
	Token string `json:"token,omitempty"`
}

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"`
	Features     FeaturesInfo `json:"features"`
}

type VirtualBoxConfig

type VirtualBoxConfig struct {
	BaseName         string `toml:"base_name" json:"base_name" long:"base-name" env:"VIRTUALBOX_BASE_NAME" description:"VM name to be used"`
	DisableSnapshots bool   `` /* 175-byte string literal not displayed */
}

Jump to

Keyboard shortcuts

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