bootstrap

package
v3.26.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2020 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const RedactLengthMin = 6

RedactLengthMin is the shortest string length that will be considered a potential secret by the environment redactor. e.g. if the redactor is configured to filter out environment variables matching *_TOKEN, and API_TOKEN is set to "none", this minimum length will prevent the word "none" from being redacted from useful log output.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bootstrap

type Bootstrap struct {
	// Config provides the bootstrap configuration
	Config
	// contains filtered or unexported fields
}

Bootstrap represents the phases of execution in a Buildkite Job. It's run as a sub-process of the buildkite-agent and finishes at the conclusion of a job. Historically (prior to v3) the bootstrap was a shell script, but was ported to Golang for portability and testability

func New

func New(conf Config) *Bootstrap

New returns a new Bootstrap instance

func (*Bootstrap) Cancel

func (b *Bootstrap) Cancel() error

Cancel interrupts any running shell processes and causes the bootstrap to stop

func (*Bootstrap) CheckoutPhase

func (b *Bootstrap) CheckoutPhase() error

CheckoutPhase creates the build directory and makes sure we're running the build at the right commit.

func (*Bootstrap) CommandPhase

func (b *Bootstrap) CommandPhase() error

CommandPhase determines how to run the build, and then runs it

func (*Bootstrap) PluginPhase

func (b *Bootstrap) PluginPhase() error

PluginPhase is where plugins that weren't filtered in the Environment phase are checked out and made available to later phases

func (*Bootstrap) Run

func (b *Bootstrap) Run(ctx context.Context) (exitCode int)

Run the bootstrap and return the exit code

func (*Bootstrap) VendoredPluginPhase

func (b *Bootstrap) VendoredPluginPhase() error

VendoredPluginPhase is where plugins that are included in the checked out code are added

type Config

type Config struct {
	// The command to run
	Command string

	// The ID of the job being run
	JobID string

	// If the bootstrap is in debug mode
	Debug bool

	// The repository that needs to be cloned
	Repository string `env:"BUILDKITE_REPO"`

	// The commit being built
	Commit string

	// The branch of the commit
	Branch string

	// The tag of the job commit
	Tag string

	// Optional refspec to override git fetch
	RefSpec string `env:"BUILDKITE_REFSPEC"`

	// Plugin definition for the job
	Plugins string

	// Should git submodules be checked out
	GitSubmodules bool

	// If the commit was part of a pull request, this will container the PR number
	PullRequest string

	// The provider of the the pipeline
	PipelineProvider string

	// Slug of the current organization
	OrganizationSlug string

	// Slug of the current pipeline
	PipelineSlug string

	// Name of the agent running the bootstrap
	AgentName string

	// Should the bootstrap remove an existing checkout before running the job
	CleanCheckout bool `env:"BUILDKITE_CLEAN_CHECKOUT"`

	// Flags to pass to "git clone" command
	GitCloneFlags string `env:"BUILDKITE_GIT_CLONE_FLAGS"`

	// Flags to pass to "git fetch" command
	GitFetchFlags string `env:"BUILDKITE_GIT_FETCH_FLAGS"`

	// Flags to pass to "git clone" command for mirroring
	GitCloneMirrorFlags string

	// Flags to pass to "git clean" command
	GitCleanFlags string `env:"BUILDKITE_GIT_CLEAN_FLAGS"`

	// Whether or not to run the hooks/commands in a PTY
	RunInPty bool

	// Are aribtary commands allowed to be executed
	CommandEval bool

	// Are plugins enabled?
	PluginsEnabled bool

	// Whether to validate plugin configuration
	PluginValidation bool

	// Are local hooks enabled?
	LocalHooksEnabled bool

	// Path where the builds will be run
	BuildPath string

	// Path where the repository mirrors are stored
	GitMirrorsPath string

	// Seconds to wait before allowing git mirror clone lock to be acquired
	GitMirrorsLockTimeout int

	// Path to the buildkite-agent binary
	BinPath string

	// Path to the global hooks
	HooksPath string

	// Path to the plugins directory
	PluginsPath string

	// Paths to automatically upload as artifacts when the build finishes
	AutomaticArtifactUploadPaths string `env:"BUILDKITE_ARTIFACT_PATHS"`

	// A custom destination to upload artifacts to (i.e. s3://...)
	ArtifactUploadDestination string `env:"BUILDKITE_ARTIFACT_UPLOAD_DESTINATION"`

	// Whether ssh-keyscan is run on ssh hosts before checkout
	SSHKeyscan bool

	// The shell used to execute commands
	Shell string

	// Phases to execute, defaults to all phases
	Phases []string

	// List of environment variable globs to redact from job output
	RedactedVars []string
}

Config provides the configuration for the Bootstrap. Some of the keys are read from the environment after hooks are run, so we use struct tags to provide that mapping along with some reflection. It's a little bit magical but it's less work to maintain in the long run.

To add a new config option that is mapped from an env, add an struct tag and it's done

func (*Config) ReadFromEnvironment

func (c *Config) ReadFromEnvironment(environ *env.Environment) map[string]string

ReadFromEnvironment reads configuration from the Environment, returns a map of the env keys that changed and the new values

type Redactor

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

func NewRedactor

func NewRedactor(output io.Writer, replacement string, needles []string) *Redactor

Construct a new Redactor, and pre-compile the Boyer-Moore skip table

func (*Redactor) Flush

func (redactor *Redactor) Flush() error

Flush should be called after the final Write. This will Write() anything retained in case of a partial match and reset the output buffer.

func (*Redactor) Reset

func (redactor *Redactor) Reset(needles []string)

We re-use the same Redactor between different hooks and the command We need to reset and update the list of needles between each phase

func (*Redactor) Write

func (redactor *Redactor) Write(input []byte) (int, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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