Class: Dpl::Providers::Opsworks

Inherits:
Dpl::Provider show all
Defined in:
lib/dpl/providers/opsworks.rb

Constant Summary

Constants inherited from Dpl::Provider

Dpl::Provider::FOLDS, Dpl::Provider::STAGES

Instance Attribute Summary

Attributes inherited from Dpl::Provider

#key_name, #repo_name

Instance Method Summary collapse

Methods inherited from Dpl::Provider

#before_finish, #before_init, #before_install, #before_prepare, #before_setup, #chmod, #cleanup, #cmd, #compact, #err, #error, #escape, examples, #expand, #file?, #finish?, #fold, #fold?, #info, #initialize, install_deps, install_deps?, #mkdir_p, move_files, #msg, #mv, #only, #open, #opt_for, #opt_key, #opts_for, #print, #quote, #read, #remove_dpl_dir, #rm_rf, #run, #run_cmd, #run_cmds, #run_stage, #run_stage?, #script, #setup_dpl_dir, #setup_git_config, #setup_git_http_user_agent, #setup_git_ssh, #setup_ssh_key, #shell, #sq, #ssh_keygen, #symbolize, #try_ssh_access, #uncleanup, unmove_files, validate_runtimes, #wait_for_ssh_access, #warn

Methods included from Dpl::Provider::Dsl

#apt, #apt?, #cmds, #description, #env, #errs, #full_name, #gem, #gem?, #keep, #move, #msgs, #needs, #needs?, #node_js, #npm, #npm?, #opt, #path, #pip, #pip?, #python, #ruby_pre?, #ruby_version, #runtimes, #status, #strs, #summary, #user_agent, #vars

Methods included from Squiggle

#sq

Methods included from Assets

#asset

Methods included from Env

included, #opts

Methods included from ConfigFile

included, #opts

Methods included from Interpolate

#interpolate, #obfuscate, #vars

Methods included from Memoize

included

Constructor Details

This class inherits a constructor from Dpl::Provider

Instance Method Details

#appObject



110
111
112
# File 'lib/dpl/providers/opsworks.rb', line 110

def app
  @app ||= describe_app
end

#build_numberObject



118
119
120
# File 'lib/dpl/providers/opsworks.rb', line 118

def build_number
  super || sha
end

#commentObject



114
115
116
# File 'lib/dpl/providers/opsworks.rb', line 114

def comment
  interpolate(msg(:comment))
end

#create_deploymentObject



55
56
57
58
59
60
# File 'lib/dpl/providers/opsworks.rb', line 55

def create_deployment
  print :create_deploy
  id = opsworks.create_deployment(deploy_config)[:deployment_id]
  info :done, id
  wait_until_deployed(id) if wait_until_deployed?
end

#credentialsObject



136
137
138
# File 'lib/dpl/providers/opsworks.rb', line 136

def credentials
  Aws::Credentials.new(access_key_id, secret_access_key)
end

#custom_jsonObject



102
103
104
# File 'lib/dpl/providers/opsworks.rb', line 102

def custom_json
  super || { deploy: { app[:shortname] => { migrate: migrate?, scm: { revision: git_sha } } } }.to_json
end

#deployObject



49
50
51
52
53
# File 'lib/dpl/providers/opsworks.rb', line 49

def deploy
  timeout(600) { create_deployment }
rescue Aws::Errors::ServiceError => e
  error :service_error, e.message
end

#deploy_configObject



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/dpl/providers/opsworks.rb', line 62

def deploy_config
  compact(
    stack_id:,
    app_id:,
    command: { name: 'deploy' },
    comment:,
    custom_json:,
    instance_ids:,
    layer_ids:
  )
end

#describe_appObject



122
123
124
125
126
# File 'lib/dpl/providers/opsworks.rb', line 122

def describe_app
  data = opsworks.describe_apps(app_ids: [app_id])
  error :app_not_found, app_id unless data[:apps]&.any?
  data[:apps].first
end

#describe_deployments(id) ⇒ Object



128
129
130
# File 'lib/dpl/providers/opsworks.rb', line 128

def describe_deployments(id)
  opsworks.describe_deployments(deployment_ids: [id])
end

#loginObject



45
46
47
# File 'lib/dpl/providers/opsworks.rb', line 45

def 
  info :login
end

#opsworksObject



132
133
134
# File 'lib/dpl/providers/opsworks.rb', line 132

def opsworks
  @opsworks ||= Aws::OpsWorks::Client.new(region:, credentials:)
end

#poll_deployment(id) ⇒ Object



82
83
84
85
86
# File 'lib/dpl/providers/opsworks.rb', line 82

def poll_deployment(id)
  print '.'
  sleep 5
  describe_deployments(id)[:deployments].first
end

#stack_idObject



106
107
108
# File 'lib/dpl/providers/opsworks.rb', line 106

def stack_id
  app[:stack_id]
end

#timeout(sec, &block) ⇒ Object



140
141
142
143
144
# File 'lib/dpl/providers/opsworks.rb', line 140

def timeout(sec, &block)
  Timeout.timeout(sec, &block)
rescue Timeout::Error
  error :timeout
end

#update_appObject



88
89
90
91
# File 'lib/dpl/providers/opsworks.rb', line 88

def update_app
  info :update_app
  opsworks.update_app(update_config)
end

#update_configObject



93
94
95
96
97
98
99
100
# File 'lib/dpl/providers/opsworks.rb', line 93

def update_config
  {
    app_id:,
    app_source: {
      revision: git_sha
    }
  }
end

#wait_until_deployed(id) ⇒ Object



74
75
76
77
78
79
80
# File 'lib/dpl/providers/opsworks.rb', line 74

def wait_until_deployed(id)
  print :waiting
  depl = poll_deployment(id) while depl.nil? || depl[:status] == 'running'
  error :failed if depl[:status] != 'successful'
  info :success
  update_app if update_on_success?
end