Skip to content

Commit

Permalink
Merge pull request #27 from stormcat24/feature/0.1.5
Browse files Browse the repository at this point in the history
Support bluegreen deployment of multi ELB on autoscaling group
  • Loading branch information
Akinori Yamada committed Aug 14, 2015
2 parents 590de28 + 97a6751 commit 81a56f9
Show file tree
Hide file tree
Showing 22 changed files with 329 additions and 309 deletions.
48 changes: 24 additions & 24 deletions Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 22 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ Apply definition.
### Blue Green Deployment
ecs-formation supports blue-green deployment.
ecs-formation supports blue-green deployment.
#### Requirements on ecs-formation
Expand All @@ -146,7 +146,7 @@ ecs-formation supports blue-green deployment.
#### Define Blue Green Deployment
Make management file of Blue Green Deployment file in bluegreen directory.
Make management file of Blue Green Deployment file in bluegreen directory.
```bash
(path-to-path/test-ecs-formation/bluegreen) $ vim test-bluegreen.yml
Expand Down Expand Up @@ -174,12 +174,31 @@ Apply blue green deployment.
(path-to-path/test-ecs-formation $ ecs-formation bluegreen apply
```
if with `--nodeploy` option, not update services. Only swap ELB on blue and green groups.
if with `--nodeploy` option, not update services. Only swap ELB on blue and green groups.
```bash
(path-to-path/test-ecs-formation $ ecs-formation bluegreen apply --nodeploy
```
If autoscaling group have several different ELB, you should specify array property of `chain_elb`. ecs-formation can swap `chain_elb` ELB group with main ELB group at the same time.
```Ruby
(path-to-path/test-ecs-formation/bluegreen) $ vim test-bluegreen.yml
blue:
cluster: test-blue
service: test-service
autoscaling_group: test-blue-asg
green:
cluster: test-green
service: test-service
autoscaling_group: test-green-asg
primary_elb: test-elb-primary
standby_elb: test-elb-standby
chain_elb:
- primary_elb: test-internal-elb-primary
standby_elb: test-internal-elb-standby
```
License
===
See [LICENSE](LICENSE).
Expand Down
23 changes: 11 additions & 12 deletions aws/ecs_service_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package aws
import (
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/service/ecs"
"github.com/stormcat24/ecs-formation/schema"
"github.com/aws/aws-sdk-go/aws"
)

Expand All @@ -12,29 +11,29 @@ type EcsServiceApi struct {
Region *string
}

func (self *EcsServiceApi) CreateService(cluster string, service schema.Service) (*ecs.CreateServiceOutput, error) {
func (self *EcsServiceApi) CreateService(cluster string, service string, desiredCount int64, lb []*ecs.LoadBalancer, taskDef string, role string) (*ecs.CreateServiceOutput, error) {

svc := ecs.New(&aws.Config{
Region: self.Region,
Credentials: self.Credentials,
})

params := &ecs.CreateServiceInput{
ServiceName: aws.String(service.Name),
ServiceName: aws.String(service),
Cluster: aws.String(cluster),
DesiredCount: &service.DesiredCount,
LoadBalancers: toLoadBalancers(&service.LoadBalancers),
TaskDefinition: aws.String(service.TaskDefinition),
DesiredCount: &desiredCount,
LoadBalancers: lb,
TaskDefinition: aws.String(taskDef),
}

if service.Role != "" {
params.Role = aws.String(service.Role)
if role != "" {
params.Role = aws.String(role)
}

return svc.CreateService(params)
}

func (self *EcsServiceApi) UpdateService(cluster string, service schema.Service) (*ecs.UpdateServiceOutput, error) {
func (self *EcsServiceApi) UpdateService(cluster string, service string, desiredCount int64, taskDef string) (*ecs.UpdateServiceOutput, error) {

svc := ecs.New(&aws.Config{
Region: self.Region,
Expand All @@ -43,9 +42,9 @@ func (self *EcsServiceApi) UpdateService(cluster string, service schema.Service)

params := &ecs.UpdateServiceInput{
Cluster: aws.String(cluster),
Service: aws.String(service.Name),
DesiredCount: &service.DesiredCount,
TaskDefinition: aws.String(service.TaskDefinition),
Service: aws.String(service),
DesiredCount: &desiredCount,
TaskDefinition: aws.String(taskDef),
}

return svc.UpdateService(params)
Expand Down
68 changes: 1 addition & 67 deletions aws/ecs_task_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ import (
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ecs"
"github.com/stormcat24/ecs-formation/schema"
"github.com/stormcat24/ecs-formation/util"
"strings"
)

type EcsTaskApi struct {
Expand All @@ -28,76 +25,13 @@ func (self *EcsTaskApi) DescribeTaskDefinition(defName string) (*ecs.DescribeTas
return svc.DescribeTaskDefinition(params)
}

func (self *EcsTaskApi) RegisterTaskDefinition(taskName string, containers []*schema.ContainerDefinition) (*ecs.RegisterTaskDefinitionOutput, error) {
func (self *EcsTaskApi) RegisterTaskDefinition(taskName string, conDefs []*ecs.ContainerDefinition, volumes []*ecs.Volume) (*ecs.RegisterTaskDefinitionOutput, error) {

svc := ecs.New(&aws.Config{
Region: self.Region,
Credentials: self.Credentials,
})

conDefs := []*ecs.ContainerDefinition{}
volumes := []*ecs.Volume{}

for _, con := range containers {

var commands []*string
if (len(con.Command) > 0) {
for _, token := range strings.Split(con.Command, " ") {
commands = append(commands, aws.String(token))
}
} else {
commands = nil
}

var entryPoints []*string
if (len(con.EntryPoint) > 0) {
for _, token := range strings.Split(con.EntryPoint, " ") {
entryPoints = append(entryPoints, aws.String(token))
}
} else {
entryPoints = nil
}

portMappings, err := toPortMappings(con.Ports)
if err != nil {
return &ecs.RegisterTaskDefinitionOutput{}, err
}

volumeItems, err := CreateVolumeInfoItems(con.Volumes)
if err != nil {
return &ecs.RegisterTaskDefinitionOutput{}, err
}

mountPoints := []*ecs.MountPoint{}
for _, vp := range volumeItems {
volumes = append(volumes, vp.Volume)

mountPoints = append(mountPoints, vp.MountPoint)
}

volumesFrom, err := toVolumesFroms(con.VolumesFrom)
if err != nil {
return &ecs.RegisterTaskDefinitionOutput{}, err
}

conDef := &ecs.ContainerDefinition{
CPU: &con.CpuUnits,
Command: commands,
EntryPoint: entryPoints,
Environment: toKeyValuePairs(con.Environment),
Essential: &con.Essential,
Image: aws.String(con.Image),
Links: util.ConvertPointerString(con.Links),
Memory: &con.Memory,
MountPoints: mountPoints,
Name: aws.String(con.Name),
PortMappings: portMappings,
VolumesFrom: volumesFrom,
}

conDefs = append(conDefs, conDef)
}

params := &ecs.RegisterTaskDefinitionInput{
ContainerDefinitions: conDefs,
Family: aws.String(taskName),
Expand Down

0 comments on commit 81a56f9

Please sign in to comment.