agent

package
v3.0.0-...-c194909 Latest Latest
Warning

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

Go to latest
Published: May 8, 2020 License: MIT Imports: 60 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ArtifactPathDelimiter    = ";"
	ArtifactFallbackMimeType = "binary/octet-stream"
)

Variables

View Source
var ArtifactPathVariableRegex = regexp.MustCompile("\\$\\{artifact\\:path\\}")

Functions

func BuildVersion

func BuildVersion() string

func FetchTags

func FetchTags(l logger.Logger, conf FetchTagsConfig) []string

FetchTags loads tags from a variety of sources

func ParseArtifactoryDestination

func ParseArtifactoryDestination(destination string) (repo string, path string)

func ParseGSDestination

func ParseGSDestination(destination string) (name string, path string)

func ParseS3Destination

func ParseS3Destination(destination string) (name string, path string)

func Register

Register takes an api.Agent and registers it with the Buildkite API and populates the result of the register call

func UserAgent

func UserAgent() string

func Version

func Version() string

func Worker

func Worker(id int, ls *LogStreamer)

The actual log streamer worker

Types

type APIClient

type APIClient interface {
	AcceptJob(*api.Job) (*api.Job, *api.Response, error)
	AcquireJob(string) (*api.Job, *api.Response, error)
	Annotate(string, *api.Annotation) (*api.Response, error)
	Config() api.Config
	Connect() (*api.Response, error)
	CreateArtifacts(string, *api.ArtifactBatch) (*api.ArtifactBatchCreateResponse, *api.Response, error)
	Disconnect() (*api.Response, error)
	ExistsMetaData(string, string) (*api.MetaDataExists, *api.Response, error)
	FinishJob(*api.Job) (*api.Response, error)
	FromAgentRegisterResponse(*api.AgentRegisterResponse) *api.Client
	FromPing(*api.Ping) *api.Client
	GetJobState(string) (*api.JobState, *api.Response, error)
	GetMetaData(string, string) (*api.MetaData, *api.Response, error)
	Heartbeat() (*api.Heartbeat, *api.Response, error)
	Ping() (*api.Ping, *api.Response, error)
	Register(*api.AgentRegisterRequest) (*api.AgentRegisterResponse, *api.Response, error)
	SaveHeaderTimes(string, *api.HeaderTimes) (*api.Response, error)
	SearchArtifacts(string, *api.ArtifactSearchOptions) ([]*api.Artifact, *api.Response, error)
	SetMetaData(string, *api.MetaData) (*api.Response, error)
	StartJob(*api.Job) (*api.Response, error)
	StepUpdate(string, *api.StepUpdate) (*api.Response, error)
	UpdateArtifacts(string, map[string]string) (*api.Response, error)
	UploadChunk(string, *api.Chunk) (*api.Response, error)
	UploadPipeline(string, *api.Pipeline) (*api.Response, error)
}

APIClient is an interface generated for "github.com/buildkite/agent/v3/api.Client".

type AgentConfiguration

type AgentConfiguration struct {
	ConfigPath                 string
	BootstrapScript            string
	BuildPath                  string
	HooksPath                  string
	GitMirrorsPath             string
	GitMirrorsLockTimeout      int
	PluginsPath                string
	GitCloneFlags              string
	GitCloneMirrorFlags        string
	GitCleanFlags              string
	GitFetchFlags              string
	GitSubmodules              bool
	SSHKeyscan                 bool
	CommandEval                bool
	PluginsEnabled             bool
	PluginValidation           bool
	LocalHooksEnabled          bool
	RunInPty                   bool
	TimestampLines             bool
	HealthCheckAddr            string
	DisconnectAfterJob         bool
	DisconnectAfterIdleTimeout int
	CancelGracePeriod          int
	Shell                      string
	Profile                    string
	RedactedVars               []string
	AcquireJob                 string
}

AgentConfiguration is the run-time configuration for an agent that has been loaded from the config file and command-line params

type AgentPool

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

AgentPool manages multiple parallel AgentWorkers

func NewAgentPool

func NewAgentPool(workers []*AgentWorker) *AgentPool

NewAgentPool returns a new AgentPool

func (*AgentPool) Start

func (r *AgentPool) Start() error

Start kicks off the parallel AgentWorkers and waits for them to finish

func (*AgentPool) Stop

func (r *AgentPool) Stop(graceful bool)

type AgentWorker

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

func NewAgentWorker

Creates the agent worker and initializes its API Client

func (*AgentWorker) AcceptAndRunJob

func (a *AgentWorker) AcceptAndRunJob(job *api.Job) error

Accepts a job and runs it, only returns an error if something goes wrong

func (*AgentWorker) AcquireAndRunJob

func (a *AgentWorker) AcquireAndRunJob(jobId string) error

Attempts to acquire a job and run it, only returns an error if something goes wrong

func (*AgentWorker) Connect

func (a *AgentWorker) Connect() error

Connects the agent to the Buildkite Agent API, retrying up to 30 times if it fails.

func (*AgentWorker) Disconnect

func (a *AgentWorker) Disconnect() error

Disconnects the agent from the Buildkite Agent API, doesn't bother retrying because we want to disconnect as fast as possible.

func (*AgentWorker) Heartbeat

func (a *AgentWorker) Heartbeat() error

Performs a heatbeat

func (*AgentWorker) Ping

func (a *AgentWorker) Ping() (*api.Job, error)

Performs a ping that checks Buildkite for a job or action to take Returns a job, or nil if none is found

func (*AgentWorker) RunJob

func (a *AgentWorker) RunJob(job *api.Job) error

func (*AgentWorker) Start

func (a *AgentWorker) Start(idleMonitor *IdleMonitor) error

Starts the agent worker

func (*AgentWorker) Stop

func (a *AgentWorker) Stop(graceful bool)

Stops the agent from accepting new work and cancels any current work it's running

type AgentWorkerConfig

type AgentWorkerConfig struct {
	// Whether to set debug in the job
	Debug bool

	// What signal to use for worker cancellation
	CancelSignal process.Signal

	// The index of this agent worker
	SpawnIndex int

	// The configuration of the agent from the CLI
	AgentConfiguration AgentConfiguration
}

type ArtifactBatchCreator

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

func (*ArtifactBatchCreator) Create

func (a *ArtifactBatchCreator) Create() ([]*api.Artifact, error)

type ArtifactBatchCreatorConfig

type ArtifactBatchCreatorConfig struct {
	// The ID of the Job that these artifacts belong to
	JobID string

	// All the artifacts that need to be created
	Artifacts []*api.Artifact

	// Where the artifacts are being uploaded to on the command line
	UploadDestination string
}

type ArtifactDownloader

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

func (*ArtifactDownloader) Download

func (a *ArtifactDownloader) Download() error

type ArtifactDownloaderConfig

type ArtifactDownloaderConfig struct {
	// The ID of the Build
	BuildID string

	// The query used to find the artifacts
	Query string

	// Which step should we look at for the jobs
	Step string

	// Whether to include artifacts from retried jobs in the search
	IncludeRetriedJobs bool

	// Where we'll be downloading artifacts to
	Destination string

	// Whether to show HTTP debugging
	DebugHTTP bool
}

type ArtifactSearcher

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

func NewArtifactSearcher

func NewArtifactSearcher(l logger.Logger, ac APIClient, buildID string) *ArtifactSearcher

func (*ArtifactSearcher) Search

func (a *ArtifactSearcher) Search(query string, scope string, includeRetriedJobs bool) ([]*api.Artifact, error)

type ArtifactUploader

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

func (*ArtifactUploader) Collect

func (a *ArtifactUploader) Collect() (artifacts []*api.Artifact, err error)

func (*ArtifactUploader) Upload

func (a *ArtifactUploader) Upload() error

type ArtifactUploaderConfig

type ArtifactUploaderConfig struct {
	// The ID of the Job
	JobID string

	// The path of the uploads
	Paths string

	// Where we'll be uploading artifacts
	Destination string

	// A specific Content-Type to use for all artifacts
	ContentType string

	// Whether to show HTTP debugging
	DebugHTTP bool
}

type ArtifactoryDownloader

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

func (ArtifactoryDownloader) RepositoryFileLocation

func (d ArtifactoryDownloader) RepositoryFileLocation() string

func (ArtifactoryDownloader) RepositoryName

func (d ArtifactoryDownloader) RepositoryName() string

func (ArtifactoryDownloader) RepositoryPath

func (d ArtifactoryDownloader) RepositoryPath() string

func (ArtifactoryDownloader) Start

func (d ArtifactoryDownloader) Start() error

type ArtifactoryDownloaderConfig

type ArtifactoryDownloaderConfig struct {
	// The Artifactory repository name and the path, e.g rt://my-repo-name/foo/bar
	Repository string

	// The root directory of the download
	Destination string

	// The relative path that should be preserved in the download folder,
	// also its location in the repo
	Path string

	// How many times should it retry the download before giving up
	Retries int

	// If failed responses should be dumped to the log
	DebugHTTP bool
}

type ArtifactoryUploader

type ArtifactoryUploader struct {
	// The artifactory bucket path set from the destination
	Path string

	// The artifactory bucket name set from the destination
	Repository string
	// contains filtered or unexported fields
}

func (*ArtifactoryUploader) URL

func (u *ArtifactoryUploader) URL(artifact *api.Artifact) string

func (*ArtifactoryUploader) Upload

func (u *ArtifactoryUploader) Upload(artifact *api.Artifact) error

type ArtifactoryUploaderConfig

type ArtifactoryUploaderConfig struct {
	// The destination which includes the Artifactory bucket name and the path.
	// e.g artifactory://my-repo-name/foo/bar
	Destination string

	// Whether or not HTTP calls should be debugged
	DebugHTTP bool
}

type Download

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

func NewDownload

func NewDownload(l logger.Logger, client *http.Client, c DownloadConfig) *Download

func (Download) Start

func (d Download) Start() error

type DownloadConfig

type DownloadConfig struct {
	// The actual URL to get the file from
	URL string

	// The root directory of the download
	Destination string

	// Optional Headers to append to the request
	Headers map[string]string

	// The relative path that should be preserved in the download folder
	Path string

	// How many times should it retry the download before giving up
	Retries int

	// If failed responses should be dumped to the log
	DebugHTTP bool
}

type EC2MetaData

type EC2MetaData struct {
}

func (EC2MetaData) Get

func (e EC2MetaData) Get() (map[string]string, error)

func (EC2MetaData) GetPaths

func (e EC2MetaData) GetPaths(paths map[string]string) (map[string]string, error)

Takes a map of tags and meta-data paths to get, returns a map of tags and fetched values.

type EC2Tags

type EC2Tags struct {
}

func (EC2Tags) Get

func (e EC2Tags) Get() (map[string]string, error)

type Error

type Error struct {
	Status  int    `json:"status"`  // Error code
	Message string `json:"message"` // Message describing the error.
}

An Error reports more details on an individual error in an ErrorResponse.

type FetchTagsConfig

type FetchTagsConfig struct {
	Tags []string

	TagsFromEC2MetaData      bool
	TagsFromEC2MetaDataPaths []string
	TagsFromEC2Tags          bool
	TagsFromGCPMetaData      bool
	TagsFromGCPMetaDataPaths []string
	TagsFromGCPLabels        bool
	TagsFromHost             bool
	WaitForEC2TagsTimeout    time.Duration
	WaitForGCPLabelsTimeout  time.Duration
}

type FormUploader

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

func NewFormUploader

func NewFormUploader(l logger.Logger, c FormUploaderConfig) *FormUploader

func (*FormUploader) URL

func (u *FormUploader) URL(artifact *api.Artifact) string

The FormUploader doens't specify a URL, as one is provided by Buildkite after uploading

func (*FormUploader) Upload

func (u *FormUploader) Upload(artifact *api.Artifact) error

type FormUploaderConfig

type FormUploaderConfig struct {
	// Whether or not HTTP calls should be debugged
	DebugHTTP bool
}

type GCPLabels

type GCPLabels struct {
}

func (GCPLabels) Get

func (e GCPLabels) Get() (map[string]string, error)

type GCPMetaData

type GCPMetaData struct {
}

func (GCPMetaData) Get

func (e GCPMetaData) Get() (map[string]string, error)

func (GCPMetaData) GetPaths

func (e GCPMetaData) GetPaths(paths map[string]string) (map[string]string, error)

Takes a map of tags and meta-data paths to get, returns a map of tags and fetched values.

type GSDownloader

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

func NewGSDownloader

func NewGSDownloader(l logger.Logger, c GSDownloaderConfig) *GSDownloader

func (GSDownloader) BucketFileLocation

func (d GSDownloader) BucketFileLocation() string

func (GSDownloader) BucketName

func (d GSDownloader) BucketName() string

func (GSDownloader) BucketPath

func (d GSDownloader) BucketPath() string

func (GSDownloader) Start

func (d GSDownloader) Start() error

type GSDownloaderConfig

type GSDownloaderConfig struct {
	// The name of the bucket
	Bucket string

	// The root directory of the download
	Destination string

	// The relative path that should be preserved in the download folder,
	// also its location in the bucket
	Path string

	// How many times should it retry the download before giving up
	Retries int

	// If failed responses should be dumped to the log
	DebugHTTP bool
}

type GSUploader

type GSUploader struct {
	// The gs bucket path set from the destination
	BucketPath string

	// The gs bucket name set from the destination
	BucketName string
	// contains filtered or unexported fields
}

func NewGSUploader

func NewGSUploader(l logger.Logger, c GSUploaderConfig) (*GSUploader, error)

func (*GSUploader) URL

func (u *GSUploader) URL(artifact *api.Artifact) string

func (*GSUploader) Upload

func (u *GSUploader) Upload(artifact *api.Artifact) error

type GSUploaderConfig

type GSUploaderConfig struct {
	// The destination which includes the GS bucket name and the path.
	// gs://my-bucket-name/foo/bar
	Destination string

	// Whether or not HTTP calls shoud be debugged
	DebugHTTP bool
}

type IdleMonitor

type IdleMonitor struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewIdleMonitor

func NewIdleMonitor(totalAgents int) *IdleMonitor

func (*IdleMonitor) Idle

func (i *IdleMonitor) Idle() bool

func (*IdleMonitor) MarkBusy

func (i *IdleMonitor) MarkBusy(agentUUID string)

func (*IdleMonitor) MarkIdle

func (i *IdleMonitor) MarkIdle(agentUUID string)

type JobRunner

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

func NewJobRunner

func NewJobRunner(l logger.Logger, scope *metrics.Scope, ag *api.AgentRegisterResponse, j *api.Job, apiClient APIClient, conf JobRunnerConfig) (*JobRunner, error)

Initializes the job runner

func (*JobRunner) Cancel

func (r *JobRunner) Cancel() error

func (*JobRunner) CancelAndStop

func (r *JobRunner) CancelAndStop() error

func (*JobRunner) Run

func (r *JobRunner) Run() error

Runs the job

type JobRunnerConfig

type JobRunnerConfig struct {
	// The configuration of the agent from the CLI
	AgentConfiguration AgentConfiguration

	// What signal to use for worker cancellation
	CancelSignal process.Signal

	// Whether to set debug in the job
	Debug bool
}

type LogStreamer

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

func NewLogStreamer

func NewLogStreamer(l logger.Logger, cb func(chunk *LogStreamerChunk) error, c LogStreamerConfig) *LogStreamer

Creates a new instance of the log streamer

func (*LogStreamer) FailedChunks

func (ls *LogStreamer) FailedChunks() int

func (*LogStreamer) Process

func (ls *LogStreamer) Process(output string) error

Takes the full process output, grabs the portion we don't have, and adds it to the stream queue

func (*LogStreamer) Start

func (ls *LogStreamer) Start() error

Spins up x number of log streamer workers

func (*LogStreamer) Stop

func (ls *LogStreamer) Stop() error

Waits for all the chunks to be uploaded, then shuts down all the workers

type LogStreamerChunk

type LogStreamerChunk struct {
	// The contents of the chunk
	Data string

	// The sequence number of this chunk
	Order int

	// The byte offset of this chunk
	Offset int

	// The byte size of this chunk
	Size int
}

type LogStreamerConfig

type LogStreamerConfig struct {
	// How many log streamer workers are running at any one time
	Concurrency int

	// The maximum size of chunks
	MaxChunkSizeBytes int
}

type PipelineParser

type PipelineParser struct {
	Env             *env.Environment
	Filename        string
	Pipeline        []byte
	NoInterpolation bool
}

func (PipelineParser) Parse

type PipelineParserResult

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

PipelineParserResult is the ordered parse tree of a Pipeline document

func (*PipelineParserResult) MarshalJSON

func (p *PipelineParserResult) MarshalJSON() ([]byte, error)

type S3Downloader

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

func NewS3Downloader

func NewS3Downloader(l logger.Logger, c S3DownloaderConfig) *S3Downloader

func (S3Downloader) BucketFileLocation

func (d S3Downloader) BucketFileLocation() string

func (S3Downloader) BucketName

func (d S3Downloader) BucketName() string

func (S3Downloader) BucketPath

func (d S3Downloader) BucketPath() string

func (S3Downloader) Start

func (d S3Downloader) Start() error

type S3DownloaderConfig

type S3DownloaderConfig struct {
	// The S3 bucket name and the path, e.g s3://my-bucket-name/foo/bar
	Bucket string

	// The root directory of the download
	Destination string

	// The relative path that should be preserved in the download folder,
	// also its location in the bucket
	Path string

	// How many times should it retry the download before giving up
	Retries int

	// If failed responses should be dumped to the log
	DebugHTTP bool
}

type S3Uploader

type S3Uploader struct {
	// The s3 bucket path set from the destination
	BucketPath string

	// The s3 bucket name set from the destination
	BucketName string
	// contains filtered or unexported fields
}

func NewS3Uploader

func NewS3Uploader(l logger.Logger, c S3UploaderConfig) (*S3Uploader, error)

func (*S3Uploader) URL

func (u *S3Uploader) URL(artifact *api.Artifact) string

func (*S3Uploader) Upload

func (u *S3Uploader) Upload(artifact *api.Artifact) error

type S3UploaderConfig

type S3UploaderConfig struct {
	// The destination which includes the S3 bucket name and the path.
	// e.g s3://my-bucket-name/foo/bar
	Destination string

	// Whether or not HTTP calls should be debugged
	DebugHTTP bool
}

type Uploader

type Uploader interface {
	// The Artifact.URL property is populated with what ever is returned
	// from this method prior to uploading.
	URL(*api.Artifact) string

	// The actual uploading of the file
	Upload(*api.Artifact) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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