agent

package
v0.0.0-...-9a8ef1a Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2018 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UID = 1000
	GID = 1000

	MOUNTPOINT = "/mnt"
	WORKDIR    = MOUNTPOINT + "/work"
)
View Source
const (
	PIPELINEFILE    = "Pipelinefile"
	STAGE_IMAGE     = "alpine:latest"
	KEY_PATH        = "/tmp/id_rsa"
	KEY_PERMISSIONS = 0600

	// scm stage definitions
	STAGE_SCM_ID   = 0
	STAGE_SCM_NAME = "Clone"

	// internal environment variables
	CI_BUILDNR    = "CI_BUILDNR"
	CI_AGENT      = "CI_AGENT"
	CI_COMMIT_REF = "CI_COMMIT_REF"
	CI_BRANCH     = "CI_BRANCH"
)
View Source
const (
	// scm commands
	SCM_CLONE    = "clone"
	SCM_HEAD_REF = "head"

	// scm compare return codes
	SCM_RET_SUCCESS        = 0
	SCM_RET_INVALID_BRANCH = 1
)
View Source
const (
	DOCKER_SOCKET = "/var/run/docker.sock"
)
View Source
const (
	DOCKER_TIMEOUT = 250 * time.Millisecond
)
View Source
const (
	EVENT_STREAM_BUFFER = 128
)

Variables

View Source
var (
	ErrNoContainer     = errors.New("no container available")
	ErrNoAgent         = errors.New("no agent available")
	ErrAlreadyExecuted = errors.New("pipeline was already executed")
	ErrInvalidBranch   = errors.New("branch does not exist")
	ErrNoProject       = errors.New("no project set")
)

errors

Functions

func Add

func Add(agents ...Agent)

Adds one or multiple agents to the build agent pool.

Types

type Agent

type Agent struct {
	// from config file
	Name       string `yaml:"name,omitempty" json:"name"`
	Endpoint   string `yaml:"endpoint,omitempty" json:"endpoint"`
	Concurrent int    `yaml:"concurrent,omitempty" json:"concurrent"`

	// public runtime variables
	BuildCount int `json:"build_count" yaml:"-"`
	// contains filtered or unexported fields
}

func Allocate

func Allocate() *Agent

Return a random build agent.

func (*Agent) CreateContainer

func (a *Agent) CreateContainer(vol string, image string, cmd string, env []string, workdir string) (string, error)

func (*Agent) CreateVolume

func (a *Agent) CreateVolume() (string, error)

Create a new volume.

func (*Agent) Filepath

func (a *Agent) Filepath(paths ...string) string

Joins parts of a filepath to a complete path.

func (*Agent) Free

func (a *Agent) Free()

func (*Agent) IsReady

func (a *Agent) IsReady() bool

Returns if this agent is ready for a new build.

func (*Agent) ReadFile

func (a *Agent) ReadFile(container string, file string) ([]byte, error)

func (*Agent) RemoveContainer

func (a *Agent) RemoveContainer(id string) error

Removes a container with the given ID from the build agent.

func (*Agent) RemoveVolume

func (a *Agent) RemoveVolume(name string) error

Deletes the given volume by its name.

func (*Agent) SavePath

func (a *Agent) SavePath(container string, path string, file string) error

Saves the remote path to a local gzip compressed tar file.

func (*Agent) StartContainer

func (a *Agent) StartContainer(container string, stdio func(string)) (int, error)

Executes a command on the build agent, while using the given volume and image.

func (*Agent) WriteFile

func (a *Agent) WriteFile(container string, path string, buf []byte, mode int64) error

Writes a file to the container

type ConsoleOutput

type ConsoleOutput struct {
	// public members
	Callback func(string)
	// contains filtered or unexported fields
}

func (*ConsoleOutput) Write

func (w *ConsoleOutput) Write(p []byte) (int, error)

type Pipeline

type Pipeline struct {
	// public variables
	Agent      *Agent
	Volume     string
	Containers []string
	StartTime  time.Time
	Env        map[string]string
	Events     chan interface{}
	// contains filtered or unexported fields
}

func CreatePipeline

func CreatePipeline() (*Pipeline, error)

Creates a new pipeline on a free agent.

func (*Pipeline) BeginPipeline

func (p *Pipeline) BeginPipeline(start time.Time, agent string)

Inform about begining a pipeline.

func (*Pipeline) BeginStage

func (p *Pipeline) BeginStage(stage int)

Begins the given stage.

func (*Pipeline) Clone

func (p *Pipeline) Clone() (*model.Commit, error)

Clones a copy of the source repository to the pipelines working dir.

func (*Pipeline) CommitFound

func (p *Pipeline) CommitFound(commit *model.Commit)

Publishes the commit details.

func (*Pipeline) Container

func (p *Pipeline) Container(image string, cmd string, workdir string, stdio func(string)) (int, error)

Executes a command in the given image on this pipeline.

func (*Pipeline) Destroy

func (p *Pipeline) Destroy()

Destroys the whole pipeline

func (*Pipeline) Execute

func (p *Pipeline) Execute() error

Executes the give project on this pipeline. This is a oneshot action. The pipeline is toren down on success or error.

func (*Pipeline) ExecuteStage

func (p *Pipeline) ExecuteStage(stageId int, stage *pipelinefile.Stage) error

Executes the given stage on this Pipieline.

func (*Pipeline) FinishPipeline

func (p *Pipeline) FinishPipeline(status string, duration time.Duration)

Inform about the end of a pipeline.

func (*Pipeline) FinishStage

func (p *Pipeline) FinishStage(stage int, status string, duration time.Duration)

Finishes the given stage

func (*Pipeline) GetPipelinefile

func (p *Pipeline) GetPipelinefile() (*pipelinefile.Definition, error)

Downloads and parses the pipeline defition from the working copy.

func (*Pipeline) HeadRef

func (p *Pipeline) HeadRef() (string, error)

Gets the head reference of the given pipeline.

func (*Pipeline) Log

func (p *Pipeline) Log(stage int, v ...interface{})

Appends a log line to a stage.

func (*Pipeline) LogTerminal

func (p *Pipeline) LogTerminal(stage int, v ...interface{})

Appends a terminal log line to a stage.

func (*Pipeline) PublishPipeline

func (p *Pipeline) PublishPipeline()

Publishes all information about the Pipeline definition to the event stream.

func (*Pipeline) ReadFile

func (p *Pipeline) ReadFile(path string) ([]byte, error)

Read a file from the pipeline. At least on container has to be executed.

func (*Pipeline) SavePath

func (p *Pipeline) SavePath(path string, local string) error

Saves a whole path from the pipeline as gzipped tar archive. At least on container has to be executed.

func (*Pipeline) SetArtifactsDir

func (p *Pipeline) SetArtifactsDir(dir string)

Sets the local directory where artifacts are stored.

func (*Pipeline) SetBuild

func (p *Pipeline) SetBuild(build *model.Build)

Assigns a build to this pipeline.

func (*Pipeline) SetProject

func (p *Pipeline) SetProject(project *model.Project)

Assigns a project to this pipeline.

Jump to

Keyboard shortcuts

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