Skip to content

Commit

Permalink
Allow the deployment group name to be configurable in order to suppor…
Browse files Browse the repository at this point in the history
…t and alternate multi-ASG strategy (#121)

Added the group_name: option to the CodeDeploy deployment mechanism, to support alternative deployment strategies.
  • Loading branch information
cpliakas authored and askreet committed Sep 14, 2016
1 parent b45f47c commit d5eb3ba
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions lib/moonshot/deployment_mechanism/code_deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,24 @@ class Moonshot::DeploymentMechanism::CodeDeploy # rubocop:disable ClassLength
# IAM role with AWSCodeDeployRole policy. CodeDeployRole is considered as
# default role if its not specified.
# @param app_name [String, nil] (nil)
# The name of the CodeDeploy Application and Deployment Group. By default,
# this is the same as the stack name, and probably what you want. If you
# have multiple deployments in a single Stack, they must have unique names.
# The name of the CodeDeploy Application. By default, this is the same as
# the stack name, and probably what you want. If you have multiple
# deployments in a single Stack, they must have unique names.
# @param group_name [String, nil] (nil)
# The name of the CodeDeploy Deployment Group. By default, this is the same
# as app_name.
# @param config_name [String]
# Name of the Deployment Config to use for CodeDeploy, By default we use
# CodeDeployDefault.OneAtATime.
def initialize(
asg: [],
role: 'CodeDeployRole',
app_name: nil,
group_name: nil,
config_name: 'CodeDeployDefault.OneAtATime')
@asg_logical_ids = asg.is_a?(Array) ? asg : [asg]
@app_name = app_name
@group_name = group_name
@codedeploy_role = role
@codedeploy_config = config_name
end
Expand Down Expand Up @@ -64,7 +69,7 @@ def deploy_hook(artifact_repo, version_name)
ilog.start_threaded 'Creating Deployment' do |s|
res = cd_client.create_deployment(
application_name: app_name,
deployment_group_name: app_name,
deployment_group_name: group_name,
revision: revision_for_artifact_repo(artifact_repo, version_name),
deployment_config_name: @codedeploy_config,
description: "Deploying version #{version_name}"
Expand All @@ -88,12 +93,18 @@ def post_delete_hook

private

# By default, use the stack name as the application and deployment group
# names, unless one has been provided.
# By default, use the stack name as the application name, unless one has been
# provided.
def app_name
@app_name || stack.name
end

# By default, use the stack name as the deployment group name, unless one has
# been provided.
def group_name
@group_name || stack.name
end

def pretty_app_name
"CodeDeploy Application #{app_name.blue}"
end
Expand Down Expand Up @@ -179,13 +190,13 @@ def application_exists?

def deployment_group
cd_client.get_deployment_group(
application_name: app_name, deployment_group_name: app_name)
application_name: app_name, deployment_group_name: group_name)
.deployment_group_info
end

def deployment_group_exists?
cd_client.get_deployment_group(
application_name: app_name, deployment_group_name: app_name)
application_name: app_name, deployment_group_name: group_name)
true
rescue Aws::CodeDeploy::Errors::ApplicationDoesNotExistException,
Aws::CodeDeploy::Errors::DeploymentGroupDoesNotExistException
Expand Down Expand Up @@ -215,15 +226,15 @@ def delete_deployment_group
ilog.start "Deleting #{pretty_deploy_group}." do |s|
cd_client.delete_deployment_group(
application_name: app_name,
deployment_group_name: app_name)
deployment_group_name: group_name)
s.success
end
end

def create_deployment_group
cd_client.create_deployment_group(
application_name: app_name,
deployment_group_name: app_name,
deployment_group_name: group_name,
service_role_arn: role.arn,
auto_scaling_groups: asg_names)
end
Expand Down

0 comments on commit d5eb3ba

Please sign in to comment.