Documentation ¶
Overview ¶
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 ¶
- type Image
- type Service
- type Task
- type TaskDefinition
- func (d *TaskDefinition) DescribeTaskDefinition(taskDefinitionName string) (*ecs.TaskDefinition, error)
- func (d *TaskDefinition) NewContainerDefinition(baseDefinition *ecs.ContainerDefinition, newImage *Image) (*ecs.ContainerDefinition, error)
- func (d *TaskDefinition) RegisterTaskDefinition(baseDefinition *ecs.TaskDefinition, newImage *Image) (*ecs.TaskDefinition, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Service ¶
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 ¶
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) DescribeService ¶
DescribeService gets a current service in the cluster.
func (*Service) Rollback ¶
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 ¶
UpdateService updates the service with a new task definition, and wait during update action.
type Task ¶
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 ¶
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.
type TaskDefinition ¶
type TaskDefinition struct {
// contains filtered or unexported fields
}
TaskDefinition has image and task definition information.
func NewTaskDefinition ¶
func NewTaskDefinition(profile, region string) *TaskDefinition
NewTaskDefinition initializes aws ecs API client, and returns a task definition struct.
func (*TaskDefinition) DescribeTaskDefinition ¶
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 ¶
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 ¶
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.