Class: Dev::Template::Aws::Ci
- Inherits:
-
BaseInterface
- Object
- BaseInterface
- Dev::Template::Aws::Ci
- Defined in:
- lib/firespring_dev_commands/templates/ci.rb
Overview
Class contains rake templates for managing your ci/cd resources
Instance Attribute Summary collapse
-
#cloudformation ⇒ Object
readonly
Returns the value of attribute cloudformation.
Attributes inherited from BaseInterface
Instance Method Summary collapse
-
#create_create_task! ⇒ Object
Create the rake task for creating the codepipeline.
-
#create_delete_task! ⇒ Object
Create the rake task for deleting the codepipeline.
-
#create_status_task! ⇒ Object
Create the rake task for the aws codepipeline status method.
-
#create_update_task! ⇒ Object
Create the rake task for updating the codepipeline.
-
#initialize(cloudformation, exclude: []) ⇒ Ci
constructor
Base interface template customized for codepipelines which require a pipeline pattern which will match the pipeline name.
Methods inherited from BaseInterface
Constructor Details
#initialize(cloudformation, exclude: []) ⇒ Ci
Base interface template customized for codepipelines which require a pipeline pattern which will match the pipeline name
11 12 13 14 15 16 |
# File 'lib/firespring_dev_commands/templates/ci.rb', line 11 def initialize(cloudformation, exclude: []) @cloudformations = Array(cloudformation).sort_by(&:name) raise 'must specify an arry of cloudformation objects' unless @cloudformations.all?(Dev::Aws::Cloudformation) super(exclude:) end |
Instance Attribute Details
#cloudformation ⇒ Object (readonly)
Returns the value of attribute cloudformation.
8 9 10 |
# File 'lib/firespring_dev_commands/templates/ci.rb', line 8 def cloudformation @cloudformation end |
Instance Method Details
#create_create_task! ⇒ Object
Create the rake task for creating the codepipeline
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/firespring_dev_commands/templates/ci.rb', line 19 def create_create_task! # Have to set a local variable to be accessible inside of the instance_eval block exclude = @exclude cloudformations = @cloudformations return if exclude.include?(:status) DEV_COMMANDS_TOP_LEVEL.instance_eval do namespace :ci do desc 'Create the ci cloudformation stack in aws' task create: %w(init ensure_aws_credentials) do LOG.info next if cloudformations.empty? # Start create on all stacks without waiting so they are created in parallel cloudformations.each do |cloudformation| next if cloudformation.exist? cloudformation.create(should_wait: false) end LOG.info 'Waiting for all stacks to finish create' # Wait until all stacks have finished creating cloudformations.each(&:create_wait) LOG.info "Stack create finished at #{Time.now.to_s.light_yellow}" LOG.info raise 'Some stacks failed to create' if cloudformations.any?(&:failed?) end end end end |
#create_delete_task! ⇒ Object
Create the rake task for deleting the codepipeline
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/firespring_dev_commands/templates/ci.rb', line 85 def create_delete_task! # Have to set a local variable to be accessible inside of the instance_eval block exclude = @exclude cloudformations = @cloudformations return if exclude.include?(:status) DEV_COMMANDS_TOP_LEVEL.instance_eval do namespace :ci do desc 'Delete the ci cloudformation stack in aws' task delete: %w(init ensure_aws_credentials) do LOG.info next if cloudformations.empty? # Start delete on all stacks without waiting so they are deleted in parallel cloudformations.each do |cloudformation| next unless cloudformation.exist? cloudformation.delete(should_wait: false) end LOG.info 'Waiting for all stacks to finish delete' # Wait until all stacks have finished creating cloudformations.each(&:delete_wait) LOG.info "Stack delete finished at #{Time.now.to_s.light_yellow}" LOG.info raise 'Some stacks failed to update' if cloudformations.any?(&:failed?) end end end end |
#create_status_task! ⇒ Object
Create the rake task for the aws codepipeline status method
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/firespring_dev_commands/templates/ci.rb', line 118 def create_status_task! # Have to set a local variable to be accessible inside of the instance_eval block exclude = @exclude cloudformations = @cloudformations return if exclude.include?(:status) DEV_COMMANDS_TOP_LEVEL.instance_eval do namespace :ci do desc 'Show the current status of the pipelines associated with your branch' task status: %w(init ensure_aws_credentials) do LOG.info next if cloudformations.empty? pattern = /#{cloudformations.map(&:name).join('|')}/ pipelines = Dev::Aws::CodePipeline.new.pipelines(pattern).sort_by(&:name) LOG.info "No pipelines found matching #{pattern.source.gsub('|', ' OR ')}" if pipelines.empty? pipelines.each do |pipeline| Dev::Aws::CodePipeline.new.status(pipeline.name) LOG.info end LOG.info end end end end |
#create_update_task! ⇒ Object
Create the rake task for updating the codepipeline
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/firespring_dev_commands/templates/ci.rb', line 52 def create_update_task! # Have to set a local variable to be accessible inside of the instance_eval block exclude = @exclude cloudformations = @cloudformations return if exclude.include?(:status) DEV_COMMANDS_TOP_LEVEL.instance_eval do namespace :ci do desc 'Update the ci cloudformation stack in aws' task update: %w(init ensure_aws_credentials) do LOG.info next if cloudformations.empty? # Start update on all stacks without waiting so they are updated in parallel cloudformations.each do |cloudformation| next unless cloudformation.exist? cloudformation.update(should_wait: false) end LOG.info 'Waiting for all stacks to finish update' # Wait until all stacks have finished creating cloudformations.each(&:update_wait) LOG.info "Stack update finished at #{Time.now.to_s.light_yellow}" LOG.info raise 'Some stacks failed to update' if cloudformations.any?(&:failed?) end end end end |