lib/capistrano/asg/tasks/rolling.rake in capistrano-asg-rolling-0.4.1 vs lib/capistrano/asg/tasks/rolling.rake in capistrano-asg-rolling-0.5.0

- old
+ new

@@ -48,11 +48,11 @@ if config.rolling_update? && !config.instances.empty? logger.info 'Stopping instance(s)...' config.instances.stop logger.info 'Creating AMI(s)...' - amis = config.instances.create_ami(description: revision_log_message) + amis = config.instances.create_ami(description: revision_log_message, tags: Capistrano::ASG::Rolling::Tags.ami_tags) logger.info 'Updating Launch Template(s) with the new AMI(s)...' launch_templates = config.autoscale_groups.launch_templates updated_templates = launch_templates.update(amis: amis, description: revision_log_message) @@ -60,11 +60,11 @@ updated_templates.each do |launch_template| config.autoscale_groups.with_launch_template(launch_template).each do |group| group.start_instance_refresh(launch_template) logger.verbose "Successfully started Instance Refresh on Auto Scaling Group **#{group.name}**." - rescue Capistrano::ASG::Rolling::InstanceRefreshFailed => e + rescue Capistrano::ASG::Rolling::StartInstanceRefreshError => e logger.info "Failed to start Instance Refresh on Auto Scaling Group **#{group.name}**: #{e.message}" end end config.launch_templates.merge(updated_templates) @@ -89,11 +89,11 @@ logger.warning("AMI **#{ami.id}** does not exist for Launch Template **#{version.name}** version **#{version.version}**.") next end # Only clean up when AMI was tagged by us. - next if exists && !ami.tag?('capistrano-asg-rolling:version') + next if exists && (!ami.tag?('capistrano-asg-rolling:version') || !ami.tag?('capistrano-asg-rolling:gem-version')) logger.verbose "Deleting Launch Template **#{version.name}** version **#{version.version}**..." version.delete next if deleted @@ -122,12 +122,11 @@ if config.instances.any? config.instances.each do |instance| instance.auto_terminate = false end else - logger.error 'No instances have been launched. Are you using a configuration with rolling deployments?' - exit 1 + raise Capistrano::ASG::Rolling::NoInstancesLaunched end end desc 'Do a test deployment: run the deploy task but do not trigger the update ASG task and do not automatically terminate instances' task :deploy_test do @@ -136,12 +135,11 @@ if config.instances.any? config.instances.each do |instance| instance.auto_terminate = false end else - logger.error 'No instances have been launched. Are you using a configuration with rolling deployments?' - exit 1 + raise Capistrano::ASG::Rolling::NoInstancesLaunched end invoke 'deploy' end @@ -154,13 +152,19 @@ instance = group.instances.sample if instance logger.info "Instance **#{instance.id}** entering standby state..." group.enter_standby(instance) + logger.info 'Stopping instance...' + instance.stop + logger.info 'Creating AMI...' - ami = instance.create_ami(description: revision_log_message) + ami = instance.create_ami(description: revision_log_message, tags: Capistrano::ASG::Rolling::Tags.ami_tags) + logger.info 'Starting instance...' + instance.start + logger.info "Instance **#{instance.id}** exiting standby state..." group.exit_standby(instance) logger.info 'Updating Launch Template with the new AMI...' launch_template = group.launch_template @@ -175,17 +179,18 @@ desc 'Get status of instance refresh' task :instance_refresh_status do if config.wait_for_instance_refresh? groups = config.autoscale_groups.to_h { |group| [group.name, group] } + completed_groups = [] while groups.any? groups.each do |name, group| refresh = group.latest_instance_refresh if refresh.nil? || refresh.completed? logger.info "Auto Scaling Group: **#{name}**, completed with status '#{refresh.status}'." if refresh.completed? - groups.delete(name) + completed_groups.push groups.delete(name) elsif !refresh.percentage_complete.nil? logger.info "Auto Scaling Group: **#{name}**, #{refresh.percentage_complete}% completed, status '#{refresh.status}'." else logger.info "Auto Scaling Group: **#{name}**, status '#{refresh.status}'." end @@ -194,8 +199,11 @@ wait_for = config.instance_refresh_polling_interval logger.info "Instance refresh(es) not completed, waiting #{wait_for} seconds..." sleep wait_for end + + failed = completed_groups.any? { |group| group.latest_instance_refresh.failed? } + raise Capistrano::ASG::Rolling::InstanceRefreshFailed if failed end end end