ecs-goploy: github.com/crowdworks/ecs-goploy/deploy Index | Files

package deploy

import "github.com/crowdworks/ecs-goploy/deploy"

Package deploy provides simple functions for deploy ECS.

Usage:

import "github.com/crowdworks/ecs-goploy/deploy"

Service update

When you want to update service in ECS, please use this package as follows.

Construct a new Service, then use deploy functions.

s, err := deploy.NewService("cluster", "service-name", "nginx:stable", nil, 5 * time.Minute, true, "", "")
if err != nil {
    log.Fatalf("[ERROR] %v", err)
}

// deploy new image
if err := s.Deploy(); err != nil {
    log.Fatalf("[ERROR] %v", err)
}

Or you can write a custom deploy recipe as you like.

For example:

s, err := deploy.NewService("cluster", "service-name", "nginx:stable", nil, 5 * time.Minute, true, "", "")
if err != nil {
    log.Fatal(err)
}

// get the current service
service, err := s.DescribeService()
if err != nil {
    log.Fatal(err)
}
currentTaskDefinition, err := s.TaskDefinition.DescribeTaskDefinition(service)
if err != nil {
    log.Fatal(err)
}

newTaskDefinition, err := s.RegisterTaskDefinition(currentTaskDefinition, s.NewImage)
if err != nil {
    log.Fatal(err)
}

// Do something

err = s.UpdateService(service, newTaskDefinition)
if err != nil {
    // Do something
}
log.Println("[INFO] Deploy success")

Run task

When you want to run task on ECS at once, plese use this package as follows.

For example:

task, err := ecsdeploy.NewTask("cluster", "container-name", "nginx:stable", "echo hoge", "sample-task-definition:1", (5 * time.Minute), "", "")
if err != nil {
    log.Fatal(err)
}
if _, err := task.Run(); err != nil {
    log.Fatal(err)
}
log.Println("[INFO] Task success")

Index

Package Files

config.go deploy.go service.go task.go task_definition.go

type Image Uses

type Image struct {

    // Docker image repository.
    Repository string

    // Docker image tag.
    Tag string
}

Image has repository and tag string of docker image.

type Service Uses

type Service struct {

    // Name of ECS cluster.
    Cluster string

    // Name of ECS service.
    Name string

    // Name of base task definition of deploy.
    BaseTaskDefinition *string

    // TaskDefinition struct to call aws API.
    TaskDefinition *TaskDefinition

    // New image for deploy.
    NewImage *Image

    // Wait time when update service.
    // This script monitors ECS service for new task definition to be running after call update service API.
    Timeout time.Duration

    // If deploy failed, rollback to current task definition.
    EnableRollback bool
    // contains filtered or unexported fields
}

Service has target ECS information, client of aws-sdk-go, tasks information and timeout seconds.

func NewService Uses

func NewService(cluster, name, imageWithTag string, baseTaskDefinition *string, timeout time.Duration, enableRollback bool, profile, region string) (*Service, error)

NewService returns a new Service struct, and initialize aws ecs API client. Separates imageWithTag into repository and tag, then sets a NewImage for deploy.

func (*Service) Deploy Uses

func (s *Service) Deploy() error

Deploy runs deploy commands and handle errors.

func (*Service) DescribeService Uses

func (s *Service) DescribeService() (*ecs.Service, error)

DescribeService gets a current service in the cluster.

func (*Service) Rollback Uses

func (s *Service) Rollback(service *ecs.Service, currentTaskDefinition *ecs.TaskDefinition) error

Rollback updates the service with current task definition. This method call update-service API and does not wait for execution to end.

func (*Service) UpdateService Uses

func (s *Service) UpdateService(service *ecs.Service, taskDefinition *ecs.TaskDefinition) error

UpdateService updates the service with a new task definition, and wait during update action.

type Task Uses

type Task struct {

    // Name of ECS cluster.
    Cluster string

    // Name of the container for override task definition.
    Name string

    // Name of base task definition for run task.
    BaseTaskDefinition *string

    // TaskDefinition struct to call aws API.
    TaskDefinition *TaskDefinition

    // New image for deploy.
    NewImage *Image

    // Task command which run on ECS.
    Command []*string

    // Wait time when run task.
    // This script monitors ECS task for new task definition to be running after call run task API.
    Timeout time.Duration
    // contains filtered or unexported fields
}

Task has target ECS information, client of aws-sdk-go, command and timeout seconds.

func NewTask Uses

func NewTask(cluster, name, imageWithTag, command string, baseTaskDefinition *string, timeout time.Duration, profile, region string) (*Task, error)

NewTask returns a new Task struct, and initialize aws ecs API client. Separates imageWithTag into repository and tag, then set NewImage for deploy.

func (*Task) Run Uses

func (t *Task) Run() ([]*ecs.Task, error)

Run regists a new task definition and run task on ECS.

func (*Task) RunTask Uses

func (t *Task) RunTask(taskDefinition *ecs.TaskDefinition) ([]*ecs.Task, error)

RunTask calls run-task API.

type TaskDefinition Uses

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

TaskDefinition has image and task definition information.

func NewTaskDefinition Uses

func NewTaskDefinition(profile, region string) *TaskDefinition

NewTaskDefinition initializes aws ecs API client, and returns a task definition struct.

func (*TaskDefinition) DescribeTaskDefinition Uses

func (d *TaskDefinition) DescribeTaskDefinition(taskDefinitionName string) (*ecs.TaskDefinition, error)

DescribeTaskDefinition gets a task definition. The family for the latest ACTIVE revision, family and revision (family:revision) for a specific revision in the family, or full Amazon Resource Name (ARN) of the task definition to describe.

func (*TaskDefinition) NewContainerDefinition Uses

func (d *TaskDefinition) NewContainerDefinition(baseDefinition *ecs.ContainerDefinition, newImage *Image) (*ecs.ContainerDefinition, error)

NewContainerDefinition updates image tag in the given container definition. If the container definition is not target container, returns the givien definition.

func (*TaskDefinition) RegisterTaskDefinition Uses

func (d *TaskDefinition) RegisterTaskDefinition(baseDefinition *ecs.TaskDefinition, newImage *Image) (*ecs.TaskDefinition, error)

RegisterTaskDefinition registers new task definition if needed. If newTask is not set, returns a task definition which same as the given task definition.

Package deploy imports 12 packages (graph) and is imported by 1 packages. Updated 2017-07-13. Refresh now. Tools for package owners.