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
151
152
153
|
# File 'lib/dpl/providers/codedeploy.rb', line 151
def bucket
super || error(:missing_bucket)
end
|
#build_number ⇒ Object
167
168
169
|
# File 'lib/dpl/providers/codedeploy.rb', line 167
def build_number
ENV['TRAVIS_BUILD_NUMBER']
end
|
#bundle_type ⇒ Object
159
160
161
|
# File 'lib/dpl/providers/codedeploy.rb', line 159
def bundle_type
super || key =~ /\.(tar|tgz|zip)$/ && $1 || error(:unknown_bundle_type)
end
|
#client_options ⇒ Object
179
180
181
|
# File 'lib/dpl/providers/codedeploy.rb', line 179
def client_options
compact(region: region, credentials: credentials, endpoint: endpoint)
end
|
#code_deploy ⇒ Object
171
172
173
|
# File 'lib/dpl/providers/codedeploy.rb', line 171
def code_deploy
@code_deploy ||= Aws::CodeDeploy::Client.new(client_options)
end
|
#commit_id ⇒ Object
143
144
145
|
# File 'lib/dpl/providers/codedeploy.rb', line 143
def commit_id
super || git_sha
end
|
#create_deployment ⇒ Object
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/dpl/providers/codedeploy.rb', line 73
def create_deployment
deployment = code_deploy.create_deployment(
revision: revision,
application_name: application,
deployment_group_name: deployment_group,
description: description,
file_exists_behavior: file_exists_behavior.upcase
)
deployment.deployment_id
end
|
#credentials ⇒ Object
183
184
185
|
# File 'lib/dpl/providers/codedeploy.rb', line 183
def credentials
Aws::Credentials.new(access_key_id, secret_access_key)
end
|
#deploy ⇒ Object
55
56
57
58
59
60
61
62
|
# File 'lib/dpl/providers/codedeploy.rb', line 55
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
163
164
165
|
# File 'lib/dpl/providers/codedeploy.rb', line 163
def description
interpolate(super || msg(:description), vars: vars)
end
|
#github_revision ⇒ Object
133
134
135
136
137
138
139
140
141
|
# File 'lib/dpl/providers/codedeploy.rb', line 133
def github_revision
{
revision_type: 'GitHub',
git_hub_location: {
commit_id: commit_id,
repository: repository
}
}
end
|
#key ⇒ Object
155
156
157
|
# File 'lib/dpl/providers/codedeploy.rb', line 155
def key
super || error(:missing_key)
end
|
#login ⇒ Object
51
52
53
|
# File 'lib/dpl/providers/codedeploy.rb', line 51
def login
info :login
end
|
#poll(id) ⇒ Object
95
96
97
98
99
|
# File 'lib/dpl/providers/codedeploy.rb', line 95
def poll(id)
sleep 5
print '.'
code_deploy.get_deployment(deployment_id: id)[:deployment_info][:status]
end
|
#register_revision ⇒ Object
64
65
66
67
68
69
70
71
|
# File 'lib/dpl/providers/codedeploy.rb', line 64
def register_revision
info :register_revision, revision_info[:version], revision_info[:e_tag]
code_deploy.register_application_revision(
revision: revision,
application_name: application,
description: description
)
end
|
#repository ⇒ Object
147
148
149
|
# File 'lib/dpl/providers/codedeploy.rb', line 147
def repository
super || ENV['TRAVIS_REPO_SLUG'] || File.basename(Dir.pwd)
end
|
#revision ⇒ Object
105
106
107
108
109
110
111
112
|
# File 'lib/dpl/providers/codedeploy.rb', line 105
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
101
102
103
|
# File 'lib/dpl/providers/codedeploy.rb', line 101
def revision_info
revision[:s3_location] || {}
end
|
#revision_version_info ⇒ Object
127
128
129
130
131
|
# File 'lib/dpl/providers/codedeploy.rb', line 127
def revision_version_info
s3.head_object(bucket: bucket, key: key)
rescue Aws::Errors::ServiceError => e
error e.message
end
|
#s3 ⇒ Object
175
176
177
|
# File 'lib/dpl/providers/codedeploy.rb', line 175
def s3
@s3 ||= Aws::S3::Client.new(client_options)
end
|
#s3_revision ⇒ Object
114
115
116
117
118
119
120
121
122
123
124
125
|
# File 'lib/dpl/providers/codedeploy.rb', line 114
def s3_revision
{
revision_type: 'S3',
s3_location: compact(
bucket: bucket,
bundle_type: bundle_type,
version: revision_version_info[:version_id],
e_tag: revision_version_info[:etag],
key: key,
)
}
end
|
#wait_until_deployed(id) ⇒ Object
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/dpl/providers/codedeploy.rb', line 84
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
|