Class: OpsworksInteractor

Inherits:
Object
  • Object
show all
Defined in:
lib/opsworks_interactor.rb

Constant Summary collapse

DeployLockError =
Class.new(StandardError)
OPSWORKS_REGION =

All opsworks endpoints are in the us-east-1 region, see: docs.aws.amazon.com/opsworks/latest/userguide/cli-examples.html

'us-east-1'

Instance Method Summary collapse

Constructor Details

#initialize(access_key_id, secret_access_key, redis: nil) ⇒ OpsworksInteractor

Returns a new instance of OpsworksInteractor.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/opsworks_interactor.rb', line 16

def initialize(access_key_id, secret_access_key, redis: nil)
  # All opsworks endpoints are always in the OPSWORKS_REGION
  @opsworks_client = Aws::OpsWorks::Client.new(
    access_key_id:     access_key_id,
    secret_access_key: secret_access_key,
    region: OPSWORKS_REGION
  )

  @elb_client = Aws::ElasticLoadBalancing::Client.new(
    access_key_id:     access_key_id,
    secret_access_key: secret_access_key,
    region: ENV['AWS_REGION'] || OPSWORKS_REGION
  )

  # Redis host and port may be supplied if you want to run your deploys with
  # mutual exclusive locking (recommended)
  # Example redis config: { host: 'foo', port: 42 }
  @redis = redis
end

Instance Method Details

#deploy(stack_id:, app_id:, instance_id:, deploy_timeout: 30.minutes) ⇒ Object

Deploys the given app_id on the given instance_id in the given stack_id

Blocks until AWS confirms that the deploy was successful

Returns a Aws::OpsWorks::Types::CreateDeploymentResult



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/opsworks_interactor.rb', line 50

def deploy(stack_id:, app_id:, instance_id:, deploy_timeout: 30.minutes)
  response = @opsworks_client.create_deployment(
    stack_id:     stack_id,
    app_id:       app_id,
    instance_ids: [instance_id],
    command: {
      name: 'deploy',
      args: {
        'migrate' => ['true'],
      }
    }
  )

  log("Deploy process running (id: #{response[:deployment_id]})...")

  wait_until_deploy_completion(response[:deployment_id], deploy_timeout)

  log("✓ deploy completed")

  response
end

#rolling_deploy(**kwargs) ⇒ Object

Runs only ONE rolling deploy at a time.

If another one is currently running, waits for it to finish before starting



39
40
41
42
43
# File 'lib/opsworks_interactor.rb', line 39

def rolling_deploy(**kwargs)
  with_deploy_lock do
    rolling_deploy_without_lock(**kwargs)
  end
end