opsworks_interactor 0.0.2 → 0.0.3
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.
- checksums.yaml +4 -4
 - data/lib/opsworks_interactor.rb +34 -15
 - metadata +1 -1
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: f97a42f30cb55c2e5f1937ad59db3d5b23d315e1
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: fedbbe8f5eb7dfea2e37634e9974344caa6ca651
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: eb8b867c041410e7a034f0980a5b1c708567f68facb11384af57f1634a512f861d25649dfe785f69aece6dca05e18f3f0d4c87d06e07bbbdd6681cf6703c65d1
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 2d9e4dcaf2f646acd9a3603e9bf8a3c939185e170dc0e57685596f20be49940607a1085eece458ef8059bc93c8c51ffadb8622ca20cd94d95efa4d6a123956b3
         
     | 
    
        data/lib/opsworks_interactor.rb
    CHANGED
    
    | 
         @@ -1,5 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'aws-sdk'
         
     | 
| 
       2 
2 
     | 
    
         
             
            class OpsworksInteractor
         
     | 
| 
      
 3 
     | 
    
         
            +
              Aws::Waiters::Errors::TimeoutError = Class.new(Aws::Waiters::Errors::WaiterFailed)
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
       3 
5 
     | 
    
         
             
              begin
         
     | 
| 
       4 
6 
     | 
    
         
             
                require 'redis-semaphore'
         
     | 
| 
       5 
7 
     | 
    
         
             
              rescue LoadError
         
     | 
| 
         @@ -46,7 +48,7 @@ class OpsworksInteractor 
     | 
|
| 
       46 
48 
     | 
    
         
             
              # Blocks until AWS confirms that the deploy was successful
         
     | 
| 
       47 
49 
     | 
    
         
             
              #
         
     | 
| 
       48 
50 
     | 
    
         
             
              # Returns a Aws::OpsWorks::Types::CreateDeploymentResult
         
     | 
| 
       49 
     | 
    
         
            -
              def deploy(stack_id:, app_id:, instance_id:)
         
     | 
| 
      
 51 
     | 
    
         
            +
              def deploy(stack_id:, app_id:, instance_id:, deploy_timeout: 30.minutes)
         
     | 
| 
       50 
52 
     | 
    
         
             
                response = @opsworks_client.create_deployment(
         
     | 
| 
       51 
53 
     | 
    
         
             
                  stack_id:     stack_id,
         
     | 
| 
       52 
54 
     | 
    
         
             
                  app_id:       app_id,
         
     | 
| 
         @@ -61,10 +63,8 @@ class OpsworksInteractor 
     | 
|
| 
       61 
63 
     | 
    
         | 
| 
       62 
64 
     | 
    
         
             
                log("Deploy process running (id: #{response[:deployment_id]})...")
         
     | 
| 
       63 
65 
     | 
    
         | 
| 
       64 
     | 
    
         
            -
                 
     | 
| 
       65 
     | 
    
         
            -
             
     | 
| 
       66 
     | 
    
         
            -
                  deployment_ids: [response[:deployment_id]]
         
     | 
| 
       67 
     | 
    
         
            -
                )
         
     | 
| 
      
 66 
     | 
    
         
            +
                wait_until_deploy_completion(response[:deployment_id], deploy_timeout)
         
     | 
| 
      
 67 
     | 
    
         
            +
              end
         
     | 
| 
       68 
68 
     | 
    
         | 
| 
       69 
69 
     | 
    
         
             
                log("✓ deploy completed")
         
     | 
| 
       70 
70 
     | 
    
         | 
| 
         @@ -73,6 +73,23 @@ class OpsworksInteractor 
     | 
|
| 
       73 
73 
     | 
    
         | 
| 
       74 
74 
     | 
    
         
             
              private
         
     | 
| 
       75 
75 
     | 
    
         | 
| 
      
 76 
     | 
    
         
            +
              # Polls Opsworks for timeout seconds until deployment_id has completed
         
     | 
| 
      
 77 
     | 
    
         
            +
              def wait_until_deploy_completion(deployment_id, timeout)
         
     | 
| 
      
 78 
     | 
    
         
            +
                started_at = Time.now
         
     | 
| 
      
 79 
     | 
    
         
            +
             
     | 
| 
      
 80 
     | 
    
         
            +
                @opsworks_client.wait_until(
         
     | 
| 
      
 81 
     | 
    
         
            +
                  :deployment_successful,
         
     | 
| 
      
 82 
     | 
    
         
            +
                  deployment_ids: [deployment_id]
         
     | 
| 
      
 83 
     | 
    
         
            +
                ) do |w|
         
     | 
| 
      
 84 
     | 
    
         
            +
                    # disable max attempts
         
     | 
| 
      
 85 
     | 
    
         
            +
                    w.max_attempts = nil
         
     | 
| 
      
 86 
     | 
    
         
            +
                    # poll for a time period, instead of a number of attempts
         
     | 
| 
      
 87 
     | 
    
         
            +
                    before_wait do |attempts, response|
         
     | 
| 
      
 88 
     | 
    
         
            +
                      raise Aws::Waiters::Errors::TimeoutError if (Time.now - started_at) > timeout
         
     | 
| 
      
 89 
     | 
    
         
            +
                    end
         
     | 
| 
      
 90 
     | 
    
         
            +
                  end
         
     | 
| 
      
 91 
     | 
    
         
            +
              end
         
     | 
| 
      
 92 
     | 
    
         
            +
             
     | 
| 
       76 
93 
     | 
    
         
             
              # Loop through all instances in layer
         
     | 
| 
       77 
94 
     | 
    
         
             
              # Deregister from ELB (elastic load balancer)
         
     | 
| 
       78 
95 
     | 
    
         
             
              # Wait connection draining timeout (default up to maximum of 300s)
         
     | 
| 
         @@ -86,19 +103,21 @@ class OpsworksInteractor 
     | 
|
| 
       86 
103 
     | 
    
         
             
                instances = @opsworks_client.describe_instances(layer_id: layer_id)[:instances]
         
     | 
| 
       87 
104 
     | 
    
         | 
| 
       88 
105 
     | 
    
         
             
                instances.each do |instance|
         
     | 
| 
       89 
     | 
    
         
            -
                   
     | 
| 
       90 
     | 
    
         
            -
             
     | 
| 
       91 
     | 
    
         
            -
                  load_balancers = detach_from_elbs(instance: instance)
         
     | 
| 
      
 106 
     | 
    
         
            +
                  begin
         
     | 
| 
      
 107 
     | 
    
         
            +
                    log("=== Starting deploy for #{instance.hostname} ===")
         
     | 
| 
       92 
108 
     | 
    
         | 
| 
       93 
     | 
    
         
            -
             
     | 
| 
       94 
     | 
    
         
            -
                    stack_id: stack_id,
         
     | 
| 
       95 
     | 
    
         
            -
                    app_id: app_id,
         
     | 
| 
       96 
     | 
    
         
            -
                    instance_id: instance.instance_id
         
     | 
| 
       97 
     | 
    
         
            -
                  )
         
     | 
| 
      
 109 
     | 
    
         
            +
                    load_balancers = detach_from_elbs(instance: instance)
         
     | 
| 
       98 
110 
     | 
    
         | 
| 
       99 
     | 
    
         
            -
             
     | 
| 
      
 111 
     | 
    
         
            +
                    deploy(
         
     | 
| 
      
 112 
     | 
    
         
            +
                      stack_id: stack_id,
         
     | 
| 
      
 113 
     | 
    
         
            +
                      app_id: app_id,
         
     | 
| 
      
 114 
     | 
    
         
            +
                      instance_id: instance.instance_id
         
     | 
| 
      
 115 
     | 
    
         
            +
                    )
         
     | 
| 
      
 116 
     | 
    
         
            +
                  ensure
         
     | 
| 
      
 117 
     | 
    
         
            +
                    attach_to_elbs(instance: instance, load_balancers: load_balancers) if load_blaancers
         
     | 
| 
       100 
118 
     | 
    
         | 
| 
       101 
     | 
    
         
            -
             
     | 
| 
      
 119 
     | 
    
         
            +
                    log("=== Done deploying on #{instance.hostname} ===\n\n")
         
     | 
| 
      
 120 
     | 
    
         
            +
                  end
         
     | 
| 
       102 
121 
     | 
    
         
             
                end
         
     | 
| 
       103 
122 
     | 
    
         | 
| 
       104 
123 
     | 
    
         
             
                log("SUCCESS: completed opsworks deploy for all instances on app #{app_id}")
         
     |