common

package
v0.1.14 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2017 License: MIT Imports: 49 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StackTypeVpc      StackType = "vpc"
	StackTypeTarget             = "target"
	StackTypeCluster            = "cluster"
	StackTypeConsul             = "consul"
	StackTypeRepo               = "repo"
	StackTypeService            = "service"
	StackTypePipeline           = "pipeline"
	StackTypeDatabase           = "database"
	StackTypeBucket             = "bucket"
)

List of valid stack types

View Source
const (
	EnvSubCmdCount          = 5
	FirstValueIndex         = 0
	SingleAliasIndex        = 0
	SvcSubCmdCount          = 6
	SvcShowFormatFlagIndex  = 0
	SvcLogFlagCount         = 3
	EnvLogFollowFlagIndex   = 0
	EnvLogDurationFlagIndex = 1
	SvcLogServiceFlagIndex  = 0
	SvcLogFollowFlagIndex   = 1
	SvcLogDurationFlagIndex = 2
	ShowFlagCount           = 1
	ExeArgsCmdIndex         = 1
	EnvLogsFlagCount        = 2
	SvcPushTagFlagIndex     = 0
	SvcDeployTagFlagIndex   = 0
	SvcUndeploySvcFlagIndex = 1
	TaskGUIDIndex           = 1
	DefaultLogDurationValue = 1 * time.Minute
	SvcCmd                  = "service"
	SvcAlias                = "svc"
	SvcUsage                = "options for managing services"
	SvcShowUsage            = "[<service>]"
	SvcLogUsage             = "show service logs"
	SvcLogArgUsage          = "<environment> [<filter>...]"
	SvcLogServiceFlagUsage  = "service name to view logs for"
	SvcExeServiceFlagUsage  = "service name for command"
	SvcExeTaskFlagUsage     = "task definition arn"
	SvcExeClusterFlagUsage  = "cluster name or full arn"
	SvcPushTagFlagUsage     = "tag to push"
	SvcDeployTagFlagUsage   = "tag to deploy"
	TagFlagName             = "tag, t"
	EnvCmd                  = "environment"
	EnvAlias                = "env"
	EnvUsage                = "options for managing environments"
	EnvArgUsage             = "<environment>"
	Tag                     = "tag"
	UpsertCmd               = "upsert"
	UpsertAlias             = "up"
	UpsertUsage             = "create/update an environment"
	ListCmd                 = "list"
	TerminateCmd            = "terminate"
	TerminateAlias          = "term"
	TerminateUsage          = "terminate an environment"
	ListAlias               = "ls"
	ListUsage               = "list environments"
	ShowCmd                 = "show"
	ShowCmdUsage            = "show environment details"
	ExeCmd                  = "exec"
	ExeUsage                = "execute a command in environment"
	ExeArgs                 = "<environment> <command>"
	LogsCmd                 = "logs"
	LogsArgs                = "<environment> [<filter>...]"
	LogsUsage               = "show environment logs"
	Format                  = "format"
	FormatFlag              = "format, f"
	FormatFlagUsage         = "output format, either 'json' or 'cli' (default: cli)"
	FormatFlagDefault       = "cli"
	Follow                  = "follow"
	FollowFlag              = "follow, f"
	ServiceFlag             = "service, s"
	TaskFlagName            = "task"
	TaskFlagVisible         = true
	TaskFlag                = "task, t"
	ClusterFlagName         = "cluster"
	ClusterFlag             = "cluster, c"
	ClusterFlagVisible      = true
	FollowUsage             = "follow logs for latest changes"
	SearchDuration          = "search-duration"
	SearchDurationUsage     = "duration to go into the past for searching (e.g. 5m for 5 minutes)"
	SearchDurationFlag      = "search-duration, t"
	PushCmd                 = "push"
	SvcPushCmdUsage         = "push service to repository"
	DeployCmd               = "deploy"
	SvcDeployCmdUsage       = "deploy service to environment"
	UndeployCmd             = "undeploy"
	SvcUndeployCmdUsage     = "undeploy service from environment"
	SvcUndeployArgsUsage    = "<environment> [<service>]"
)

Constants for available command names and options

View Source
const (
	Zero                        = 0
	ECSRunTaskDefaultCount      = 1
	Empty                       = ""
	Space                       = " "
	Spaces                      = "   "
	LineChar                    = "-"
	ForwardSlash                = "/"
	NewLine                     = "\n"
	NA                          = "N/A"
	UnknownValue                = "???"
	JSON                        = "json"
	HomeIPAddress               = "127.0.0.1"
	DefaultVersion              = "0.0.0-local"
	LastUpdateTime              = "2006-01-02 15:04:05"
	CPU                         = "CPU"
	MEMORY                      = "MEMORY"
	AMI                         = "AMI"
	AZ                          = "AZ"
	BoolStringFormat            = "%v"
	IntStringFormat             = "%d"
	HeaderValueFormat           = "%s:\t%s\n"
	SvcPipelineFormat           = HeaderValueFormat
	HeadNewlineHeader           = "%s:\n"
	SvcDeploymentsFormat        = HeadNewlineHeader
	SvcContainersFormat         = "\n%s for %s:\n"
	KeyValueFormat              = "%s %s"
	StackFormat                 = "%s:\t%s (%s)\n"
	UnmanagedStackFormat        = "%s:\tunmanaged\n"
	BaseURLKey                  = "BASE_URL"
	BaseURLValueKey             = "BaseUrl"
	SvcPipelineURLLabel         = "Pipeline URL"
	SvcDeploymentsLabel         = "Deployments"
	SvcContainersLabel          = "Containers"
	BaseURLHeader               = "Base URL"
	SvcCodePipelineURLKey       = "CodePipelineUrl"
	SvcVersionKey               = "version"
	SvcCodePipelineNameKey      = "PipelineName"
	ECSClusterKey               = "EcsCluster"
	EC2Instance                 = "EC2 Instance"
	VPCStack                    = "VPC Stack"
	ContainerInstances          = "Container Instances"
	BastionHost                 = "Bastion Host"
	BastionHostKey              = "BastionHost"
	ClusterStack                = "Cluster Stack"
	TypeHeader                  = "Type"
	ConnectedHeader             = "Connected"
	CPUAvail                    = "CPU Avail"
	MEMAvail                    = "Mem Avail"
	NumTasks                    = "# Tasks"
	SvcImageURLKey              = "ImageUrl"
	SvcStageHeader              = "Stage"
	SvcServiceHeader            = "Service"
	ServicesHeader              = "Services"
	SvcActionHeader             = "Action"
	SvcStatusHeader             = "Status"
	SvcRevisionHeader           = "Revision"
	SvcMuVersionHeader          = "Mu Version"
	SvcImageHeader              = "Image"
	EnvironmentHeader           = "Environment"
	SvcStackHeader              = "Stack"
	SvcLastUpdateHeader         = "Last Update"
	ECSServiceNameParameterKey  = "ServiceName"
	ListServices                = "ListServices"
	DescribeInstances           = "DescribeInstances"
	ListTasks                   = "ListTasks"
	DescribeTasks               = "DescribeTasks"
	DescribeContainerInstances  = "DescribeContainerInstances"
	ECSTaskDefinitionOutputKey  = "MicroserviceTaskDefinition"
	ECSClusterOutputKey         = "EcsCluster"
	NoEnvValidation             = "environment must be provided"
	NoCmdValidation             = "command must be provided"
	EmptyCmdValidation          = "command must not be an empty string"
	SvcCmdTaskExecutingLog      = "Creating service executor...\n"
	SvcCmdTaskResultLog         = "Service executor complete with result:\n%s\n"
	SvcCmdStackLog              = "Getting stack '%s'..."
	SvcCmdTaskErrorLog          = "The following error has occurred executing the command:  '%v'"
	EcsConnectionLog            = "Connecting to ECS service"
	ExecuteCommandStartLog      = "Executing command '[%s]' on environment '%s' for service '%s'\n"
	ExecuteCommandFinishLog     = "Command execution complete\n"
	ExecuteECSInputParameterLog = "Environment: %s, Service: %s, Cluster: %s, Task: %s"
	ExecuteECSInputContentsLog  = "ECS Input Contents: %s\n"
	ExecuteECSResultContentsLog = "ECS Result Contents: %s, %s\n"
	SvcGetTaskInfoLog           = "Getting task info for task: %s"
	SvcTaskDetailLog            = "Task Detail: %s"
	SvcInstancePrivateIPLog     = "Instance Private IP for Instance ID %s: %s"
	SvcListTasksLog             = "Listing tasks for Environment: %s, Cluster: %s, Service: %s"
	ECSAvailabilityZoneKey      = "ecs.availability-zone"
	ECSInstanceTypeKey          = "ecs.instance-type"
	ECSAMIKey                   = "ecs.ami-id"
	TaskARNSeparator            = ForwardSlash
)

Constants to prevent multiple updates when making changes.

View Source
const (
	EnvAliasCount    = 1
	SvcAliasCount    = 1
	FailExitCode     = 1
	Test             = "test"
	TestEnv          = "fooenv"
	TestSvc          = "foosvc"
	TestCmd          = "foocmd"
	TestTaskARN      = "ARN/TEST"
	Help             = "help"
	GetStackName     = "GetStack"
	RunTaskName      = "RunTask"
	NameMessage      = "Name should match"
	UsageMessage     = "Usage should match"
	AliasLenMessage  = "Aliases len should match"
	AliasMessage     = "Aliases should match"
	ArgsUsageMessage = "ArgsUsage should match"
	SubCmdLenMessage = "Subcommands len should match"
	FlagLenMessage   = "Flag len should match"
	FlagMessage      = "Flag should match"
)

Constants used during testing

Variables

View Source
var Bold = color.New(color.Bold).SprintFunc()

Bold is the specifier for bold formatted text values

EnvironmentAMITableHeader is the header for the instance details

EnvironmentShowHeader is the header for the environment table

PipeLineServiceHeader is the header for the pipeline service table

ServiceTableHeader is the header for the service table

SvcEnvironmentTableHeader is the header array for the environment table

SvcPipelineTableHeader is the header array for the pipeline table

View Source
var SvcTaskContainerHeader = []string{"Task", "Container", "Instance", "Private IP"}

SvcTaskContainerHeader is the header for container task detail

Functions

func CreateStackName

func CreateStackName(stackType StackType, names ...string) string

CreateStackName will create a name for a stack

func CreateTableSection added in v0.1.13

func CreateTableSection(writer io.Writer, header []string) *tablewriter.Table

CreateTableSection creates the standard output table used

func GetStackOverrides added in v0.1.8

func GetStackOverrides(stackName string) interface{}

GetStackOverrides will get the overrides from the config

func GetVersion

func GetVersion() string

GetVersion returns the current version of the app

func MapApply added in v0.1.8

func MapApply(dest, src interface{})

MapApply recursively applies map values from source to destination

func SetVersion added in v0.1.3

func SetVersion(v string)

SetVersion returns the current version of the app

func SetupLogging

func SetupLogging(verbosity int)

SetupLogging - verbosity 0=error, 1=info, 2=debug

Types

type ClusterInstanceLister

type ClusterInstanceLister interface {
	ListInstances(clusterName string) ([]*ecs.ContainerInstance, error)
}

ClusterInstanceLister for getting cluster instances

type ClusterManager

type ClusterManager interface {
	ClusterInstanceLister
	RepositoryAuthenticator
}

ClusterManager composite of all cluster capabilities

type Config

type Config struct {
	Environments []Environment `yaml:"environments,omitempty"`
	Service      Service       `yaml:"service,omitempty"`
	Basedir      string        `yaml:"-"`
	Repo         struct {
		Name     string
		Slug     string
		Revision string
		Provider string
	} `yaml:"-"`
	Templates map[string]interface{} `yaml:"templates,omitempty"`
}

Config defines the structure of the yml file for the mu config

type Container added in v0.1.13

type Container struct {
	Name      string
	Instance  string
	PrivateIP string
}

Container describes container details

type Context

type Context struct {
	Config          Config
	StackManager    StackManager
	ClusterManager  ClusterManager
	ElbManager      ElbManager
	RdsManager      RdsManager
	ParamManager    ParamManager
	PipelineManager PipelineManager
	LogsManager     LogsManager
	DockerManager   DockerManager
	DockerOut       io.Writer
	TaskManager     TaskManager
}

Context defines the context object passed around

func NewContext

func NewContext() *Context

NewContext create a new context object

func (*Context) InitializeConfig added in v0.1.7

func (ctx *Context) InitializeConfig(configReader io.Reader) error

InitializeConfig loads config object

func (*Context) InitializeConfigFromFile added in v0.1.7

func (ctx *Context) InitializeConfigFromFile(muFile string) error

InitializeConfigFromFile loads config from file

func (*Context) InitializeContext added in v0.1.7

func (ctx *Context) InitializeContext(profile string, region string, dryrun bool) error

InitializeContext loads manager objects

type Database added in v0.1.12

type Database struct {
	Name              string `yaml:"name,omitempty"`
	InstanceClass     string `yaml:"instanceClass,omitempty"`
	Engine            string `yaml:"engine,omitempty"`
	IamAuthentication bool   `yaml:"iamAuthentication,omitempty"`
	MasterUsername    string `yaml:"masterUsername,omitempty"`
	AllocatedStorage  string `yaml:"allocatedStorage,omitempty"`
}

Database definition

type DockerImageBuilder added in v0.1.3

type DockerImageBuilder interface {
	ImageBuild(contextDir string, relDockerfile string, tags []string, dockerOut io.Writer) error
}

DockerImageBuilder for creating docker images

type DockerImagePusher added in v0.1.3

type DockerImagePusher interface {
	ImagePush(image string, registryAuth string, dockerOut io.Writer) error
}

DockerImagePusher for pushing docker images

type DockerManager added in v0.1.3

type DockerManager interface {
	DockerImageBuilder
	DockerImagePusher
}

DockerManager composite of all cluster capabilities

type ECSRunTaskResult added in v0.1.13

type ECSRunTaskResult *ecs.RunTaskOutput

ECSRunTaskResult describes the output result from ECS call to RunTask

type ElbManager added in v0.1.7

type ElbManager interface {
	ElbRuleLister
}

ElbManager composite of all cluster capabilities

type ElbRuleLister added in v0.1.7

type ElbRuleLister interface {
	ListRules(listenerArn string) ([]*elbv2.Rule, error)
}

ElbRuleLister for getting cluster instances

type Environment

type Environment struct {
	Name         string `yaml:"name,omitempty"`
	Loadbalancer struct {
		HostedZone  string `yaml:"hostedzone,omitempty"`
		Name        string `yaml:"name,omitempty"`
		Certificate string `yaml:"certificate,omitempty"`
		Internal    bool   `yaml:"internal,omitempty"`
	} `yaml:"loadbalancer,omitempty"`
	Cluster struct {
		InstanceType      string `yaml:"instanceType,omitempty"`
		ImageID           string `yaml:"imageId,omitempty"`
		InstanceTenancy   string `yaml:"instanceTenancy,omitempty"`
		DesiredCapacity   int    `yaml:"desiredCapacity,omitempty"`
		MaxSize           int    `yaml:"maxSize,omitempty"`
		KeyName           string `yaml:"keyName,omitempty"`
		SSHAllow          string `yaml:"sshAllow,omitempty"`
		ScaleOutThreshold int    `yaml:"scaleOutThreshold,omitempty"`
		ScaleInThreshold  int    `yaml:"scaleInThreshold,omitempty"`
		HTTPProxy         string `yaml:"httpProxy,omitempty"`
	} `yaml:"cluster,omitempty"`
	Discovery struct {
		Provider      string            `yaml:"provider,omitempty"`
		Configuration map[string]string `yaml:"configuration,omitempty"`
	} `yaml:"discovery,omitempty"`
	VpcTarget struct {
		VpcID        string   `yaml:"vpcId,omitempty"`
		EcsSubnetIds []string `yaml:"ecsSubnetIds,omitempty"`
		ElbSubnetIds []string `yaml:"elbSubnetIds,omitempty"`
	} `yaml:"vpcTarget,omitempty"`
}

Environment defines the structure of the yml file for an environment

type GitInfo added in v0.1.10

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

GitInfo represents pertinent git information

type ImageFinder

type ImageFinder interface {
	FindLatestImageID(namePattern string) (string, error)
}

ImageFinder for finding latest image

type JSONOutput added in v0.1.13

type JSONOutput struct {
	Values [1]struct {
		Key   string `json:"key"`
		Value string `json:"value"`
	} `json:"values"`
}

JSONOutput common json definition

type LogsManager added in v0.1.10

type LogsManager interface {
	LogsViewer
}

LogsManager composite of all logs capabilities

type LogsViewer added in v0.1.10

type LogsViewer interface {
	ViewLogs(logGroup string, searchDuration time.Duration, follow bool, filter string, callback func(string, string, int64)) error
}

LogsViewer for viewing cloudwatch logs

type ParamGetter added in v0.1.12

type ParamGetter interface {
	GetParam(name string) (string, error)
}

ParamGetter for getting parameters

type ParamManager added in v0.1.12

type ParamManager interface {
	ParamGetter
	ParamSetter
}

ParamManager composite of all param capabilities

type ParamSetter added in v0.1.12

type ParamSetter interface {
	SetParam(name string, value string) error
}

ParamSetter for setting parameters

type Pipeline added in v0.1.5

type Pipeline struct {
	Source struct {
		Provider string `yaml:"provider,omitempty"`
		Repo     string `yaml:"repo,omitempty"`
		Branch   string `yaml:"branch,omitempty"`
	} `yaml:"source,omitempty"`
	Build struct {
		Type        string `yaml:"type,omitempty"`
		ComputeType string `yaml:"computeType,omitempty"`
		Image       string `yaml:"image,omitempty"`
	} `yaml:"build,omitempty"`
	Acceptance struct {
		Environment string `yaml:"environment,omitempty"`
		Type        string `yaml:"type,omitempty"`
		ComputeType string `yaml:"computeType,omitempty"`
		Image       string `yaml:"image,omitempty"`
	} `yaml:"acceptance,omitempty"`
	Production struct {
		Environment string `yaml:"environment,omitempty"`
	} `yaml:"production,omitempty"`
	MuBaseurl string `yaml:"muBaseurl,omitempty"`
	MuVersion string `yaml:"muVersion,omitempty"`
}

Pipeline definition

type PipelineGitInfoGetter added in v0.1.10

type PipelineGitInfoGetter interface {
	GetGitInfo(pipelineName string) (GitInfo, error)
}

PipelineGitInfoGetter for getting the git revision

type PipelineManager added in v0.1.5

type PipelineManager interface {
	PipelineStateLister
	PipelineGitInfoGetter
}

PipelineManager composite of all cluster capabilities

type PipelineStateLister added in v0.1.5

type PipelineStateLister interface {
	ListState(pipelineName string) ([]*codepipeline.StageState, error)
}

PipelineStateLister for getting cluster instances

type RdsIamAuthenticationSetter added in v0.1.12

type RdsIamAuthenticationSetter interface {
	SetIamAuthentication(dbInstanceIdentifier string, enabled bool, dbEngine string) error
}

RdsIamAuthenticationSetter for getting db instances

type RdsManager added in v0.1.12

type RdsManager interface {
	RdsIamAuthenticationSetter
}

RdsManager composite of all cluster capabilities

type RepositoryAuthenticator added in v0.1.3

type RepositoryAuthenticator interface {
	AuthenticateRepository(repoURL string) (string, error)
}

RepositoryAuthenticator auths for a repo

type Service

type Service struct {
	Name            string                 `yaml:"name,omitempty"`
	DesiredCount    int                    `yaml:"desiredCount,omitempty"`
	Dockerfile      string                 `yaml:"dockerfile,omitempty"`
	ImageRepository string                 `yaml:"imageRepository,omitempty"`
	Port            int                    `yaml:"port,omitempty"`
	HealthEndpoint  string                 `yaml:"healthEndpoint,omitempty"`
	CPU             int                    `yaml:"cpu,omitempty"`
	Memory          int                    `yaml:"memory,omitempty"`
	Environment     map[string]interface{} `yaml:"environment,omitempty"`
	PathPatterns    []string               `yaml:"pathPatterns,omitempty"`
	Priority        int                    `yaml:"priority,omitempty"`
	Pipeline        Pipeline               `yaml:"pipeline,omitempty"`
	Database        Database               `yaml:"database,omitempty"`
}

Service defines the structure of the yml file for a service

type Stack

type Stack struct {
	ID             string
	Name           string
	Status         string
	StatusReason   string
	LastUpdateTime time.Time
	Tags           map[string]string
	Outputs        map[string]string
	Parameters     map[string]string
}

Stack summary

type StackDeleter

type StackDeleter interface {
	DeleteStack(stackName string) error
}

StackDeleter for deleting stacks

type StackGetter

type StackGetter interface {
	GetStack(stackName string) (*Stack, error)
}

StackGetter for getting stacks

type StackLister

type StackLister interface {
	ListStacks(stackType StackType) ([]*Stack, error)
}

StackLister for listing stacks

type StackManager

StackManager composite of all stack capabilities

type StackType

type StackType string

StackType describes supported stack types

type StackUpserter

type StackUpserter interface {
	UpsertStack(stackName string, templateBodyReader io.Reader, parameters map[string]string, tags map[string]string) error
}

StackUpserter for applying changes to a stack

type StackWaiter

type StackWaiter interface {
	AwaitFinalStatus(stackName string) *Stack
}

StackWaiter for waiting on stack status to be final

type Task added in v0.1.13

type Task struct {
	Name           string
	Environment    string
	Service        string
	TaskDefinition string
	Cluster        string
	Command        string
	Containers     []Container
}

Task describes task definition

type TaskCommandExecutor added in v0.1.13

type TaskCommandExecutor interface {
	ExecuteCommand(task Task) (ECSRunTaskResult, error)
}

TaskCommandExecutor for executing commands against an environment

type TaskContainerLister added in v0.1.13

type TaskContainerLister interface {
	ListTasks(environment string, serviceName string) ([]Task, error)
}

TaskContainerLister for listing tasks with containers

type TaskManager added in v0.1.13

type TaskManager interface {
	TaskContainerLister
	TaskCommandExecutor
}

TaskManager composite of all task capabilities

func NewTaskManager added in v0.1.13

func NewTaskManager(ec2API ec2iface.EC2API, ecsAPI ecsiface.ECSAPI, stackManager StackGetter) (TaskManager, error)

NewTaskManager need for testing

Jump to

Keyboard shortcuts

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