Skip to content

Commit

Permalink
Merge pull request #313 from YOwatari/capacity-provider-strategy
Browse files Browse the repository at this point in the history
Add CapacityProviderStrategy in CodeDeploy AppSpec
  • Loading branch information
fujiwara committed Jul 30, 2021
2 parents 870bfbc + 5f5e5d0 commit 67b75fb
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
24 changes: 20 additions & 4 deletions appspec/spec.go
Expand Up @@ -58,6 +58,15 @@ func NewWithService(sv *ecs.Service, tdArn string) (*AppSpec, error) {
},
}
}
if sv.CapacityProviderStrategy != nil {
for _, strategy := range sv.CapacityProviderStrategy {
resource.TargetService.Properties.CapacityProviderStrategy = append(resource.TargetService.Properties.CapacityProviderStrategy, &CapacityProviderStrategy{
CapacityProvider: strategy.CapacityProvider,
Base: strategy.Base,
Weight: strategy.Weight,
})
}
}
spec.Resources = append(spec.Resources, resource)
return spec, nil
}
Expand All @@ -72,10 +81,11 @@ type TargetService struct {
}

type Properties struct {
TaskDefinition *string `yaml:"TaskDefinition,omitempty"`
LoadBalancerInfo *LoadBalancerInfo `yaml:"LoadBalancerInfo,omitempty"`
PlatformVersion *string `yaml:"PlatformVersion,omitempty"`
NetworkConfiguration *NetworkConfiguration `yaml:"NetworkConfiguration,omitempty"`
TaskDefinition *string `yaml:"TaskDefinition,omitempty"`
LoadBalancerInfo *LoadBalancerInfo `yaml:"LoadBalancerInfo,omitempty"`
PlatformVersion *string `yaml:"PlatformVersion,omitempty"`
NetworkConfiguration *NetworkConfiguration `yaml:"NetworkConfiguration,omitempty"`
CapacityProviderStrategy []*CapacityProviderStrategy `yaml:"CapacityProviderStrategy,omitempty"`
}

type LoadBalancerInfo struct {
Expand All @@ -93,6 +103,12 @@ type AwsVpcConfiguration struct {
Subnets []*string `yaml:"Subnets,omitempty"`
}

type CapacityProviderStrategy struct {
CapacityProvider *string `yaml:"CapacityProvider,omitempty""`
Base *int64 `yaml:"Base,omitempty"`
Weight *int64 `yaml:"Weight,omitempty"`
}

type Hook struct {
BeforeInstall string `yaml:"BeforeInstall,omitempty"`
AfterInstall string `yaml:"AfterInstall,omitempty"`
Expand Down
12 changes: 12 additions & 0 deletions appspec/spec_test.go
Expand Up @@ -34,6 +34,18 @@ var expected = &appspec.AppSpec{
AssignPublicIp: aws.String("ENABLED"),
},
},
CapacityProviderStrategy: []*appspec.CapacityProviderStrategy{
{
CapacityProvider: aws.String("FARGATE_SPOT"),
Base: aws.Int64(1),
Weight: aws.Int64(2),
},
{
CapacityProvider: aws.String("FARGATE"),
Base: aws.Int64(0),
Weight: aws.Int64(1),
},
},
},
},
},
Expand Down
7 changes: 7 additions & 0 deletions appspec/test.yml
Expand Up @@ -14,6 +14,13 @@ Resources:
Subnets: ["subnet-1234abcd", "subnet-5678abcd"]
SecurityGroups: ["sg-12345678"]
AssignPublicIp: "ENABLED"
CapacityProviderStrategy:
- Base: 1
CapacityProvider: "FARGATE_SPOT"
Weight: 2
- Base: 0
CapacityProvider: "FARGATE"
Weight: 1
Hooks:
- BeforeInstall: "LambdaFunctionToValidateBeforeInstall"
- AfterInstall: "LambdaFunctionToValidateAfterTraffic"
Expand Down

0 comments on commit 67b75fb

Please sign in to comment.