eb_deployer 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +5 -0
- data/lib/eb_deployer.rb +24 -31
- data/lib/eb_deployer/application.rb +7 -10
- data/lib/eb_deployer/aws_driver/beanstalk.rb +11 -2
- data/lib/eb_deployer/component.rb +40 -0
- data/lib/eb_deployer/config_loader.rb +12 -15
- data/lib/eb_deployer/default_component.rb +37 -0
- data/lib/eb_deployer/eb_environment.rb +6 -6
- data/lib/eb_deployer/environment.rb +38 -21
- data/lib/eb_deployer/event_poller.rb +9 -9
- data/lib/eb_deployer/version.rb +1 -1
- data/test/blue_green_deploy_test.rb +15 -0
- data/test/inplace_update_deploy_test.rb +7 -7
- data/test/multi_components_deploy_test.rb +93 -0
- data/test/tier_setting_deploy_test.rb +2 -8
- metadata +8 -4
    
        data/CHANGELOG.md
    CHANGED
    
    | @@ -1,3 +1,8 @@ | |
| 1 | 
            +
            0.4.1
         | 
| 2 | 
            +
            =====
         | 
| 3 | 
            +
            * Remove options for delete all environments ("-d --all"), because it is too destructive and not recoverable.
         | 
| 4 | 
            +
            * Experimental support for multiple components deployment.
         | 
| 5 | 
            +
             | 
| 1 6 | 
             
            0.4.0
         | 
| 2 7 | 
             
            ====
         | 
| 3 8 | 
             
            * revert back all changes from 0.3.8 to 0.3.9. Elasticbeanstalk haven't relex the real unique constain. The actually contrain is you can not have environment name cross different application
         | 
    
        data/lib/eb_deployer.rb
    CHANGED
    
    | @@ -16,6 +16,8 @@ require 'eb_deployer/application' | |
| 16 16 | 
             
            require 'eb_deployer/resource_stacks'
         | 
| 17 17 | 
             
            require 'eb_deployer/eb_environment'
         | 
| 18 18 | 
             
            require 'eb_deployer/environment'
         | 
| 19 | 
            +
            require 'eb_deployer/default_component'
         | 
| 20 | 
            +
            require 'eb_deployer/component'
         | 
| 19 21 | 
             
            require 'eb_deployer/event_poller'
         | 
| 20 22 | 
             
            require 'eb_deployer/package'
         | 
| 21 23 | 
             
            require 'eb_deployer/config_loader'
         | 
| @@ -25,15 +27,6 @@ require 'eb_deployer/version_cleaner' | |
| 25 27 |  | 
| 26 28 | 
             
            module EbDeployer
         | 
| 27 29 |  | 
| 28 | 
            -
              TIERS = [
         | 
| 29 | 
            -
                {:name=>"Worker", :type=>"SQS/HTTP", :version=>"1.0"},
         | 
| 30 | 
            -
                {:name=>"WebServer", :type=>"Standard", :version=>"1.0"}
         | 
| 31 | 
            -
              ]
         | 
| 32 | 
            -
             | 
| 33 | 
            -
              def environment_tier(name)
         | 
| 34 | 
            -
                TIERS.find {|t| t[:name].downcase == name.downcase} || raise("No tier found with name #{name.inspect}")
         | 
| 35 | 
            -
              end
         | 
| 36 | 
            -
              module_function :environment_tier
         | 
| 37 30 | 
             
              #
         | 
| 38 31 | 
             
              # Query ouput value of the cloud formation stack
         | 
| 39 32 | 
             
              #
         | 
| @@ -83,7 +76,7 @@ module EbDeployer | |
| 83 76 | 
             
              #        :option_name => 'InstanceType',
         | 
| 84 77 | 
             
              #        :value => 'm1.small' }]
         | 
| 85 78 | 
             
              #
         | 
| 86 | 
            -
              #   When there are many,  | 
| 79 | 
            +
              #   When there are many, using an external yaml file to hold those
         | 
| 87 80 | 
             
              #   configuration is recommended. Such as:
         | 
| 88 81 | 
             
              #
         | 
| 89 82 | 
             
              #     YAML.load(File.read("my_settings_file.yml"))
         | 
| @@ -187,7 +180,7 @@ module EbDeployer | |
| 187 180 | 
             
                version_prefix = opts[:version_prefix].to_s.strip
         | 
| 188 181 | 
             
                version_label = "#{version_prefix}#{opts[:version_label].to_s.strip}"
         | 
| 189 182 | 
             
                cname = opts[:cname]
         | 
| 190 | 
            -
                 | 
| 183 | 
            +
                eb_settings = opts[:option_settings] || opts[:settings] || []
         | 
| 191 184 | 
             
                strategy_name = opts[:strategy] || :blue_green
         | 
| 192 185 | 
             
                cname_prefix = opts[:cname_prefix]
         | 
| 193 186 | 
             
                smoke_test = opts[:smoke_test] || Proc.new {}
         | 
| @@ -195,22 +188,24 @@ module EbDeployer | |
| 195 188 | 
             
                bucket = opts[:package_bucket] || app
         | 
| 196 189 | 
             
                skip_resource = opts[:skip_resource_stack_update]
         | 
| 197 190 | 
             
                keep_latest = opts[:keep_latest].to_i || 0
         | 
| 198 | 
            -
                app_tier =  | 
| 191 | 
            +
                app_tier = opts[:tier] || 'WebServer'
         | 
| 199 192 |  | 
| 200 193 | 
             
                resource_stacks = ResourceStacks.new(opts[:resources], cf, skip_resource)
         | 
| 201 194 | 
             
                application = Application.new(app, bs, s3, bucket)
         | 
| 202 | 
            -
                environment = Environment.new(application,
         | 
| 203 | 
            -
             | 
| 204 | 
            -
             | 
| 205 | 
            -
             | 
| 206 | 
            -
             | 
| 207 | 
            -
             | 
| 208 | 
            -
             | 
| 209 | 
            -
             | 
| 210 | 
            -
             | 
| 211 | 
            -
             | 
| 212 | 
            -
             | 
| 213 | 
            -
             | 
| 195 | 
            +
                environment = Environment.new(application, env_name, bs) do |env|
         | 
| 196 | 
            +
                  env.resource_stacks = resource_stacks
         | 
| 197 | 
            +
                  env.settings = eb_settings
         | 
| 198 | 
            +
                  env.creation_opts = {
         | 
| 199 | 
            +
                    :solution_stack => stack_name,
         | 
| 200 | 
            +
                    :cname_prefix => cname_prefix,
         | 
| 201 | 
            +
                    :smoke_test => smoke_test,
         | 
| 202 | 
            +
                    :phoenix_mode => phoenix_mode,
         | 
| 203 | 
            +
                    :tier => app_tier
         | 
| 204 | 
            +
                  }
         | 
| 205 | 
            +
             | 
| 206 | 
            +
                  env.components = opts[:components]
         | 
| 207 | 
            +
                  env.component_under_deploy = opts[:component]
         | 
| 208 | 
            +
                end
         | 
| 214 209 |  | 
| 215 210 | 
             
                application.create_version(version_label, opts[:package])
         | 
| 216 211 | 
             
                environment.deploy(version_label, strategy_name)
         | 
| @@ -241,8 +236,6 @@ module EbDeployer | |
| 241 236 | 
             
                parser.parse!
         | 
| 242 237 | 
             
                action = options.delete(:action)
         | 
| 243 238 |  | 
| 244 | 
            -
                raise "--all is only valid with --destroy" if (options[:all_envs] && action != :destroy)
         | 
| 245 | 
            -
             | 
| 246 239 | 
             
                if File.exists?(options[:config_file])
         | 
| 247 240 | 
             
                  puts "Found configuration at #{options[:config_file]}."
         | 
| 248 241 | 
             
                else
         | 
| @@ -278,16 +271,16 @@ module EbDeployer | |
| 278 271 | 
             
                    options[:config_file] = v
         | 
| 279 272 | 
             
                  end
         | 
| 280 273 |  | 
| 281 | 
            -
                  opts.on("-d", "--destroy", "Destroy specified environment") do |v|
         | 
| 274 | 
            +
                  opts.on("-d", "--destroy", "Destroy all Elasticbeanstalk environments under the application which have specified environment as name prefix") do |v|
         | 
| 282 275 | 
             
                    options[:action] = :destroy
         | 
| 283 276 | 
             
                  end
         | 
| 284 277 |  | 
| 285 | 
            -
                  opts.on("-- | 
| 286 | 
            -
                    options[: | 
| 278 | 
            +
                  opts.on("--skip-resource-stack-update", "Skip cloud-formation stack update. (only for extreme situation like hitting a cloudformation bug)") do |v|
         | 
| 279 | 
            +
                    options[:skip_resource_stack_update] = true
         | 
| 287 280 | 
             
                  end
         | 
| 288 281 |  | 
| 289 | 
            -
                  opts.on("-- | 
| 290 | 
            -
                    options[: | 
| 282 | 
            +
                  opts.on("--component [COMPONENT]", "Specify which component to deploy") do |v|
         | 
| 283 | 
            +
                    options[:component] = v
         | 
| 291 284 | 
             
                  end
         | 
| 292 285 |  | 
| 293 286 | 
             
                  opts.on("-v", "--version", "Print current version") do |v|
         | 
| @@ -34,24 +34,21 @@ module EbDeployer | |
| 34 34 | 
             
                  end
         | 
| 35 35 | 
             
                end
         | 
| 36 36 |  | 
| 37 | 
            -
                def delete( | 
| 37 | 
            +
                def delete(env_name_prefix)
         | 
| 38 38 | 
             
                  if @eb_driver.application_exists?(@name)
         | 
| 39 | 
            -
                    available_envs = @eb_driver.environment_names_for_application(@name)
         | 
| 39 | 
            +
                    available_envs = @eb_driver.environment_names_for_application(@name).select do |name|
         | 
| 40 | 
            +
                      name =~ /^#{env_name_prefix}-/
         | 
| 41 | 
            +
                    end
         | 
| 40 42 |  | 
| 41 | 
            -
                     | 
| 42 | 
            -
                      log("Environment #{ | 
| 43 | 
            +
                    if available_envs.empty?
         | 
| 44 | 
            +
                      log("Environment #{env_name_prefix.inspect} does not exist in application #{@name.inspect}. Skipping delete.")
         | 
| 43 45 | 
             
                      return
         | 
| 44 46 | 
             
                    end
         | 
| 45 47 |  | 
| 46 | 
            -
                    available_envs. | 
| 48 | 
            +
                    available_envs.each do |env|
         | 
| 47 49 | 
             
                      log("Terminating environment #{env}")
         | 
| 48 50 | 
             
                      @eb_driver.delete_environment(@name, env)
         | 
| 49 51 | 
             
                    end
         | 
| 50 | 
            -
             | 
| 51 | 
            -
                    if env_name.nil?
         | 
| 52 | 
            -
                      log("Deleting application")
         | 
| 53 | 
            -
                      @eb_driver.delete_application(@name)
         | 
| 54 | 
            -
                    end
         | 
| 55 52 | 
             
                  end
         | 
| 56 53 | 
             
                end
         | 
| 57 54 |  | 
| @@ -25,7 +25,7 @@ module EbDeployer | |
| 25 25 | 
             
                      :environment_id => env_id,
         | 
| 26 26 | 
             
                      :version_label => version,
         | 
| 27 27 | 
             
                      :option_settings => settings,
         | 
| 28 | 
            -
                      :tier => tier
         | 
| 28 | 
            +
                      :tier => environment_tier(tier)
         | 
| 29 29 | 
             
                    }
         | 
| 30 30 |  | 
| 31 31 | 
             
                    @client.update_environment(request)
         | 
| @@ -46,7 +46,7 @@ module EbDeployer | |
| 46 46 | 
             
                      :solution_stack_name => stack_name,
         | 
| 47 47 | 
             
                      :version_label => version,
         | 
| 48 48 | 
             
                      :option_settings => settings,
         | 
| 49 | 
            -
                      :tier => tier,
         | 
| 49 | 
            +
                      :tier => environment_tier(tier),
         | 
| 50 50 | 
             
                      :cname_prefix => cname_prefix
         | 
| 51 51 | 
             
                    }
         | 
| 52 52 |  | 
| @@ -112,6 +112,15 @@ module EbDeployer | |
| 112 112 |  | 
| 113 113 | 
             
                  private
         | 
| 114 114 |  | 
| 115 | 
            +
                  TIERS = [
         | 
| 116 | 
            +
                           {:name=>"Worker", :type=>"SQS/HTTP", :version=>"1.0"},
         | 
| 117 | 
            +
                           {:name=>"WebServer", :type=>"Standard", :version=>"1.0"}
         | 
| 118 | 
            +
                          ]
         | 
| 119 | 
            +
             | 
| 120 | 
            +
                  def environment_tier(name)
         | 
| 121 | 
            +
                    TIERS.find {|t| t[:name].downcase == name.downcase} || raise("No tier found with name #{name.inspect}")
         | 
| 122 | 
            +
                  end
         | 
| 123 | 
            +
             | 
| 115 124 | 
             
                  def convert_env_name_to_id(app_name, env_names)
         | 
| 116 125 | 
             
                    envs = alive_envs(app_name, env_names)
         | 
| 117 126 | 
             
                    envs.map { |env| env[:environment_id] }
         | 
| @@ -0,0 +1,40 @@ | |
| 1 | 
            +
            module EbDeployer
         | 
| 2 | 
            +
              class Component
         | 
| 3 | 
            +
                attr_reader :name
         | 
| 4 | 
            +
             | 
| 5 | 
            +
                def initialize(name, env, creation_opts, eb_settings, eb_driver)
         | 
| 6 | 
            +
                  @name = name
         | 
| 7 | 
            +
                  @env = env
         | 
| 8 | 
            +
                  @eb_driver = eb_driver
         | 
| 9 | 
            +
                  @creation_opts = creation_opts
         | 
| 10 | 
            +
                  @eb_settings = eb_settings
         | 
| 11 | 
            +
                end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                def cname_prefix
         | 
| 14 | 
            +
                  @creation_opts[:cname_prefix] || default_cname_prefix
         | 
| 15 | 
            +
                end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                def deploy(version_label, strategy_name, eb_settings)
         | 
| 18 | 
            +
                  strategy = create_strategy(strategy_name)
         | 
| 19 | 
            +
                  strategy.deploy(version_label, eb_settings + @eb_settings)
         | 
| 20 | 
            +
                end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                def new_eb_env(suffix=nil, cname_prefix_overriding=nil)
         | 
| 23 | 
            +
                  EbEnvironment.new(@env.app_name,
         | 
| 24 | 
            +
                                    [@env.name, @name, suffix].compact.join('-'),
         | 
| 25 | 
            +
                                    @eb_driver,
         | 
| 26 | 
            +
                                    @creation_opts.merge(:cname_prefix => cname_prefix_overriding || cname_prefix))
         | 
| 27 | 
            +
                end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                private
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                def default_cname_prefix
         | 
| 32 | 
            +
                  [@env.app_name, @env.name, @name].join('-')
         | 
| 33 | 
            +
                end
         | 
| 34 | 
            +
             | 
| 35 | 
            +
                def create_strategy(strategy_name)
         | 
| 36 | 
            +
                  DeploymentStrategy.create(self, strategy_name)
         | 
| 37 | 
            +
                end
         | 
| 38 | 
            +
             | 
| 39 | 
            +
              end
         | 
| 40 | 
            +
            end
         | 
| @@ -24,24 +24,21 @@ module EbDeployer | |
| 24 24 | 
             
                  config_file = options.delete(:config_file)
         | 
| 25 25 | 
             
                  config_settings = load_config_settings(config_file, package_digest)
         | 
| 26 26 |  | 
| 27 | 
            -
                   | 
| 28 | 
            -
                  common_settings[:version_label] ||= package_digest
         | 
| 27 | 
            +
                  app_name = config_settings[:application]
         | 
| 29 28 |  | 
| 30 | 
            -
                   | 
| 31 | 
            -
                   | 
| 32 | 
            -
                  unless ret.delete(:all_envs)
         | 
| 33 | 
            -
                    env = ret[:environment]
         | 
| 34 | 
            -
                    raise "Environment #{env} is not defined in #{config_file}" unless envs.has_key?(env)
         | 
| 35 | 
            -
                    env_settings = symbolize_keys(envs[env] || {})
         | 
| 36 | 
            -
                    env_option_settings = env_settings.delete(:option_settings) || []
         | 
| 29 | 
            +
                  common_settings = symbolize_keys(config_settings[:common])
         | 
| 30 | 
            +
                  common_settings[:version_label] ||= package_digest
         | 
| 37 31 |  | 
| 38 | 
            -
             | 
| 32 | 
            +
                  envs = config_settings[:environments]
         | 
| 33 | 
            +
                  env = options[:environment]
         | 
| 34 | 
            +
                  raise "Environment #{env} is not defined in #{config_file}" unless envs.has_key?(env)
         | 
| 35 | 
            +
                  env_settings = symbolize_keys(envs[env] || {})
         | 
| 36 | 
            +
                  env_option_settings = env_settings.delete(:option_settings) || []
         | 
| 39 37 |  | 
| 40 | 
            -
             | 
| 41 | 
            -
             | 
| 42 | 
            -
                   | 
| 43 | 
            -
             | 
| 44 | 
            -
                  end
         | 
| 38 | 
            +
                  ret = options.merge(common_settings).merge(env_settings)
         | 
| 39 | 
            +
                  ret[:application] = app_name
         | 
| 40 | 
            +
                  ret[:option_settings] ||= []
         | 
| 41 | 
            +
                  ret[:option_settings] += env_option_settings
         | 
| 45 42 | 
             
                  ret
         | 
| 46 43 | 
             
                end
         | 
| 47 44 |  | 
| @@ -0,0 +1,37 @@ | |
| 1 | 
            +
            module EbDeployer
         | 
| 2 | 
            +
              class DefaultComponent
         | 
| 3 | 
            +
                def initialize(env, creation_opts, eb_driver)
         | 
| 4 | 
            +
                  @env = env
         | 
| 5 | 
            +
                  @eb_driver = eb_driver
         | 
| 6 | 
            +
                  @creation_opts = creation_opts
         | 
| 7 | 
            +
                end
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                def cname_prefix
         | 
| 10 | 
            +
                  @creation_opts[:cname_prefix] || default_cname_prefix
         | 
| 11 | 
            +
                end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
             | 
| 14 | 
            +
                def deploy(version_label, strategy_name, eb_settings)
         | 
| 15 | 
            +
                  strategy = create_strategy(strategy_name)
         | 
| 16 | 
            +
                  strategy.deploy(version_label, eb_settings)
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                def new_eb_env(suffix=nil, cname_prefix_overriding=nil)
         | 
| 20 | 
            +
                  EbEnvironment.new(@env.app_name,
         | 
| 21 | 
            +
                                    [@env.name, suffix].compact.join('-'),
         | 
| 22 | 
            +
                                    @eb_driver,
         | 
| 23 | 
            +
                                    @creation_opts.merge(:cname_prefix => cname_prefix_overriding || cname_prefix))
         | 
| 24 | 
            +
                end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                private
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                def default_cname_prefix
         | 
| 29 | 
            +
                  [@env.app_name, @env.name].join('-')
         | 
| 30 | 
            +
                end
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                def create_strategy(strategy_name)
         | 
| 33 | 
            +
                  DeploymentStrategy.create(self, strategy_name)
         | 
| 34 | 
            +
                end
         | 
| 35 | 
            +
             | 
| 36 | 
            +
              end
         | 
| 37 | 
            +
            end
         | 
| @@ -38,7 +38,7 @@ module EbDeployer | |
| 38 38 |  | 
| 39 39 | 
             
                def terminate
         | 
| 40 40 | 
             
                  if @bs.environment_exists?(@app, @name)
         | 
| 41 | 
            -
                    with_polling_events( | 
| 41 | 
            +
                    with_polling_events(/terminateEnvironment completed successfully/i) do
         | 
| 42 42 | 
             
                      @bs.delete_environment(@app, @name)
         | 
| 43 43 | 
             
                    end
         | 
| 44 44 | 
             
                  end
         | 
| @@ -48,11 +48,11 @@ module EbDeployer | |
| 48 48 |  | 
| 49 49 | 
             
                def create_or_update_env(version_label, settings)
         | 
| 50 50 | 
             
                  if @bs.environment_exists?(@app, @name)
         | 
| 51 | 
            -
                    with_polling_events( | 
| 51 | 
            +
                    with_polling_events(/Environment update completed successfully/i) do
         | 
| 52 52 | 
             
                      @bs.update_environment(@app, @name, version_label, @creation_opts[:tier], settings)
         | 
| 53 53 | 
             
                    end
         | 
| 54 54 | 
             
                  else
         | 
| 55 | 
            -
                    with_polling_events( | 
| 55 | 
            +
                    with_polling_events(/Successfully launched environment/i) do
         | 
| 56 56 | 
             
                      @bs.create_environment(@app, @name, @creation_opts[:solution_stack], @creation_opts[:cname_prefix], version_label, @creation_opts[:tier], settings)
         | 
| 57 57 | 
             
                    end
         | 
| 58 58 | 
             
                  end
         | 
| @@ -63,10 +63,10 @@ module EbDeployer | |
| 63 63 | 
             
                  SmokeTest.new(@creation_opts[:smoke_test]).run(host_name, self)
         | 
| 64 64 | 
             
                end
         | 
| 65 65 |  | 
| 66 | 
            -
                def with_polling_events( | 
| 66 | 
            +
                def with_polling_events(terminate_pattern, &block)
         | 
| 67 67 | 
             
                  event_start_time = Time.now
         | 
| 68 68 | 
             
                  yield
         | 
| 69 | 
            -
                  event_poller.poll( | 
| 69 | 
            +
                  event_poller.poll(event_start_time) do |event|
         | 
| 70 70 | 
             
                    if event[:message] =~ /Failed to deploy application/
         | 
| 71 71 | 
             
                      raise event[:message]
         | 
| 72 72 | 
             
                    end
         | 
| @@ -95,7 +95,7 @@ module EbDeployer | |
| 95 95 | 
             
                end
         | 
| 96 96 |  | 
| 97 97 | 
             
                def event_poller
         | 
| 98 | 
            -
                  @event_poller || EventPoller.new(@app, @bs)
         | 
| 98 | 
            +
                  @event_poller || EventPoller.new(@app, @name, @bs)
         | 
| 99 99 | 
             
                end
         | 
| 100 100 |  | 
| 101 101 |  | 
| @@ -1,45 +1,62 @@ | |
| 1 1 | 
             
            module EbDeployer
         | 
| 2 2 | 
             
              class Environment
         | 
| 3 | 
            +
                attr_writer :resource_stacks, :settings, :creation_opts, :components, :component_under_deploy
         | 
| 4 | 
            +
                attr_reader :name
         | 
| 3 5 |  | 
| 4 | 
            -
                def initialize(app, name,  | 
| 6 | 
            +
                def initialize(app, name, eb_driver, &block)
         | 
| 5 7 | 
             
                  @app = app
         | 
| 6 8 | 
             
                  @name = name
         | 
| 7 | 
            -
                  @ | 
| 8 | 
            -
                  @ | 
| 9 | 
            -
                  @ | 
| 10 | 
            -
                   | 
| 9 | 
            +
                  @eb_driver = eb_driver
         | 
| 10 | 
            +
                  @creation_opts = {}
         | 
| 11 | 
            +
                  @settings = []
         | 
| 12 | 
            +
                  yield(self) if block_given?
         | 
| 13 | 
            +
                  unless @components
         | 
| 14 | 
            +
                    @components = [DefaultComponent.new(self, @creation_opts, @eb_driver)]
         | 
| 15 | 
            +
                  end
         | 
| 11 16 | 
             
                end
         | 
| 12 17 |  | 
| 13 | 
            -
                def  | 
| 14 | 
            -
                  @ | 
| 18 | 
            +
                def app_name
         | 
| 19 | 
            +
                  @app.name
         | 
| 15 20 | 
             
                end
         | 
| 16 21 |  | 
| 17 22 | 
             
                def deploy(version_label, strategy_name)
         | 
| 18 | 
            -
                   | 
| 19 | 
            -
                   | 
| 20 | 
            -
             | 
| 23 | 
            +
                  resource_settings = @resource_stacks.provision(resource_stack_name)
         | 
| 24 | 
            +
                  components_to_deploy.each do |component|
         | 
| 25 | 
            +
                    component.deploy(version_label, strategy_name, @settings + resource_settings)
         | 
| 26 | 
            +
                  end
         | 
| 21 27 | 
             
                end
         | 
| 22 28 |  | 
| 23 | 
            -
                def  | 
| 24 | 
            -
                   | 
| 25 | 
            -
             | 
| 26 | 
            -
             | 
| 27 | 
            -
             | 
| 29 | 
            +
                def components=(components_attrs)
         | 
| 30 | 
            +
                  return unless components_attrs
         | 
| 31 | 
            +
                  @components = components_attrs.map do |attrs|
         | 
| 32 | 
            +
                    attrs = symbolize_keys(attrs)
         | 
| 33 | 
            +
                    name = attrs.delete(:name)
         | 
| 34 | 
            +
                    eb_settings = attrs.delete(:option_settings) || []
         | 
| 35 | 
            +
                    Component.new(name, self, @creation_opts.merge(attrs), eb_settings, @eb_driver)
         | 
| 36 | 
            +
                  end
         | 
| 28 37 | 
             
                end
         | 
| 29 38 |  | 
| 30 39 | 
             
                private
         | 
| 31 | 
            -
             | 
| 32 | 
            -
             | 
| 33 | 
            -
             | 
| 40 | 
            +
                def components_to_deploy
         | 
| 41 | 
            +
                  if @component_under_deploy
         | 
| 42 | 
            +
                    component = component_named(@component_under_deploy)
         | 
| 43 | 
            +
                    raise "'#{@component_under_deploy}' is not in the configuration. Available components are #{@components.map(&:name) }" unless component
         | 
| 44 | 
            +
                    [component]
         | 
| 45 | 
            +
                  else
         | 
| 46 | 
            +
                    @components
         | 
| 47 | 
            +
                  end
         | 
| 34 48 | 
             
                end
         | 
| 35 49 |  | 
| 50 | 
            +
                def component_named(name)
         | 
| 51 | 
            +
                  @components.detect { |c| c.name == name }
         | 
| 52 | 
            +
                end
         | 
| 36 53 |  | 
| 37 | 
            -
                def  | 
| 38 | 
            -
                   | 
| 54 | 
            +
                def symbolize_keys(hash)
         | 
| 55 | 
            +
                  hash.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
         | 
| 39 56 | 
             
                end
         | 
| 40 57 |  | 
| 41 58 | 
             
                def resource_stack_name
         | 
| 42 | 
            -
                  "#{ | 
| 59 | 
            +
                  "#{app_name}-#{@name}"
         | 
| 43 60 | 
             
                end
         | 
| 44 61 | 
             
              end
         | 
| 45 62 | 
             
            end
         | 
| @@ -1,13 +1,13 @@ | |
| 1 1 | 
             
            module EbDeployer
         | 
| 2 2 | 
             
              class EventPoller
         | 
| 3 | 
            -
                def initialize(app, beanstalk)
         | 
| 4 | 
            -
                  @app, @beanstalk = app, beanstalk
         | 
| 3 | 
            +
                def initialize(app, env, beanstalk)
         | 
| 4 | 
            +
                  @app, @env, @beanstalk = app, env, beanstalk
         | 
| 5 5 | 
             
                end
         | 
| 6 6 |  | 
| 7 | 
            -
                def poll( | 
| 7 | 
            +
                def poll(start_time = Time.now, &block)
         | 
| 8 8 | 
             
                  handled = Set.new
         | 
| 9 9 | 
             
                  loop do
         | 
| 10 | 
            -
                    fetch_events( | 
| 10 | 
            +
                    fetch_events(start_time) do |events|
         | 
| 11 11 | 
             
                      new_events = events.reject { |e| handled.include?(digest(e)) }
         | 
| 12 12 | 
             
                      handle(new_events, &block)
         | 
| 13 13 | 
             
                      handled += new_events.map { |e| digest(e) }
         | 
| @@ -27,14 +27,14 @@ module EbDeployer | |
| 27 27 | 
             
                  events.reverse.each(&block)
         | 
| 28 28 | 
             
                end
         | 
| 29 29 |  | 
| 30 | 
            -
                def fetch_events( | 
| 31 | 
            -
                  events, next_token = @beanstalk.fetch_events(@app,  | 
| 30 | 
            +
                def fetch_events(start_time, &block)
         | 
| 31 | 
            +
                  events, next_token = @beanstalk.fetch_events(@app, @env, :start_time => start_time.iso8601)
         | 
| 32 32 | 
             
                  yield(events)
         | 
| 33 | 
            -
                  fetch_next( | 
| 33 | 
            +
                  fetch_next(next_token, &block) if next_token
         | 
| 34 34 | 
             
                end
         | 
| 35 35 |  | 
| 36 | 
            -
                def fetch_next( | 
| 37 | 
            -
                  events, next_token = @beanstalk.fetch_events(@app,  | 
| 36 | 
            +
                def fetch_next(next_token, &block)
         | 
| 37 | 
            +
                  events, next_token = @beanstalk.fetch_events(@app, @env, :next_token => next_token)
         | 
| 38 38 | 
             
                  yield(events)
         | 
| 39 39 | 
             
                  fetch_next(next_token, &block) if next_token
         | 
| 40 40 | 
             
                end
         | 
    
        data/lib/eb_deployer/version.rb
    CHANGED
    
    
| @@ -102,5 +102,20 @@ class BlueGreenDeployTest < DeployTest | |
| 102 102 | 
             
                assert_equal 'simple-production',  @eb.environment_cname_prefix('simple', inactive_env)
         | 
| 103 103 | 
             
              end
         | 
| 104 104 |  | 
| 105 | 
            +
              def test_destroy_should_clean_up_env
         | 
| 106 | 
            +
                2.times do
         | 
| 107 | 
            +
                  deploy(:application => 'simple',
         | 
| 108 | 
            +
                         :environment => "production",
         | 
| 109 | 
            +
                         :strategy => 'blue-green',
         | 
| 110 | 
            +
                         :version_label => 44,
         | 
| 111 | 
            +
                         :phoenix_mode => true)
         | 
| 112 | 
            +
                end
         | 
| 113 | 
            +
             | 
| 114 | 
            +
                destroy(:application => 'simple', :environment => 'production')
         | 
| 115 | 
            +
                assert !@eb.environment_exists?('simple', t('production-a', 'simple'))
         | 
| 116 | 
            +
                assert !@eb.environment_exists?('simple', t('production-b', 'simple'))
         | 
| 117 | 
            +
              end
         | 
| 118 | 
            +
             | 
| 119 | 
            +
             | 
| 105 120 |  | 
| 106 121 | 
             
            end
         | 
| @@ -18,13 +18,6 @@ class InplaceUpdateDeployTest < DeployTest | |
| 18 18 |  | 
| 19 19 | 
             
              end
         | 
| 20 20 |  | 
| 21 | 
            -
              def test_destroy_should_clean_up_eb_application_and_env
         | 
| 22 | 
            -
                deploy(:application => 'simple', :environment => "production")
         | 
| 23 | 
            -
                destroy(:application => 'simple')
         | 
| 24 | 
            -
                assert !@eb.application_exists?('simple')
         | 
| 25 | 
            -
                assert !@eb.environment_exists?('simple', t('production', 'simple'))
         | 
| 26 | 
            -
              end
         | 
| 27 | 
            -
             | 
| 28 21 | 
             
              def test_first_deployment_create_environment
         | 
| 29 22 | 
             
                assert !@eb.environment_exists?('simple', t('production', 'simple'))
         | 
| 30 23 | 
             
                deploy(:application => 'simple', :environment => "production")
         | 
| @@ -79,4 +72,11 @@ class InplaceUpdateDeployTest < DeployTest | |
| 79 72 | 
             
                assert @eb.environments_been_deleted('simple').include?(t('production', 'simple'))
         | 
| 80 73 | 
             
                assert @eb.environment_exists?('simple', t('production', 'simple'))
         | 
| 81 74 | 
             
              end
         | 
| 75 | 
            +
             | 
| 76 | 
            +
              def test_destroy_should_clean_up_env
         | 
| 77 | 
            +
                deploy(:application => 'simple', :environment => "production")
         | 
| 78 | 
            +
                destroy(:application => 'simple', :environment => 'production')
         | 
| 79 | 
            +
                assert !@eb.environment_exists?('simple', t('production', 'simple'))
         | 
| 80 | 
            +
              end
         | 
| 81 | 
            +
             | 
| 82 82 | 
             
            end
         | 
| @@ -0,0 +1,93 @@ | |
| 1 | 
            +
            require 'deploy_test'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            class MultiComponentsDeployTest < DeployTest
         | 
| 4 | 
            +
              def test_deploy_with_components
         | 
| 5 | 
            +
                do_deploy
         | 
| 6 | 
            +
                assert @eb.environment_exists?('simple', t('prod-web', 'simple'))
         | 
| 7 | 
            +
                assert @eb.environment_exists?('simple', t('prod-bg', 'simple'))
         | 
| 8 | 
            +
                assert @eb.environment_exists?('simple', t('prod-api', 'simple'))
         | 
| 9 | 
            +
                assert !@eb.environment_exists?('simple', t('prod', 'simple'))
         | 
| 10 | 
            +
              end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
              def test_deploy_with_components_with_blue_green
         | 
| 13 | 
            +
                do_bg_deploy
         | 
| 14 | 
            +
                assert @eb.environment_exists?('simple', t('prod-web-a', 'simple'))
         | 
| 15 | 
            +
                assert @eb.environment_exists?('simple', t('prod-bg-a', 'simple'))
         | 
| 16 | 
            +
                assert @eb.environment_exists?('simple', t('prod-api-a', 'simple'))
         | 
| 17 | 
            +
                do_bg_deploy
         | 
| 18 | 
            +
                assert @eb.environment_exists?('simple', t('prod-web-b', 'simple'))
         | 
| 19 | 
            +
                assert @eb.environment_exists?('simple', t('prod-bg-b', 'simple'))
         | 
| 20 | 
            +
                assert @eb.environment_exists?('simple', t('prod-api-b', 'simple'))
         | 
| 21 | 
            +
              end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
              def test_cname_include_component_name
         | 
| 24 | 
            +
                do_deploy
         | 
| 25 | 
            +
                assert_equal 'simple-prod-web', @eb.environment_cname_prefix('simple', t('prod-web', 'simple'))
         | 
| 26 | 
            +
                assert_equal 'simple-prod-api', @eb.environment_cname_prefix('simple', t('prod-api', 'simple'))
         | 
| 27 | 
            +
              end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
              def test_cname_include_component_name_in_blue_green
         | 
| 30 | 
            +
                do_bg_deploy
         | 
| 31 | 
            +
                assert_equal 'simple-prod-web', @eb.environment_cname_prefix('simple', t('prod-web-a', 'simple'))
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                do_bg_deploy
         | 
| 34 | 
            +
                assert_equal 'simple-prod-web', @eb.environment_cname_prefix('simple', t('prod-web-b', 'simple'))
         | 
| 35 | 
            +
                assert_equal 'simple-prod-web-inactive', @eb.environment_cname_prefix('simple', t('prod-web-a', 'simple'))
         | 
| 36 | 
            +
              end
         | 
| 37 | 
            +
             | 
| 38 | 
            +
              def test_components_inheritate_creation_options_from_environment
         | 
| 39 | 
            +
                do_deploy
         | 
| 40 | 
            +
                assert_equal 'WebServer', @eb.environment_tier('simple', t('prod-web', 'simple'))
         | 
| 41 | 
            +
              end
         | 
| 42 | 
            +
             | 
| 43 | 
            +
              def test_components_can_override_creation_opts
         | 
| 44 | 
            +
                do_deploy(:tier => 'WebServer',
         | 
| 45 | 
            +
                          :components => [{'name' => 'web'}, {'name' => 'bg', 'tier' => "Worker"}])
         | 
| 46 | 
            +
                assert_equal 'WebServer', @eb.environment_tier('simple', t('prod-web', 'simple'))
         | 
| 47 | 
            +
                assert_equal 'Worker', @eb.environment_tier('simple', t('prod-bg', 'simple'))
         | 
| 48 | 
            +
              end
         | 
| 49 | 
            +
             | 
| 50 | 
            +
              def test_components_specific_eb_settings_will_override_env_eb_settings
         | 
| 51 | 
            +
                minsize_3 = {:namespace => 'aws:autoscaling:launchconfiguration',
         | 
| 52 | 
            +
                  :option_name => 'MinSize',
         | 
| 53 | 
            +
                  :value => '3' }
         | 
| 54 | 
            +
                minsize_2 = {:namespace => 'aws:autoscaling:launchconfiguration',
         | 
| 55 | 
            +
                  :option_name => 'MinSize',
         | 
| 56 | 
            +
                  :value => '2' }
         | 
| 57 | 
            +
             | 
| 58 | 
            +
                do_deploy(:option_settings => [minsize_3],
         | 
| 59 | 
            +
                          :components => [{'name' => 'web'},
         | 
| 60 | 
            +
                                          {'name' => 'api',
         | 
| 61 | 
            +
                                            'option_settings' => [minsize_2]}])
         | 
| 62 | 
            +
                assert_equal [minsize_3], @eb.environment_settings('simple', t('prod-web', 'simple'))
         | 
| 63 | 
            +
                assert_equal [minsize_3, minsize_2], @eb.environment_settings('simple', t('prod-api', 'simple'))
         | 
| 64 | 
            +
              end
         | 
| 65 | 
            +
             | 
| 66 | 
            +
              def test_can_deploy_single_component
         | 
| 67 | 
            +
                do_deploy(:component => "bg")
         | 
| 68 | 
            +
                assert !@eb.environment_exists?('simple', t('prod-web', 'simple'))
         | 
| 69 | 
            +
                assert !@eb.environment_exists?('simple', t('prod-api', 'simple'))
         | 
| 70 | 
            +
                assert @eb.environment_exists?('simple', t('prod-bg', 'simple'))
         | 
| 71 | 
            +
              end
         | 
| 72 | 
            +
             | 
| 73 | 
            +
              def test_should_raise_exception_when_try_to_deploy_a_none_exists_component
         | 
| 74 | 
            +
                assert_raises(RuntimeError) do
         | 
| 75 | 
            +
                  do_deploy(:component => "foo")
         | 
| 76 | 
            +
                end
         | 
| 77 | 
            +
              end
         | 
| 78 | 
            +
             | 
| 79 | 
            +
              private
         | 
| 80 | 
            +
              def do_deploy(options={})
         | 
| 81 | 
            +
                deploy({:application => 'simple',
         | 
| 82 | 
            +
                         :environment => 'prod',
         | 
| 83 | 
            +
                         :components => [{ 'name' => 'web' },
         | 
| 84 | 
            +
                                         { 'name' => 'bg' },
         | 
| 85 | 
            +
                                         { 'name' => 'api' }]
         | 
| 86 | 
            +
                       }.merge(options))
         | 
| 87 | 
            +
              end
         | 
| 88 | 
            +
             | 
| 89 | 
            +
              def do_bg_deploy
         | 
| 90 | 
            +
                do_deploy(:strategy => 'blue-green')
         | 
| 91 | 
            +
              end
         | 
| 92 | 
            +
             | 
| 93 | 
            +
            end
         | 
| @@ -3,17 +3,11 @@ require 'deploy_test' | |
| 3 3 | 
             
            class TierSettingDeployTest < DeployTest
         | 
| 4 4 | 
             
              def test_sets_default_tier_as_webserver
         | 
| 5 5 | 
             
                deploy(:application => 'simple', :environment => "production")
         | 
| 6 | 
            -
                assert_equal  | 
| 6 | 
            +
                assert_equal 'WebServer', @eb.environment_tier('simple', t('production', 'simple'))
         | 
| 7 7 | 
             
              end
         | 
| 8 8 |  | 
| 9 9 | 
             
              def test_can_change_tier
         | 
| 10 10 | 
             
                deploy(:application => 'simple', :environment => "production", :tier => 'Worker')
         | 
| 11 | 
            -
                assert_equal  | 
| 12 | 
            -
              end
         | 
| 13 | 
            -
             | 
| 14 | 
            -
              def test_should_raise_error_when_tier_setting_is_not_recognized
         | 
| 15 | 
            -
                assert_raises(RuntimeError) do
         | 
| 16 | 
            -
                  deploy(:application => 'simple', :environment => "production", :tier => 'Gum')
         | 
| 17 | 
            -
                end
         | 
| 11 | 
            +
                assert_equal 'Worker', @eb.environment_tier('simple', t('production', 'simple'))
         | 
| 18 12 | 
             
              end
         | 
| 19 13 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: eb_deployer
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.4. | 
| 4 | 
            +
              version: 0.4.1
         | 
| 5 5 | 
             
              prerelease: 
         | 
| 6 6 | 
             
            platform: ruby
         | 
| 7 7 | 
             
            authors:
         | 
| @@ -10,7 +10,7 @@ authors: | |
| 10 10 | 
             
            autorequire: 
         | 
| 11 11 | 
             
            bindir: bin
         | 
| 12 12 | 
             
            cert_chain: []
         | 
| 13 | 
            -
            date: 2014-03- | 
| 13 | 
            +
            date: 2014-03-31 00:00:00.000000000 Z
         | 
| 14 14 | 
             
            dependencies:
         | 
| 15 15 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 16 16 | 
             
              name: aws-sdk
         | 
| @@ -55,7 +55,9 @@ files: | |
| 55 55 | 
             
            - lib/eb_deployer/aws_driver/cloud_formation_driver.rb
         | 
| 56 56 | 
             
            - lib/eb_deployer/aws_driver/s3_driver.rb
         | 
| 57 57 | 
             
            - lib/eb_deployer/cloud_formation_provisioner.rb
         | 
| 58 | 
            +
            - lib/eb_deployer/component.rb
         | 
| 58 59 | 
             
            - lib/eb_deployer/config_loader.rb
         | 
| 60 | 
            +
            - lib/eb_deployer/default_component.rb
         | 
| 59 61 | 
             
            - lib/eb_deployer/default_config.rb
         | 
| 60 62 | 
             
            - lib/eb_deployer/default_config.yml
         | 
| 61 63 | 
             
            - lib/eb_deployer/deployment_strategy.rb
         | 
| @@ -76,6 +78,7 @@ files: | |
| 76 78 | 
             
            - test/deploy_test.rb
         | 
| 77 79 | 
             
            - test/eb_environment_test.rb
         | 
| 78 80 | 
             
            - test/inplace_update_deploy_test.rb
         | 
| 81 | 
            +
            - test/multi_components_deploy_test.rb
         | 
| 79 82 | 
             
            - test/resources_deploy_test.rb
         | 
| 80 83 | 
             
            - test/smoke_test_test.rb
         | 
| 81 84 | 
             
            - test/test_helper.rb
         | 
| @@ -96,7 +99,7 @@ required_ruby_version: !ruby/object:Gem::Requirement | |
| 96 99 | 
             
                  version: '0'
         | 
| 97 100 | 
             
                  segments:
         | 
| 98 101 | 
             
                  - 0
         | 
| 99 | 
            -
                  hash:  | 
| 102 | 
            +
                  hash: -3040208226803688120
         | 
| 100 103 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 101 104 | 
             
              none: false
         | 
| 102 105 | 
             
              requirements:
         | 
| @@ -105,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 105 108 | 
             
                  version: '0'
         | 
| 106 109 | 
             
                  segments:
         | 
| 107 110 | 
             
                  - 0
         | 
| 108 | 
            -
                  hash:  | 
| 111 | 
            +
                  hash: -3040208226803688120
         | 
| 109 112 | 
             
            requirements: []
         | 
| 110 113 | 
             
            rubyforge_project: 
         | 
| 111 114 | 
             
            rubygems_version: 1.8.29
         | 
| @@ -122,6 +125,7 @@ test_files: | |
| 122 125 | 
             
            - test/deploy_test.rb
         | 
| 123 126 | 
             
            - test/eb_environment_test.rb
         | 
| 124 127 | 
             
            - test/inplace_update_deploy_test.rb
         | 
| 128 | 
            +
            - test/multi_components_deploy_test.rb
         | 
| 125 129 | 
             
            - test/resources_deploy_test.rb
         | 
| 126 130 | 
             
            - test/smoke_test_test.rb
         | 
| 127 131 | 
             
            - test/test_helper.rb
         |