Class: Moonshot::DeploymentMechanism::CodeDeploy
- Inherits:
-
Object
- Object
- Moonshot::DeploymentMechanism::CodeDeploy
- Includes:
- CredsHelper, Moonshot::DoctorHelper, ResourcesHelper
- Defined in:
- lib/moonshot/deployment_mechanism/code_deploy.rb
Overview
This mechanism is used to deploy software to an auto-scaling group within a stack. It currently only works with the S3Bucket ArtifactRepository.
Usage: class MyApp < Moonshot::CLI
self.artifact_repository = S3Bucket.new('foobucket')
self.deployment_mechanism = CodeDeploy.new(asg: 'AutoScalingGroup')
end
Constant Summary collapse
- DEFAULT_ROLE_NAME =
'CodeDeployRole'
Instance Attribute Summary
Attributes included from ResourcesHelper
Instance Method Summary collapse
- #deploy_cli_hook(parser) ⇒ Object (also: #push_cli_hook)
- #deploy_hook(artifact_repo, version_name) ⇒ Object
-
#initialize(asg: [], optional_asg: [], role: DEFAULT_ROLE_NAME, app_name: nil, group_name: nil, config_name: 'CodeDeployDefault.OneAtATime') ⇒ CodeDeploy
constructor
rubocop:disable Metrics/ParameterLists.
-
#post_create_hook ⇒ Object
rubocop:enable Metrics/ParameterLists.
- #post_delete_hook ⇒ Object
- #post_update_hook ⇒ Object
- #status_hook ⇒ Object
Methods included from Moonshot::DoctorHelper
Methods included from CredsHelper
#as_client, #cd_client, #cf_client, #ec2_client, #iam_client, #s3_client
Constructor Details
#initialize(asg: [], optional_asg: [], role: DEFAULT_ROLE_NAME, app_name: nil, group_name: nil, config_name: 'CodeDeployDefault.OneAtATime') ⇒ CodeDeploy
rubocop:disable Metrics/ParameterLists
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/moonshot/deployment_mechanism/code_deploy.rb', line 41 def initialize( asg: [], optional_asg: [], role: DEFAULT_ROLE_NAME, app_name: nil, group_name: nil, config_name: 'CodeDeployDefault.OneAtATime' ) @asg_logical_ids = Array(asg) @optional_asg_logical_ids = Array(optional_asg) @app_name = app_name @group_name = group_name @codedeploy_role = role @codedeploy_config = config_name @ignore_app_stop_failures = false end |
Instance Method Details
#deploy_cli_hook(parser) ⇒ Object Also known as: push_cli_hook
107 108 109 110 111 112 113 114 |
# File 'lib/moonshot/deployment_mechanism/code_deploy.rb', line 107 def deploy_cli_hook(parser) parser.on('--ignore-app-stop-failures', TrueClass, 'Continue deployment on ApplicationStop failures') do |v| puts "ignore = #{v}" @ignore_app_stop_failures = v end parser end |
#deploy_hook(artifact_repo, version_name) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/moonshot/deployment_mechanism/code_deploy.rb', line 82 def deploy_hook(artifact_repo, version_name) success = true deployment_id = nil ilog.start_threaded 'Creating Deployment' do |s| res = create_deployment(artifact_repo, version_name) deployment_id = res.deployment_id s.continue "Created Deployment #{deployment_id.blue}." success = wait_for_deployment(deployment_id, s) end handle_deployment_failure(deployment_id) unless success end |
#post_create_hook ⇒ Object
rubocop:enable Metrics/ParameterLists
59 60 61 62 63 64 |
# File 'lib/moonshot/deployment_mechanism/code_deploy.rb', line 59 def post_create_hook create_application_if_needed create_deployment_group_if_needed wait_for_asg_capacity end |
#post_delete_hook ⇒ Object
96 97 98 99 100 101 102 103 104 105 |
# File 'lib/moonshot/deployment_mechanism/code_deploy.rb', line 96 def post_delete_hook ilog.start 'Cleaning up CodeDeploy Application' do |s| if application_exists? cd_client.delete_application(application_name: app_name) s.success "Deleted CodeDeploy Application '#{app_name}'." else s.success "CodeDeploy Application '#{app_name}' does not exist." end end end |
#post_update_hook ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'lib/moonshot/deployment_mechanism/code_deploy.rb', line 66 def post_update_hook post_create_hook unless deployment_group_ok? # rubocop:disable Style/GuardClause delete_deployment_group create_deployment_group_if_needed end end |
#status_hook ⇒ Object
75 76 77 78 79 80 |
# File 'lib/moonshot/deployment_mechanism/code_deploy.rb', line 75 def status_hook t = Moonshot::UnicodeTable.new('') application = t.add_leaf("CodeDeploy Application: #{app_name}") application.add_line(code_deploy_status_msg) t.draw_children end |