Class: Dpl::Providers::Codedeploy
Overview
split this up to CodeDeploy::Github and CodeDeploy::S3 using the revision_type, in order to make opts more strict
Constant Summary
Dpl::Provider::FOLDS, Dpl::Provider::STAGES
Instance Attribute Summary
#key_name, #repo_name
Instance Method Summary
collapse
#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
#apt, #apt?, #cmds, #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
#interpolate, #obfuscate, #vars
Methods included from Memoize
included
Constructor Details
This class inherits a constructor from Dpl::Provider
Instance Method Details
#bucket ⇒ Object
154
155
156
|
# File 'lib/dpl/providers/codedeploy.rb', line 154
def bucket
super || error(:missing_bucket)
end
|
#build_number ⇒ Object
170
171
172
|
# File 'lib/dpl/providers/codedeploy.rb', line 170
def build_number
ENV['TRAVIS_BUILD_NUMBER']
end
|
#bundle_type ⇒ Object
162
163
164
|
# File 'lib/dpl/providers/codedeploy.rb', line 162
def bundle_type
super || key =~ /\.(tar|tgz|zip)$/ && ::Regexp.last_match(1) || error(:unknown_bundle_type)
end
|
#client_options ⇒ Object
182
183
184
|
# File 'lib/dpl/providers/codedeploy.rb', line 182
def client_options
compact(region:, credentials:, endpoint:)
end
|
#code_deploy ⇒ Object
174
175
176
|
# File 'lib/dpl/providers/codedeploy.rb', line 174
def code_deploy
@code_deploy ||= Aws::CodeDeploy::Client.new(client_options)
end
|
#commit_id ⇒ Object
146
147
148
|
# File 'lib/dpl/providers/codedeploy.rb', line 146
def commit_id
super || git_sha
end
|
#create_deployment ⇒ Object
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/dpl/providers/codedeploy.rb', line 76
def create_deployment
deployment = code_deploy.create_deployment(
revision:,
application_name: application,
deployment_group_name: deployment_group,
description:,
file_exists_behavior: file_exists_behavior.upcase
)
deployment.deployment_id
end
|
#credentials ⇒ Object
186
187
188
|
# File 'lib/dpl/providers/codedeploy.rb', line 186
def credentials
Aws::Credentials.new(access_key_id, secret_access_key)
end
|
#deploy ⇒ Object
58
59
60
61
62
63
64
65
|
# File 'lib/dpl/providers/codedeploy.rb', line 58
def deploy
register_revision if revision_info[:version]
id = create_deployment
info :deploy_triggered, id
wait_until_deployed(id) if wait_until_deployed?
rescue Aws::CodeDeploy::Errors::DeploymentLimitExceededException => e
error e.message
end
|
#description ⇒ Object
166
167
168
|
# File 'lib/dpl/providers/codedeploy.rb', line 166
def description
interpolate(super || msg(:description), vars:)
end
|
#github_revision ⇒ Object
136
137
138
139
140
141
142
143
144
|
# File 'lib/dpl/providers/codedeploy.rb', line 136
def github_revision
{
revision_type: 'GitHub',
git_hub_location: {
commit_id:,
repository:
}
}
end
|
#key ⇒ Object
158
159
160
|
# File 'lib/dpl/providers/codedeploy.rb', line 158
def key
super || error(:missing_key)
end
|
#login ⇒ Object
54
55
56
|
# File 'lib/dpl/providers/codedeploy.rb', line 54
def login
info :login
end
|
#poll(id) ⇒ Object
98
99
100
101
102
|
# File 'lib/dpl/providers/codedeploy.rb', line 98
def poll(id)
sleep 5
print '.'
code_deploy.get_deployment(deployment_id: id)[:deployment_info][:status]
end
|
#register_revision ⇒ Object
67
68
69
70
71
72
73
74
|
# File 'lib/dpl/providers/codedeploy.rb', line 67
def register_revision
info :register_revision, revision_info[:version], revision_info[:e_tag]
code_deploy.register_application_revision(
revision:,
application_name: application,
description:
)
end
|
#repository ⇒ Object
150
151
152
|
# File 'lib/dpl/providers/codedeploy.rb', line 150
def repository
super || ENV['TRAVIS_REPO_SLUG'] || File.basename(Dir.pwd)
end
|
#revision ⇒ Object
108
109
110
111
112
113
114
115
|
# File 'lib/dpl/providers/codedeploy.rb', line 108
def revision
@revision ||= case revision_type
when 's3' then s3_revision
when 'github' then github_revision
when nil then bucket? ? s3_revision : github_revision
else error :unknown_revision_type, revision_type
end
end
|
#revision_info ⇒ Object
104
105
106
|
# File 'lib/dpl/providers/codedeploy.rb', line 104
def revision_info
revision[:s3_location] || {}
end
|
#revision_version_info ⇒ Object
130
131
132
133
134
|
# File 'lib/dpl/providers/codedeploy.rb', line 130
def revision_version_info
s3.head_object(bucket:, key:)
rescue Aws::Errors::ServiceError => e
error e.message
end
|
#s3 ⇒ Object
178
179
180
|
# File 'lib/dpl/providers/codedeploy.rb', line 178
def s3
@s3 ||= Aws::S3::Client.new(client_options)
end
|
#s3_revision ⇒ Object
117
118
119
120
121
122
123
124
125
126
127
128
|
# File 'lib/dpl/providers/codedeploy.rb', line 117
def s3_revision
{
revision_type: 'S3',
s3_location: compact(
bucket:,
bundle_type:,
version: revision_version_info[:version_id],
e_tag: revision_version_info[:etag],
key:
)
}
end
|
#wait_until_deployed(id) ⇒ Object
87
88
89
90
91
92
93
94
95
96
|
# File 'lib/dpl/providers/codedeploy.rb', line 87
def wait_until_deployed(id)
print :waiting_for_deploy
status = poll(id) until %w[Succeeded Failed Stopped].include?(status)
case status
when 'Succeeded'
info :finished_deploy, status
else
error :finished_deploy, status
end
end
|