Sha256: 472d5d7d409d1eb11d2bf36e4e0409f958e6cde62c50b10ad0e72b7f31bd7129

Contents?: true

Size: 1.41 KB

Versions: 3

Compression:

Stored size: 1.41 KB

Contents

module EbDeployer
  module DeploymentStrategy
    class BlueGreen
      def initialize(component)
        @component = component
      end

      def test_compatibility(env_create_options)
        tier = env_create_options[:tier]
        if tier && tier.downcase == 'worker'
          raise "Blue green deployment is not supported for Worker tier"
        end
      end

      def deploy(version_label, env_settings, inactive_settings=[])
        if !ebenvs.any?(&method(:active_ebenv?))
          ebenv('a', @component.cname_prefix).
            deploy(version_label, env_settings)
          return
        end

        active_ebenv = ebenvs.detect(&method(:active_ebenv?))
        inactive_ebenv = ebenvs.reject(&method(:active_ebenv?)).first

        inactive_ebenv.deploy(version_label, env_settings)
        active_ebenv.swap_cname_with(inactive_ebenv)
        unless inactive_settings.empty?
          active_ebenv.log("applying inactive settings...")
          active_ebenv.apply_settings(inactive_settings)
        end
      end

      private
      def active_ebenv?(ebenv)
        ebenv.cname_prefix == @component.cname_prefix
      end

      def ebenvs
        [ebenv('a'), ebenv('b')]
      end

      def ebenv(suffix, cname_prefix=nil)
        @component.new_eb_env(suffix, cname_prefix || inactive_cname_prefix)
      end

      def inactive_cname_prefix
        "#{@component.cname_prefix}-inactive"
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
eb_deployer-0.6.1 lib/eb_deployer/deployment_strategy/blue_green.rb
eb_deployer-0.6.0 lib/eb_deployer/deployment_strategy/blue_green.rb
eb_deployer-0.6.0.beta6 lib/eb_deployer/deployment_strategy/blue_green.rb