Skip to content

Commit

Permalink
Merge pull request #313 from stelligent/dev-1.5.1
Browse files Browse the repository at this point in the history
1.5.1 development
  • Loading branch information
cplee committed Aug 1, 2018
2 parents 11c49e8 + 1695029 commit 798ee54
Show file tree
Hide file tree
Showing 15 changed files with 217 additions and 28 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.4.7
1.5.1
6 changes: 6 additions & 0 deletions common/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ type ImageFinder interface {
FindLatestImageID(namePattern string) (string, error)
}

// AZCounter for counting availability zones in a region
type AZCounter interface {
CountAZs() (int, error)
}

// StackManager composite of all stack capabilities
type StackManager interface {
StackUpserter
Expand All @@ -48,4 +53,5 @@ type StackManager interface {
StackGetter
StackDeleter
ImageFinder
AZCounter
}
16 changes: 14 additions & 2 deletions common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ type Environment struct {
ExtraUserData string `yaml:"extraUserData,omitempty"`
} `yaml:"cluster,omitempty"`
Discovery struct {
Provider string `yaml:"provider,omitempty"`
Configuration map[string]string `yaml:"configuration,omitempty"`
Provider string `yaml:"provider,omitempty"`
Name string `yaml:"name,omitempty"`
} `yaml:"discovery,omitempty"`
VpcTarget struct {
VpcID string `yaml:"vpcId,omitempty"`
Expand All @@ -102,6 +102,7 @@ type Environment struct {
// Service defines the structure of the yml file for a service
type Service struct {
Name string `yaml:"name,omitempty"`
DeploymentStrategy string `yaml:"deploymentStrategy,omitempty"`
DesiredCount int `yaml:"desiredCount,omitempty"`
MinSize int `yaml:"minSize,omitempty"`
MaxSize int `yaml:"maxSize,omitempty"`
Expand Down Expand Up @@ -279,6 +280,16 @@ const (
StackTypeBucket = "bucket"
)

// DeploymentStrategy describes supported deployment strategies
type DeploymentStrategy string

// List of supported deployment strategies
const (
BlueGreenDeploymentStrategy DeploymentStrategy = "blue_green"
RollingDeploymentStrategy = "rolling"
ReplaceDeploymentStrategy = "replace"
)

// EnvProvider describes supported environment strategies
type EnvProvider string

Expand Down Expand Up @@ -309,6 +320,7 @@ type Task struct {
Name string
Environment string
Service string
Status string
TaskDefinition string
Cluster string
Command []string
Expand Down
19 changes: 19 additions & 0 deletions provider/aws/cloudformation.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,25 @@ func (cfnMgr *cloudformationStackManager) GetStack(stackName string) (*common.St
return stack, nil
}

// CountAZs for current region
func (cfnMgr *cloudformationStackManager) CountAZs() (int, error) {
ec2Api := cfnMgr.ec2API
resp, err := ec2Api.DescribeAvailabilityZones(&ec2.DescribeAvailabilityZonesInput{
Filters: []*ec2.Filter{
{
Name: aws.String("state"),
Values: []*string{
aws.String("available"),
},
},
},
})
if err != nil {
return 0, err
}
return len(resp.AvailabilityZones), nil
}

// FindLatestImageID for a given
func (cfnMgr *cloudformationStackManager) FindLatestImageID(namePattern string) (string, error) {
ec2Api := cfnMgr.ec2API
Expand Down
5 changes: 3 additions & 2 deletions provider/aws/task.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package aws

import (
"strings"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ecs"
"github.com/aws/aws-sdk-go/service/ecs/ecsiface"
"github.com/pkg/errors"
"github.com/stelligent/mu/common"
"strings"
)

type ecsTaskManager struct {
Expand Down Expand Up @@ -154,7 +155,6 @@ func (taskMgr *ecsTaskManager) StopTask(namespace string, environment string, ta
}

func getTaskDetail(ecsTask *ecs.Task, taskMgr *ecsTaskManager, cluster string, environment string, serviceName string) (*common.Task, error) {
log.Debugf(SvcGetTaskInfoLog, *ecsTask.TaskArn)
containers := []common.Container{}
if len(ecsTask.Containers) > Zero {
for _, container := range ecsTask.Containers {
Expand All @@ -172,6 +172,7 @@ func getTaskDetail(ecsTask *ecs.Task, taskMgr *ecsTaskManager, cluster string, e
Name: strings.Split(*ecsTask.TaskArn, TaskARNSeparator)[1],
Environment: environment,
Service: serviceName,
Status: aws.StringValue(ecsTask.LastStatus),
Containers: containers,
}
log.Debugf(SvcTaskDetailLog, task)
Expand Down
22 changes: 22 additions & 0 deletions templates/assets/common-iam.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ Resources:
Version: '2012-10-17'
Statement:
- Action:
- route53:CreateHostedZone
- route53:DeleteHostedZone
- route53:ChangeResourceRecordSets
- route53:ChangeTagsForResource
- route53:GetHostedZone
Expand All @@ -131,6 +133,26 @@ Resources:
- route53:ListResourceRecordSets
- route53:ListTagsForResource
- route53:ListTagsForResources
- route53:ListQueryLoggingConfigs
- route53:UpdateHostedZoneComment
Resource: '*'
Effect: Allow
- PolicyName: update-servicediscovery
PolicyDocument:
Version: '2012-10-17'
Statement:
- Action:
- servicediscovery:CreatePrivateDnsNamespace
- servicediscovery:CreateService
- servicediscovery:DeleteNamespace
- servicediscovery:DeleteService
- servicediscovery:GetNamespace
- servicediscovery:GetService
- servicediscovery:GetOperation
- servicediscovery:ListNamespaces
- servicediscovery:ListServices
- servicediscovery:ListOperations
- servicediscovery:UpdateService
Resource: '*'
Effect: Allow
- PolicyName: deploy-cluster
Expand Down
21 changes: 21 additions & 0 deletions templates/assets/elb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
AWSTemplateFormatVersion: '2010-09-09'
Description: MU load balancer for an environment
Parameters:
ServiceDiscoveryName:
Type: String
Description: Name for the service discovery namespace
ElbInternal:
Description: Should ELB be internal?
Type: String
Expand Down Expand Up @@ -53,6 +56,14 @@ Conditions:
- !Ref ElbInternal
- 'true'
Resources:
ServiceDiscoveryNamespace:
Type: AWS::ServiceDiscovery::PrivateDnsNamespace
Properties:
Description: !Sub Service Discovery Namespace for ${AWS::StackName}
Vpc:
Fn::ImportValue: !Sub ${VpcId}
Name:
Ref: ServiceDiscoveryName
ElbInstanceSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
Expand Down Expand Up @@ -220,3 +231,13 @@ Outputs:
Description: Arn of the ELB HTTPS Listener.
Export:
Name: !Sub ${AWS::StackName}-ElbHttpsListenerArn
ServiceDiscoveryId:
Value: !Ref ServiceDiscoveryNamespace
Description: Id of the Service Discovery Namespace
Export:
Name: !Sub ${AWS::StackName}-ServiceDiscoveryId
ServiceDiscoveryName:
Value: !Ref ServiceDiscoveryName
Description: Name of the Service Discovery Namespace
Export:
Name: !Sub ${AWS::StackName}-ServiceDiscoveryName
45 changes: 43 additions & 2 deletions templates/assets/service-ecs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ Parameters:
ImageUrl:
Type: String
Description: Docker Image URL
MaximumPercent:
Type: String
Description: Maximum percent for deployment strategy
Default: '200'
MinimumHealthyPercent:
Type: String
Description: Minimum percent for deployment strategy
Default: '100'
ServicePort:
Type: String
Description: Port exposed in service
Expand Down Expand Up @@ -139,6 +147,16 @@ Parameters:
ElbSecurityGroup:
Type: String
Description: Name of the value to import for the ELB group id
ServiceDiscoveryTTL:
Type: String
Description: The amount of time, in seconds, that you want DNS resolvers to cache the settings for this record.
Default: '60'
ServiceDiscoveryId:
Type: String
Description: Name of the value to import for the service discovery namespace id
ServiceDiscoveryName:
Type: String
Description: Name of the value to import for the service discovery namespace name
Conditions:
HasPathPattern:
"Fn::Not":
Expand Down Expand Up @@ -208,6 +226,21 @@ Conditions:
- !Ref TaskCpu
- ''
Resources:
EcsServiceName:
Type: AWS::ServiceDiscovery::Service
Properties:
DnsConfig:
NamespaceId:
Fn::ImportValue: !Sub ${ServiceDiscoveryId}
DnsRecords:
- Type: A
TTL: !Ref ServiceDiscoveryTTL
- Type: SRV
TTL: !Ref ServiceDiscoveryTTL
HealthCheckCustomConfig:
FailureThreshold: 5
Name:
Ref: ServiceName
EcsService:
Type: AWS::ECS::Service
DependsOn:
Expand All @@ -217,8 +250,8 @@ Resources:
Fn::ImportValue: !Sub ${EcsCluster}
DesiredCount: !Ref ServiceDesiredCount
DeploymentConfiguration:
MaximumPercent: 200
MinimumHealthyPercent: 100
MaximumPercent: !Ref MaximumPercent
MinimumHealthyPercent: !Ref MinimumHealthyPercent
LaunchType:
Fn::ImportValue: !Sub ${LaunchType}
NetworkConfiguration:
Expand Down Expand Up @@ -249,6 +282,9 @@ Resources:
- !Ref EcsServiceRoleArn
- !Ref AWS::NoValue
TaskDefinition: !Ref MicroserviceTaskDefinition
ServiceRegistries:
- RegistryArn: !Sub ${EcsServiceName.Arn}
Port: !Ref ServicePort
ServiceLogGroup:
Type: AWS::Logs::LogGroup
DeletionPolicy: Delete
Expand Down Expand Up @@ -282,13 +318,18 @@ Resources:
- HasLinks
- !Ref Links
- !Ref AWS::NoValue
#DnsSearchDomains:
#- Fn::ImportValue: !Sub ${ServiceDiscoveryName}
Environment:
{{with .Environment}}
{{range $key, $val := .}}
- Name: {{$key}}
Value: !Sub {{$val}}
{{end}}
{{end}}
- Name: _SERVICE_DISCOVERY_NAME
Value:
Fn::ImportValue: !Sub ${ServiceDiscoveryName}
- Name: _PRIMARY_ELB_LISTENER
Value:
Fn::If:
Expand Down
4 changes: 4 additions & 0 deletions templates/assets/vpc-target.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ Parameters:
ElbSubnetIds:
Description: ELB subnet ids
Type: CommaDelimitedList
AZCount:
Description: Number of availability zones to use
Type: String
Default: '3'
Resources:
WaitHandle:
Type: "AWS::CloudFormation::WaitConditionHandle"
Expand Down
24 changes: 18 additions & 6 deletions templates/assets/vpc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ Parameters:
Description: SSH Key to add to bastion
Type: String
Default: ''
AZCount:
Description: Number of availability zones to use
Type: String
Default: '3'
Conditions:
HasElbSubnetAZ1:
"Fn::Not":
Expand All @@ -111,10 +115,14 @@ Conditions:
- !Ref ElbSubnetAZ2CidrBlock
- ''
HasElbSubnetAZ3:
"Fn::Not":
"Fn::And":
- "Fn::Equals":
- !Ref ElbSubnetAZ3CidrBlock
- ''
- !Ref AZCount
- '3'
- "Fn::Not":
- "Fn::Equals":
- !Ref ElbSubnetAZ3CidrBlock
- ''
HasInstanceSubnetAZ1:
"Fn::Not":
- "Fn::Equals":
Expand All @@ -126,10 +134,14 @@ Conditions:
- !Ref InstanceSubnetAZ2CidrBlock
- ''
HasInstanceSubnetAZ3:
"Fn::Not":
"Fn::And":
- "Fn::Equals":
- !Ref InstanceSubnetAZ3CidrBlock
- ''
- !Ref AZCount
- '3'
- "Fn::Not":
- "Fn::Equals":
- !Ref InstanceSubnetAZ3CidrBlock
- ''
IsPublicElb:
"Fn::Not":
- "Fn::Equals":
Expand Down
2 changes: 1 addition & 1 deletion wiki
Submodule wiki updated from aae91d to 504e62

0 comments on commit 798ee54

Please sign in to comment.