cmd

package
v0.0.0-...-34717ca Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2017 License: Apache-2.0 Imports: 38 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// These flags tell us where to go for operations
	EndpointFlags = []cli.Flag{

		cli.StringFlag{Name: "wercker-endpoint", Value: "", Usage: "Deprecated.", Hidden: true},
		cli.StringFlag{Name: "base-url", Value: core.DEFAULT_BASE_URL, Usage: "Base url for the wercker app.", Hidden: true},
		cli.StringFlag{Name: "steps-registry", Value: "", EnvVar: "STEPS_REGISTRY", Usage: "Endpoint for the steps registry", Hidden: true},
	}

	// These flags let us auth to wercker services
	AuthFlags = []cli.Flag{
		cli.StringFlag{Name: "auth-token", Usage: "Authentication token to use."},
		cli.StringFlag{Name: "auth-token-store", Value: "~/.wercker/token", Usage: "Where to store the token after a login.", Hidden: true},
	}

	DockerFlags = []cli.Flag{
		cli.StringFlag{Name: "docker-host", Value: "", Usage: "Docker api endpoint.", EnvVar: "DOCKER_HOST"},
		cli.StringFlag{Name: "docker-tls-verify", Value: "0", Usage: "Docker api tls verify.", EnvVar: "DOCKER_TLS_VERIFY"},
		cli.StringFlag{Name: "docker-cert-path", Value: "", Usage: "Docker api cert path.", EnvVar: "DOCKER_CERT_PATH"},
		cli.StringSliceFlag{Name: "docker-dns", Value: &cli.StringSlice{}, Usage: "Docker DNS server.", EnvVar: "DOCKER_DNS", Hidden: true},
		cli.BoolFlag{Name: "docker-local", Usage: "Don't interact with remote repositories"},
		cli.StringFlag{Name: "checkpoint", Value: "", Usage: "Skip to the next step after a recent build checkpoint."},
		cli.IntFlag{Name: "docker-cpu-period", Usage: "Set docker CPU period NOTIMPLEMENTED", Hidden: true},
		cli.IntFlag{Name: "docker-cpu-quota", Usage: "Set docker CPU quota NOTIMPLEMENTED", Hidden: true},
		cli.IntFlag{Name: "docker-memory", Usage: "Set docker user memory limit in MB", Hidden: true},
		cli.IntFlag{Name: "docker-memory-swap", Usage: "Set docker user memory swap limit in MB", Hidden: true},
		cli.IntFlag{Name: "docker-memory-reservation", Usage: "Set docker user memory soft limit in MB NOTIMPLEMENTED", Hidden: true},
		cli.IntFlag{Name: "docker-kernel-memory", Usage: "Set docker kernel memory limit in MB NOTIMPLEMENTED", Hidden: true},
	}

	// These flags control where we store local files
	LocalPathFlags = []cli.Flag{
		cli.StringFlag{Name: "working-dir", Value: "./.wercker", Usage: "Path where we store working files.", EnvVar: "WERCKER_WORKING_DIR"},
	}

	// These flags control paths on the guest and probably shouldn't change
	InternalPathFlags = []cli.Flag{
		cli.StringFlag{Name: "mnt-root", Value: "/mnt", Usage: "Directory on the guest where volumes are mounted.", Hidden: true},
		cli.StringFlag{Name: "guest-root", Value: "/pipeline", Usage: "Directory on the guest where work is done.", Hidden: true},
		cli.StringFlag{Name: "report-root", Value: "/report", Usage: "Directory on the guest where reports will be written.", Hidden: true},
	}

	// These flags are usually pulled from the env
	WerckerFlags = []cli.Flag{
		cli.StringFlag{Name: "build-id", Value: "", EnvVar: "WERCKER_BUILD_ID", Hidden: true, Usage: "The build id (deprecated)."},
		cli.StringFlag{Name: "deploy-id", Value: "", EnvVar: "WERCKER_DEPLOY_ID", Hidden: true, Usage: "The deploy id (deprecated)."},
		cli.StringFlag{Name: "run-id", Value: "", EnvVar: "WERCKER_DEPLOY_ID", Hidden: true, Usage: "The run id."},
		cli.StringFlag{Name: "deploy-target", Value: "", EnvVar: "WERCKER_DEPLOYTARGET_NAME", Usage: "The deploy target name."},
		cli.StringFlag{Name: "application-id", Value: "", EnvVar: "WERCKER_APPLICATION_ID", Hidden: true, Usage: "The application id."},
		cli.StringFlag{Name: "application-name", Value: "", EnvVar: "WERCKER_APPLICATION_NAME", Hidden: true, Usage: "The application name."},
		cli.StringFlag{Name: "application-owner-name", Value: "", EnvVar: "WERCKER_APPLICATION_OWNER_NAME", Hidden: true, Usage: "The application owner name."},
		cli.StringFlag{Name: "application-started-by-name", Value: "", EnvVar: "WERCKER_APPLICATION_STARTED_BY_NAME", Hidden: true, Usage: "The name of the user who started the application."},
		cli.StringFlag{Name: "wercker-container-registry", Value: "https://wercker.gcr.io", Usage: "Wercker Registry Domain.", EnvVar: "WERCKER_CONTAINER_REGISTRY", Hidden: true},
		cli.StringFlag{Name: "pipeline", Value: "", EnvVar: "WERCKER_PIPELINE", Usage: "Alternate pipeline name to execute."},
	}

	GitFlags = []cli.Flag{
		cli.StringFlag{Name: "git-domain", Value: "", Usage: "Git domain.", EnvVar: "WERCKER_GIT_DOMAIN", Hidden: true},
		cli.StringFlag{Name: "git-owner", Value: "", Usage: "Git owner.", EnvVar: "WERCKER_GIT_OWNER", Hidden: true},
		cli.StringFlag{Name: "git-repository", Value: "", Usage: "Git repository.", EnvVar: "WERCKER_GIT_REPOSITORY", Hidden: true},
		cli.StringFlag{Name: "git-branch", Value: "", Usage: "Git branch.", EnvVar: "WERCKER_GIT_BRANCH", Hidden: true},
		cli.StringFlag{Name: "git-commit", Value: "", Usage: "Git commit.", EnvVar: "WERCKER_GIT_COMMIT", Hidden: true},
	}

	// These flags affect our registry interactions
	RegistryFlags = []cli.Flag{
		cli.StringFlag{Name: "commit", Value: "", Usage: "Commit the build result locally."},
		cli.StringFlag{Name: "tag", Value: "", Usage: "Tag for this build.", EnvVar: "WERCKER_GIT_BRANCH"},
		cli.StringFlag{Name: "message", Value: "", Usage: "Message for this build."},
	}

	// These flags affect our artifact interactions
	ArtifactFlags = []cli.Flag{
		cli.BoolFlag{Name: "artifacts", Usage: "Store artifacts."},
		cli.BoolFlag{Name: "no-remove", Usage: "Don't remove the containers."},
		cli.BoolFlag{Name: "store-s3",
			Usage: `Store artifacts and containers on s3.
			This requires access to aws credentials, pulled from any of the usual places
			(~/.aws/config, AWS_SECRET_ACCESS_KEY, etc), or from the --aws-secret-key and
			--aws-access-key flags. It will upload to a bucket defined by --s3-bucket in
			the region named by --aws-region`},
	}

	// These flags affect our local execution environment
	DevFlags = []cli.Flag{
		cli.StringFlag{Name: "environment", Value: "ENVIRONMENT", Usage: "Specify additional environment variables in a file.", EnvVar: "WERCKER_ENVIRONMENT_FILE"},
		cli.BoolFlag{Name: "verbose", Usage: "Print more information."},
		cli.BoolFlag{Name: "no-colors", Usage: "Wercker output will not use colors (does not apply to step output)."},
		cli.BoolFlag{Name: "debug", Usage: "Print additional debug information."},
		cli.BoolFlag{Name: "journal", Usage: "Send logs to systemd-journald. Suppresses stdout logging."},
	}

	// These flags are advanced dev settings
	InternalDevFlags = []cli.Flag{
		cli.BoolTFlag{Name: "direct-mount", Usage: "Mount our binds read-write to the pipeline path."},
		cli.BoolFlag{Name: "expose-ports", Usage: "Enable ports from wercker.yml beeing exposed to the host system."},

		cli.StringSliceFlag{Name: "publish", Value: &cli.StringSlice{}, Usage: "[Deprecated] Use: --expose-ports. - Publish a port from the main container, same format as docker --publish.", Hidden: true},
		cli.BoolFlag{Name: "attach-on-error", Usage: "Attach shell to container if a step fails.", Hidden: true},
		cli.BoolFlag{Name: "enable-volumes", Usage: "Mount local files and directories as volumes to your wercker container, specified in your wercker.yml."},
		cli.BoolTFlag{Name: "enable-dev-steps", Hidden: true, Usage: `
		Enable internal dev steps.
		This enables:
		- internal/watch
		`},
	}

	// These flags are advanced build settings
	InternalBuildFlags = []cli.Flag{
		cli.BoolFlag{Name: "direct-mount", Usage: "Mount our binds read-write to the pipeline path."},
		cli.BoolFlag{Name: "expose-ports", Usage: "Enable ports from wercker.yml beeing exposed to the host system."},

		cli.StringSliceFlag{Name: "publish", Value: &cli.StringSlice{}, Usage: "[Deprecated] Use: --expose-ports. - Publish a port from the main container, same format as docker --publish.", Hidden: true},
		cli.BoolFlag{Name: "attach-on-error", Usage: "Attach shell to container if a step fails.", Hidden: true},
		cli.BoolFlag{Name: "enable-volumes", Usage: "Mount local files and directories as volumes to your wercker container, specified in your wercker.yml."},
		cli.BoolFlag{Name: "enable-dev-steps", Hidden: true, Usage: `
		Enable internal dev steps.
		This enables:
		- internal/watch
		`},
	}

	// Flags for advanced deploy settings
	InternalDeployFlags = []cli.Flag{
		cli.BoolFlag{Name: "expose-ports", Usage: "Enable ports from wercker.yml beeing exposed to the host system."},

		cli.StringSliceFlag{Name: "publish", Value: &cli.StringSlice{}, Usage: "[Deprecated] Use: --expose-ports. - Publish a port from the main container, same format as docker --publish.", Hidden: true},
		cli.BoolFlag{Name: "attach-on-error", Usage: "Attach shell to container if a step fails.", Hidden: true},
		cli.BoolFlag{Name: "enable-dev-steps", Hidden: true, Usage: `
		Enable internal dev steps.
		This enables:
		- internal/watch
		`},
	}

	// AWS bits
	AWSFlags = []cli.Flag{
		cli.StringFlag{Name: "aws-secret-key", Value: "", Usage: "Secret access key. Used for artifact storage."},
		cli.StringFlag{Name: "aws-access-key", Value: "", Usage: "Access key id. Used for artifact storage."},
		cli.StringFlag{Name: "s3-bucket", Value: "wercker-development", Usage: "Bucket for artifact storage."},
		cli.StringFlag{Name: "aws-region", Value: "us-east-1", Usage: "AWS region to use for artifact storage."},
	}

	// keen.io bits
	KeenFlags = []cli.Flag{
		cli.BoolFlag{Name: "keen-metrics", Usage: "Report metrics to keen.io.", Hidden: true},
		cli.StringFlag{Name: "keen-project-write-key", Value: "", Usage: "Keen write key.", Hidden: true},
		cli.StringFlag{Name: "keen-project-id", Value: "", Usage: "Keen project id.", Hidden: true},
	}

	// Wercker Reporter settings
	ReporterFlags = []cli.Flag{
		cli.BoolFlag{Name: "report", Usage: "Report logs back to wercker (requires build-id, wercker-host, wercker-token).", Hidden: true},
		cli.StringFlag{Name: "wercker-host", Usage: "Wercker host to use for wercker reporter.", Hidden: true},
		cli.StringFlag{Name: "wercker-token", Usage: "Wercker token to use for wercker reporter.", Hidden: true},
	}

	// These options might be overwritten by the wercker.yml
	ConfigFlags = []cli.Flag{
		cli.StringFlag{Name: "ignore-file", Value: ".werckerignore", Usage: "File with file patterns to ignore when copying files."},
		cli.StringFlag{Name: "source-dir", Value: "", Usage: "Source path relative to checkout root."},
		cli.Float64Flag{Name: "no-response-timeout", Value: 5, Usage: "Timeout if no script output is received in this many minutes."},
		cli.Float64Flag{Name: "command-timeout", Value: 25, Usage: "Timeout if command does not complete in this many minutes."},
		cli.StringFlag{Name: "wercker-yml", Value: "", Usage: "Specify a specific yaml file.", EnvVar: "WERCKER_YML_FILE"},
	}

	PullFlagSet = [][]cli.Flag{
		[]cli.Flag{
			cli.StringFlag{Name: "branch", Value: "", Usage: "Filter on this branch."},
			cli.StringFlag{Name: "result", Value: "", Usage: "Filter on this result (passed or failed)."},
			cli.StringFlag{Name: "output", Value: "./repository.tar", Usage: "Path to repository."},
			cli.BoolFlag{Name: "load", Usage: "Load the container into docker after downloading."},
			cli.BoolFlag{Name: "f, force", Usage: "Override output if it already exists."},
		},
	}

	GlobalFlagSet = [][]cli.Flag{
		DevFlags,
		EndpointFlags,
		AuthFlags,
	}

	DockerFlagSet = [][]cli.Flag{
		DockerFlags,
	}

	PipelineFlagSet = [][]cli.Flag{
		LocalPathFlags,
		WerckerFlags,
		DockerFlags,
		InternalBuildFlags,
		GitFlags,
		RegistryFlags,
		ArtifactFlags,
		AWSFlags,
		ConfigFlags,
	}

	DeployPipelineFlagSet = [][]cli.Flag{
		LocalPathFlags,
		WerckerFlags,
		DockerFlags,
		InternalDeployFlags,
		GitFlags,
		RegistryFlags,
		ArtifactFlags,
		AWSFlags,
		ConfigFlags,
	}

	DevPipelineFlagSet = [][]cli.Flag{
		LocalPathFlags,
		WerckerFlags,
		DockerFlags,
		InternalDevFlags,
		GitFlags,
		RegistryFlags,
		ArtifactFlags,
		AWSFlags,
		ConfigFlags,
	}

	WerckerInternalFlagSet = [][]cli.Flag{
		InternalPathFlags,
		KeenFlags,
		ReporterFlags,
	}
)

Flags for setting these options from the CLI

Functions

func AskForUpdate

func AskForUpdate() bool

AskForUpdate asks users if they want to update and returns the answer

func DumpOptions

func DumpOptions(options interface{}, indent ...string)

DumpOptions prints out a sorted list of options

func FlagsFor

func FlagsFor(flagSets ...[][]cli.Flag) []cli.Flag

func GenerateDocumentation

func GenerateDocumentation(options *core.GlobalOptions, app *cli.App) error

GenerateDocumentation generates docs for each command

func GetApp

func GetApp() *cli.App

func GetBuildPipelineFactory

func GetBuildPipelineFactory(name string) func(*core.Config, *core.PipelineOptions, *dockerlocal.Options) (core.Pipeline, error)

GetBuildPipelineFactory makes build pipelines out of arbitrarily named config sections

func GetDeployPipelineFactory

func GetDeployPipelineFactory(name string) func(*core.Config, *core.PipelineOptions, *dockerlocal.Options) (core.Pipeline, error)

GetDeployPipelineFactory makes deploy pipelines out of arbitrarily named config sections

func GetDevPipelineFactory

func GetDevPipelineFactory(name string) func(*core.Config, *core.PipelineOptions, *dockerlocal.Options) (core.Pipeline, error)

GetDevPipelineFactory makes dev pipelines out of arbitrarily named config sections

Types

type DockerBuilder

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

func NewDockerBuilder

func NewDockerBuilder(options *core.PipelineOptions, dockerOptions *dockerlocal.Options) *DockerBuilder

func (*DockerBuilder) Build

func (b *DockerBuilder) Build(ctx context.Context, env *util.Environment, config *core.BoxConfig) (*dockerlocal.DockerBox, *docker.Image, error)

Build the image and commit it so we can use it as a service

type Request

type Request struct {
	Name string `json:"name"`
}

Request contains the name needed to generate a token.

type Response

type Response struct {
	Token string `json:"token"`
}

Response from authentication endpoint

type Runner

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

Runner is the base type for running the pipelines.

func NewRunner

func NewRunner(ctx context.Context, options *core.PipelineOptions, dockerOptions *dockerlocal.Options, getPipeline pipelineGetter) (*Runner, error)

NewRunner from global options

func (*Runner) AddServices

func (p *Runner) AddServices(ctx context.Context, pipeline core.Pipeline, box core.Box) error

AddServices fetches and links the services to the base box.

func (*Runner) CleanupOldBuilds

func (p *Runner) CleanupOldBuilds() error

CleanupOldBuilds removes old builds and keeps the latest 2

func (*Runner) CopyCache

func (p *Runner) CopyCache() error

CopyCache copies the source into the HostPath

func (*Runner) CopySource

func (p *Runner) CopySource() error

CopySource copies the source into the HostPath

func (*Runner) EnsureCode

func (p *Runner) EnsureCode() (string, error)

EnsureCode makes sure the code is in the ProjectDir. NOTE(termie): When launched by kiddie-pool the ProjectPath will be set to the location where grappler checked out the code and the copy will be a little superfluous, but in the case where this is being run in Single Player Mode this copy is necessary to avoid screwing with the local dir.

func (*Runner) GetConfig

func (p *Runner) GetConfig() (*core.Config, string, error)

GetConfig parses and returns the wercker.yml file.

func (*Runner) GetPipeline

func (p *Runner) GetPipeline(rawConfig *core.Config) (core.Pipeline, error)

GetPipeline returns a pipeline based on the "build" config section

func (*Runner) GetSession

func (p *Runner) GetSession(runnerContext context.Context, containerID string) (context.Context, *core.Session, error)

GetSession attaches to the container and returns a session.

func (*Runner) ProjectDir

func (p *Runner) ProjectDir() string

ProjectDir returns the directory where we expect to find the code for this project

func (*Runner) RunStep

func (p *Runner) RunStep(shared *RunnerShared, step core.Step, order int) (*StepResult, error)

RunStep runs a step and tosses error if it fails

func (*Runner) SetupEnvironment

func (p *Runner) SetupEnvironment(runnerCtx context.Context) (*RunnerShared, error)

SetupEnvironment does a lot of boilerplate legwork and returns a pipeline, box, and session. This is a bit of a long method, but it is pretty much the entire "Setup Environment" step.

func (*Runner) StartBuild

func (p *Runner) StartBuild(options *core.PipelineOptions) *util.Finisher

StartBuild emits a BuildStarted and returns for a Finisher for the end.

func (*Runner) StartFullPipeline

func (p *Runner) StartFullPipeline(options *core.PipelineOptions) *util.Finisher

StartFullPipeline emits a FullPipelineFinished when the Finisher is called.

func (*Runner) StartStep

func (p *Runner) StartStep(ctx *RunnerShared, step core.Step, order int) *util.Finisher

StartStep emits BuildStepStarted and returns a Finisher for the end event.

type RunnerShared

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

RunnerShared holds on to the information we got from setting up our environment.

type SoftExit

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

SoftExit is a helper for determining when to show stack traces

func NewSoftExit

func NewSoftExit(options *core.GlobalOptions) *SoftExit

NewSoftExit constructor

func (*SoftExit) Exit

func (s *SoftExit) Exit(v ...interface{}) error

Exit with either an error or a panic

type StepResult

type StepResult struct {
	Success             bool
	Artifact            *core.Artifact
	PackageURL          string
	Message             string
	ExitCode            int
	WerckerYamlContents string
}

StepResult holds the info we need to report on steps

type Updater

type Updater struct {
	CurrentVersion *util.Versions
	ServerVersion  *util.Versions
	// contains filtered or unexported fields
}

Updater data structure for versions

func NewUpdater

func NewUpdater(channel string) (*Updater, error)

NewUpdater constructor

func (*Updater) DownloadURL

func (u *Updater) DownloadURL() string

DownloadURL returns the url to download the latest version

func (*Updater) DownloadVersionURL

func (u *Updater) DownloadVersionURL(version string) string

DownloadVersionURL returns the url to download the specified version

func (*Updater) Update

func (u *Updater) Update() error

Update replaces the inode of the current executable with the latest version n.b. this won't work on Windows

func (*Updater) UpdateAvailable

func (u *Updater) UpdateAvailable() bool

UpdateAvailable returns true if there's an update available

Jump to

Keyboard shortcuts

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