idlc-sdk-deploy 1.0.0.rc2 → 1.0.0.rc3
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b3b51c257080d9be67689a495fe74209d817a439
|
4
|
+
data.tar.gz: 892a9846ac9aa7aa0e5c30bb98e720769594a049
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81008c97731ddaf34cee0a9a72bbdd93f82f4cfe47f284d63f82173187c17a836d391f6139dd3bbc91e122fbe4363961aefab7b0ced8dea01d1b48af50269632
|
7
|
+
data.tar.gz: 2f805f5131b70a9788d430dcc7c8124f7242cd4ec44ddbd728120c6944a32d76a5b2f0a3b03f10749ff977a39bb3af09d03527f16e8c8f55ad000cab9358870f
|
data/lib/idlc-sdk-deploy.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: idlc-sdk-deploy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.rc3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Cazell
|
@@ -213,10 +213,8 @@ files:
|
|
213
213
|
- idlc-sdk-deploy.gemspec
|
214
214
|
- lib/idlc-sdk-deploy.rb
|
215
215
|
- lib/idlc-sdk-deploy/config.rb
|
216
|
-
- lib/idlc-sdk-deploy/elasticsearchv2.rb
|
217
216
|
- lib/idlc-sdk-deploy/keypair.rb
|
218
217
|
- lib/idlc-sdk-deploy/power.rb
|
219
|
-
- lib/idlc-sdk-deploy/tasks/elasticsearchv2.rake
|
220
218
|
- lib/idlc-sdk-deploy/version.rb
|
221
219
|
homepage: https://github.com/nathantcz/idlc-sdk
|
222
220
|
licenses:
|
@@ -1,183 +0,0 @@
|
|
1
|
-
module Idlc
|
2
|
-
module Deploy
|
3
|
-
class ElasticsearchV2
|
4
|
-
include Idlc::Helpers
|
5
|
-
|
6
|
-
def initialize(credentials, region, endpoint)
|
7
|
-
@service_name = 'es'
|
8
|
-
@credentials = credentials
|
9
|
-
@region = region
|
10
|
-
@endpoint = endpoint.strip
|
11
|
-
@index_migrations = []
|
12
|
-
@tmp_dir = Dir.mktmpdir('es-temp')
|
13
|
-
@full_release_path = ''
|
14
|
-
|
15
|
-
# Instantiate an S3 Client
|
16
|
-
@s3 = Aws::S3::Client.new(
|
17
|
-
region: @region,
|
18
|
-
access_key_id: @credentials[:access_key_id],
|
19
|
-
secret_access_key: @credentials[:secret_access_key]
|
20
|
-
)
|
21
|
-
end
|
22
|
-
|
23
|
-
def create_index(app_release, bucket, prefix)
|
24
|
-
mapping = es_mapping(bucket, prefix, app_release)
|
25
|
-
parts = parse_request(mapping)
|
26
|
-
|
27
|
-
send_signed_request(
|
28
|
-
parts[:method],
|
29
|
-
"#{@endpoint}#{parts[:path]}",
|
30
|
-
parts[:body]
|
31
|
-
)
|
32
|
-
end
|
33
|
-
|
34
|
-
def delete_index(index)
|
35
|
-
send_signed_request('DELETE', "#{@endpoint}/#{index}", '{}')
|
36
|
-
end
|
37
|
-
|
38
|
-
def run_migrations(app_release, bucket, prefix)
|
39
|
-
migrations = es_migrations(bucket, prefix, app_release)
|
40
|
-
|
41
|
-
migrations.each do |migration|
|
42
|
-
parts = parse_request(migration)
|
43
|
-
|
44
|
-
send_signed_request(
|
45
|
-
parts[:method],
|
46
|
-
"#{@endpoint}#{parts[:path]}",
|
47
|
-
parts[:body]
|
48
|
-
)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
def cleanup
|
53
|
-
debug("keeping directory: #{@tmp_dir} for dubugging")
|
54
|
-
return if ENV['DEBUG']
|
55
|
-
|
56
|
-
FileUtils.rm_rf(@tmp_dir)
|
57
|
-
end
|
58
|
-
|
59
|
-
private
|
60
|
-
|
61
|
-
def major_minor_patch(version)
|
62
|
-
# Strip build number from version number. The migration scripts only include
|
63
|
-
# major.minor.patch
|
64
|
-
version.split('.')[0..2].join('.')
|
65
|
-
end
|
66
|
-
|
67
|
-
def es_mapping(bucket, prefix, app_release)
|
68
|
-
get_release(bucket, prefix, app_release)
|
69
|
-
|
70
|
-
# Read Mapping JSON into string
|
71
|
-
file = File.open("#{@full_release_path}/es/axiompro_mapping.txt", 'rb')
|
72
|
-
mapping = file.read
|
73
|
-
file.close
|
74
|
-
|
75
|
-
mapping
|
76
|
-
end
|
77
|
-
|
78
|
-
def es_migrations(bucket, prefix, app_release)
|
79
|
-
get_release(bucket, prefix, app_release)
|
80
|
-
migrations = []
|
81
|
-
|
82
|
-
Dir.glob("#{@full_release_path}/es/Migrations/*.txt").each do |f|
|
83
|
-
msg(f)
|
84
|
-
file = File.open(f, 'rb')
|
85
|
-
migrations.push(file.read)
|
86
|
-
file.close
|
87
|
-
end
|
88
|
-
|
89
|
-
migrations
|
90
|
-
end
|
91
|
-
|
92
|
-
def get_release(src_bucket, app, version)
|
93
|
-
@full_release_path = "#{@tmp_dir}/#{app}-#{version}"
|
94
|
-
release_archive = "#{@full_release_path}.zip"
|
95
|
-
|
96
|
-
return if File.exist? @full_release_path
|
97
|
-
|
98
|
-
@s3.get_object(
|
99
|
-
response_target: release_archive,
|
100
|
-
bucket: src_bucket,
|
101
|
-
key: "#{app}/#{major_minor_patch(version)}/AxiomPro.#{version}.deploy.zip"
|
102
|
-
)
|
103
|
-
|
104
|
-
unzip(release_archive, @full_release_path)
|
105
|
-
end
|
106
|
-
|
107
|
-
def unzip(file, destination)
|
108
|
-
Zip::ZipFile.open(file) do |zip_file|
|
109
|
-
zip_file.each do |f|
|
110
|
-
f_path = File.join(destination, f.name)
|
111
|
-
FileUtils.mkdir_p(File.dirname(f_path))
|
112
|
-
f.extract(f_path)
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
def send_signed_request(method, url, payload)
|
118
|
-
uri = URI.parse(url)
|
119
|
-
https = Net::HTTP.new(uri.host, uri.port)
|
120
|
-
https.use_ssl = true
|
121
|
-
signature = sigv4_signature(method, url, payload)
|
122
|
-
request = http_request(method, uri.path, signature, payload)
|
123
|
-
|
124
|
-
response = https.request(request)
|
125
|
-
msg("#{response.code} #{response.message} #{response.body}")
|
126
|
-
end
|
127
|
-
|
128
|
-
def parse_request(document)
|
129
|
-
method = document.lines[0].strip
|
130
|
-
path = document.lines[1].strip
|
131
|
-
body = document.lines[2..-1].join
|
132
|
-
|
133
|
-
{ method: method, path: path, body: body }
|
134
|
-
end
|
135
|
-
|
136
|
-
def set_headers(request, signature)
|
137
|
-
request.add_field 'host', signature.headers['host']
|
138
|
-
request.add_field 'content-type', 'application/json'
|
139
|
-
request.add_field 'x-amz-content-sha256', signature.headers['x-amz-content-sha256']
|
140
|
-
request.add_field 'x-amz-date', signature.headers['x-amz-date']
|
141
|
-
request.add_field 'authorization', signature.headers['authorization']
|
142
|
-
end
|
143
|
-
|
144
|
-
def http_request(method, path, signature, payload)
|
145
|
-
case method.downcase
|
146
|
-
when 'put'
|
147
|
-
request = Net::HTTP::Put.new(path)
|
148
|
-
when 'get'
|
149
|
-
request = Net::HTTP::Get.new(path)
|
150
|
-
when 'delete'
|
151
|
-
request = Net::HTTP::Delete.new(path)
|
152
|
-
else
|
153
|
-
request = Net::HTTP::Put.new(path)
|
154
|
-
end
|
155
|
-
|
156
|
-
set_headers(request, signature)
|
157
|
-
request.body = payload
|
158
|
-
|
159
|
-
request
|
160
|
-
end
|
161
|
-
|
162
|
-
def signer
|
163
|
-
Aws::Sigv4::Signer.new(
|
164
|
-
service: @service_name,
|
165
|
-
region: @region,
|
166
|
-
access_key_id: @credentials[:access_key_id],
|
167
|
-
secret_access_key: @credentials[:secret_access_key]
|
168
|
-
)
|
169
|
-
end
|
170
|
-
|
171
|
-
def sigv4_signature(method, url, payload)
|
172
|
-
signer.sign_request(
|
173
|
-
http_method: method,
|
174
|
-
url: url,
|
175
|
-
headers: {
|
176
|
-
'content-type' => 'application/json'
|
177
|
-
},
|
178
|
-
body: payload
|
179
|
-
)
|
180
|
-
end
|
181
|
-
end
|
182
|
-
end
|
183
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
namespace :elasticsearchv2 do
|
2
|
-
task :deps do
|
3
|
-
if ENV.include? 'ES_ENDPOINT'
|
4
|
-
ES_ENDPOINT = ENV['ES_ENDPOINT']
|
5
|
-
else
|
6
|
-
ES_ENDPOINT = Idlc::Deploy::Config.get_deployment_output('es_endpoint')
|
7
|
-
end
|
8
|
-
|
9
|
-
ES = Idlc::Deploy::ElasticsearchV2.new(
|
10
|
-
{
|
11
|
-
access_key_id: ENV['AWS_ACCESS_KEY_ID'],
|
12
|
-
secret_access_key: ENV['AWS_SECRET_ACCESS_KEY']
|
13
|
-
},
|
14
|
-
ENV['AWS_REGION'],
|
15
|
-
ES_ENDPOINT
|
16
|
-
)
|
17
|
-
end
|
18
|
-
|
19
|
-
desc 'Initialize ElasticSearch'
|
20
|
-
task init: [:deps] do
|
21
|
-
ES.create_index(ENV['APP_RELEASE'], 'dev-publish', 'axp')
|
22
|
-
end
|
23
|
-
|
24
|
-
desc 'Clear ElasticSearch'
|
25
|
-
task clear: [:setup, :deps] do
|
26
|
-
ES.delete_index('axiompro')
|
27
|
-
ES.cleanup
|
28
|
-
end
|
29
|
-
|
30
|
-
desc 'Update ElasticSearch'
|
31
|
-
task update: [:deps, :init] do
|
32
|
-
ES.run_migrations(ENV['APP_RELEASE'], 'dev-publish', 'axp')
|
33
|
-
ES.cleanup
|
34
|
-
end
|
35
|
-
end
|