ecspresso

package module
v0.6.5 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2018 License: MIT Imports: 16 Imported by: 0

README

ecspresso

ecspresso is a deployment tool for Amazon ECS.

(pronounced same as "espresso")

Usage

usage: ecspresso --config=CONFIG [<flags>] <command> [<args> ...]

Flags:
  --help           Show context-sensitive help (also try --help-long and --help-man).
  --config=CONFIG  config file

Commands:
  help [<command>...]
    Show help.

  deploy [<flags>]
    deploy service

  create [<flags>]
    create service

  status [<flags>]
    show status of service

  rollback [<flags>]
    rollback service

  delete [<flags>]
    delete service

  run [<flags>]
    run task

For more options for sub-commands, See ecspresso sub-command --help.

Configuration file

YAML format.

region: ap-northeast-1
cluster: default
service: myService
task_definition: myTask.json
timeout: 5m

ecspresso works as below.

  • Register a new task definition from JSON file.
    • JSON file is allowed both of formats as below.
      • aws ecs describe-task-definition output.
      • aws ecs register-task-definition --cli-input-json input.
    • Replace {{ env `FOO` `bar` }} syntax in the JSON file to environment variable "FOO".
      • If "FOO" is not defined, replaced by "bar"
    • Replace {{ must_env `FOO` }} syntax in the JSON file to environment variable "FOO".
      • If "FOO" is not defined, abort immediately.
  • Update a service definition.
  • Wait a service stable.
  • Run a new task.

Example of deploy

$ ecspresso deploy --config config.yaml
2017/11/09 23:20:13 myService/default Starting deploy
Service: myService
Cluster: default
TaskDefinition: myService:3
Deployments:
    PRIMARY myService:3 desired:1 pending:0 running:1
Events:
2017/11/09 23:20:13 myService/default Creating a new task definition by myTask.json
2017/11/09 23:20:13 myService/default Registering a new task definition...
2017/11/09 23:20:13 myService/default Task definition is registered myService:4
2017/11/09 23:20:13 myService/default Updating service...
2017/11/09 23:20:13 myService/default Waiting for service stable...(it will take a few minutes)
2017/11/09 23:23:23 myService/default  PRIMARY myService:4 desired:1 pending:0 running:1
2017/11/09 23:23:29 myService/default Service is stable now. Completed!

Scale out/in

To change desired count of the service, specify --tasks option.

If --skip-task-definition is set, task definition will not be registered.

$ ecspresso deploy --config config.yaml --tasks 10 --skip-task-definition

Example of create

escpresso can create service by service_definition JSON file and task_definition.

$ ecspresso create --config config.yaml
...
# config.yaml
service_definition: service.json

example of service.json below.

{
  "role": "ecsServiceRole",
  "desiredCount": 2,
  "loadBalancers": [
    {
      "containerName": "myLoadbalancer",
      "containerPort": 80,
      "targetGroupArn": "arn:aws:elasticloadbalancing:[region]:[account-id]:targetgroup/{target-name}/201ae83c14de522d"
    }
  ]
}

Keys are same format as aws ecs describe-services output.

  • deploymentConfiguration
  • launchType
  • loadBalancers
  • networkConfiguration
  • placementConstraint
  • placementStrategy
  • role

Example of run task

$ ecspresso run --config config.yaml --task-def=db-migrate.json

Notes

Deploy to Fargate

If you want to deploy services to Fargate, task-definition and service-definition requires some settings.

For task definition,

  • requiresCompatibilities (required "FARGATE")
  • networkMode (required "awsvpc")
  • cpu (required)
  • memory (required)
  • executionRoleArn (optional)
{
  "taskDefinition": {
    "networkMode": "awsvpc",
    "requiresCompatibilities": [
      "FARGATE"
    ],
    "cpu": "1024",
    "memory": "2048",
    // ...
}

For service-definition,

  • launchType (required "FARGATE")
  • networkConfiguration (required "awsvpcConfiguration")
{
  "launchType": "FARGATE",
  "networkConfiguration": {
    "awsvpcConfiguration": {
      "subnets": [
        "subnet-aaaaaaaa",
        "subnet-bbbbbbbb"
      ],
      "securityGroups": [
        "sg-11111111"
      ],
      "assignPublicIp": "ENABLED"
    }
  },
  // ...
}

LICENCE

MIT

Author

KAYAC Inc.

Documentation

Index

Constants

View Source
const KeepDesiredCount = -1

Variables

View Source
var TerminalWidth = 90

Functions

This section is empty.

Types

type App added in v0.2.2

type App struct {
	Service string
	Cluster string
	// contains filtered or unexported fields
}

func NewApp added in v0.2.2

func NewApp(conf *Config) (*App, error)

func (*App) Create added in v0.2.2

func (d *App) Create(opt CreateOption) error

func (*App) Delete added in v0.6.0

func (d *App) Delete(opt DeleteOption) error

func (*App) Deploy added in v0.2.2

func (d *App) Deploy(opt DeployOption) error

func (*App) DescribeServiceDeployments added in v0.2.2

func (d *App) DescribeServiceDeployments(ctx context.Context, startedAt time.Time) (int, error)

func (*App) DescribeServiceStatus added in v0.2.2

func (d *App) DescribeServiceStatus(ctx context.Context, events int) (*ecs.Service, error)

func (*App) DescribeServicesInput added in v0.2.2

func (d *App) DescribeServicesInput() *ecs.DescribeServicesInput

func (*App) DescribeTask added in v0.6.0

func (d *App) DescribeTask(ctx context.Context, task *ecs.Task) error

func (*App) DescribeTasksInput added in v0.6.0

func (d *App) DescribeTasksInput(task *ecs.Task) *ecs.DescribeTasksInput

func (*App) FindRollbackTarget added in v0.2.2

func (d *App) FindRollbackTarget(ctx context.Context, taskDefinitionArn string) (string, error)

func (*App) GetLogEvents added in v0.6.0

func (d *App) GetLogEvents(ctx context.Context, logGroup string, logStream string, startedAt time.Time) (int, error)

func (*App) GetLogEventsInput added in v0.6.0

func (d *App) GetLogEventsInput(logGroup string, logStream string, startAt int64) *cloudwatchlogs.GetLogEventsInput

func (*App) GetLogInfo added in v0.6.0

func (d *App) GetLogInfo(task *ecs.Task, lc *ecs.LogConfiguration) (string, string)

func (*App) LoadServiceDefinition added in v0.2.2

func (d *App) LoadServiceDefinition(path string) (*ecs.CreateServiceInput, error)

func (*App) LoadTaskDefinition added in v0.2.2

func (d *App) LoadTaskDefinition(path string) (*ecs.TaskDefinition, error)

func (*App) Log added in v0.2.2

func (d *App) Log(v ...interface{})

func (*App) Name added in v0.2.2

func (d *App) Name() string

func (*App) RegisterTaskDefinition added in v0.2.2

func (d *App) RegisterTaskDefinition(ctx context.Context, td *ecs.TaskDefinition) (*ecs.TaskDefinition, error)

func (*App) Rollback added in v0.2.2

func (d *App) Rollback(opt RollbackOption) error

func (*App) Run added in v0.6.0

func (d *App) Run(opt RunOption) error

func (*App) RunTask added in v0.6.0

func (d *App) RunTask(ctx context.Context, tdArn string, sv *ecs.Service) (*ecs.Task, error)

func (*App) Start added in v0.2.2

func (d *App) Start() (context.Context, context.CancelFunc)

func (*App) Status added in v0.2.2

func (d *App) Status(opt StatusOption) error

func (*App) UpdateService added in v0.2.2

func (d *App) UpdateService(ctx context.Context, taskDefinitionArn string, count *int64, force bool, sv *ecs.Service) error

func (*App) WaitRunTask added in v0.6.0

func (d *App) WaitRunTask(ctx context.Context, task *ecs.Task, lc *ecs.LogConfiguration, startedAt time.Time) error

func (*App) WaitServiceStable added in v0.2.2

func (d *App) WaitServiceStable(ctx context.Context, startedAt time.Time) error

type Config added in v0.2.2

type Config struct {
	Region                string        `yaml:"region"`
	Service               string        `yaml:"service"`
	Cluster               string        `yaml:"cluster"`
	TaskDefinitionPath    string        `yaml:"task_definition"`
	ServiceDefinitionPath string        `yaml:"service_definition"`
	Timeout               time.Duration `yaml:"timeout"`
}

func NewDefaultConfig added in v0.2.2

func NewDefaultConfig() *Config

func (*Config) Validate added in v0.2.2

func (c *Config) Validate() error

type CreateOption added in v0.2.2

type CreateOption struct {
	DryRun       *bool
	DesiredCount *int64
}

type DeleteOption added in v0.6.0

type DeleteOption struct {
	DryRun *bool
	Force  *bool
}

type DeployOption added in v0.2.2

type DeployOption struct {
	DryRun             *bool
	DesiredCount       *int64
	SkipTaskDefinition *bool
	ForceNewDeployment *bool
}

type RollbackOption added in v0.2.2

type RollbackOption struct {
	DryRun                   *bool
	DeregisterTaskDefinition *bool
}

type RunOption added in v0.6.0

type RunOption struct {
	DryRun         *bool
	TaskDefinition *string
}

type ServiceDefinition added in v0.2.2

type ServiceDefinition struct {
	DeploymentConfiguration       *ecs.DeploymentConfiguration `json:"deploymentConfiguration"`
	DesiredCount                  *int64                       `json:"desiredCount"`
	HealthCheckGracePeriodSeconds *int64                       `json:"healthCheckGracePeriod_seconds"`
	LaunchType                    *string                      `json:"launchType"`
	LoadBalancers                 []*ecs.LoadBalancer          `json:"loadBalancers"`
	NetworkConfiguration          *ecs.NetworkConfiguration    `json:"networkConfiguration"`
	PlacementConstraints          []*ecs.PlacementConstraint   `json:"placementConstraints"`
	PlacementStrategy             []*ecs.PlacementStrategy     `json:"placementStrategy"`
	PlatformVersion               *string                      `json:"platformVersion"`
	Role                          *string                      `json:"role"`
	SchedulingStrategy            *string                      `json:"schedulingStrategy"`
	ServiceRegistries             []*ecs.ServiceRegistry       `json:"serviceRegistries"`
}

type StatusOption added in v0.2.2

type StatusOption struct {
	Events *int
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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