-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
378 lines (319 loc) · 10.2 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
$:.unshift File.join(File.dirname(__FILE__), 'lib')
require 'yaml'
require 'rake_terraform'
require 'rake_docker'
require 'confidante'
require 's3_version_file'
require 'terraform_output'
RakeTerraform.define_installation_tasks(
path: File.join(Dir.pwd, 'vendor', 'terraform'),
version: '0.11.1')
configuration = Confidante.configuration
shared_configuration =
configuration
.for_overrides(
shared_deployment_identifier: 'default')
version = S3VersionFile.new(
shared_configuration.region,
shared_configuration.shared_storage_bucket_name,
shared_configuration.image_version_key,
'build/version')
task :default => [
:'bootstrap:plan',
:'blockchain_archive_lambda:plan',
:'ardor:image_repository:plan',
:'ardor:service:plan',
:'cert_manager:task:plan'
]
namespace :version do
task :bump do
version.bump(:revision)
end
end
namespace :virtualenv do
task :create do
mkdir_p 'vendor'
sh 'virtualenv vendor/virtualenv --always-copy'
end
task :destroy do
rm_rf 'vendor/virtualenv'
end
task :ensure do
unless File.exists?('vendor/virtualenv')
Rake::Task['virtualenv:create'].invoke
end
end
end
namespace :dependencies do
namespace :install do
task :blockchain_archive_lambda => ['virtualenv:ensure'] do
puts 'Installing dependencies for blockchain archive lambda'
sh_in_virtualenv(
'pip', 'install -r ' +
'infra/blockchain-archive-lambda/' +
'lambda-definitions/blockchain-archive/requirements.txt')
end
task :all => ['dependencies:install:blockchain_archive_lambda']
end
end
namespace :test do
namespace :unit do
task :blockchain_archive_lambda => [
'dependencies:install:blockchain_archive_lambda'
] do
puts 'Running unit tests for blockchain archive lambda'
sh_in_virtualenv(
'python', '-m unittest discover -s ' +
'infra/blockchain-archive-lambda/' +
'lambda-definitions/blockchain-archive')
end
task :all => ['test:unit:blockchain_archive_lambda']
end
end
namespace :bootstrap do
RakeTerraform.define_command_tasks do |t|
t.argument_names = [:deployment_identifier]
t.configuration_name = 'bootstrap'
t.source_directory = 'infra/bootstrap'
t.work_directory = 'build'
t.state_file = lambda do |args|
deployment =
configuration
.for_overrides(args)
.deployment_identifier
File.join(Dir.pwd, "state/bootstrap-#{deployment}.tfstate")
end
t.vars = lambda do |args|
deployment =
configuration
.for_overrides(args)
.deployment_identifier
configuration
.for_overrides(args)
.for_scope(
role: 'bootstrap',
deployment: deployment)
.vars
end
end
end
namespace :blockchain_archive_lambda do
task :prepare => [
'terraform:ensure',
'dependencies:install:blockchain_archive_lambda'
] do
rm_rf('build/lambda-definitions/blockchain-archive')
mkdir_p('build/lambda-definitions/blockchain-archive')
cp_r(
'infra/blockchain-archive-lambda/lambda-definitions/blockchain-archive/.',
'build/lambda-definitions/blockchain-archive')
cp_r(
'vendor/virtualenv/lib/python3.6/site-packages/.',
'build/lambda-definitions/blockchain-archive')
end
RakeTerraform.define_command_tasks do |t|
t.argument_names = [:specific_deployment_identifier]
t.ensure_task = 'blockchain_archive_lambda:prepare'
t.configuration_name = 'blockchain archive lambda'
t.source_directory = 'infra/blockchain-archive-lambda'
t.work_directory = 'build'
t.backend_config = lambda do |args|
deployment =
configuration
.for_overrides(args)
.specific_deployment_identifier
configuration
.for_overrides(args)
.for_scope(
role: 'blockchain-archive-lambda',
deployment: deployment)
.backend_config
end
t.vars = lambda do |args|
deployment =
configuration
.for_overrides(args)
.specific_deployment_identifier
configuration
.for_overrides(args)
.for_scope(
role: 'blockchain-archive-lambda',
deployment: deployment)
.vars
end
end
end
namespace :ardor do
namespace :image_repository do
RakeTerraform.define_command_tasks do |t|
t.configuration_name = 'Ardor image repository'
t.source_directory = 'infra/image-repository'
t.work_directory = 'build'
t.backend_config = lambda do
configuration
.for_overrides(
shared_deployment_identifier: 'default')
.for_scope(
role: 'ardor-image-repository',
deployment: 'default')
.backend_config
end
t.vars = lambda do
configuration
.for_overrides(
shared_deployment_identifier: 'default')
.for_scope(
role: 'ardor-image-repository',
deployment: 'default')
.vars
end
end
end
namespace :image do
RakeDocker.define_image_tasks do |t|
t.image_name = 'aws-ardor'
t.work_directory = 'build/images'
t.copy_spec = [
{from: 'src/ardor/Dockerfile', to: 'Dockerfile'},
{from: 'src/ardor/ardor.sh', to: 'ardor.sh'},
{from: 'src/ardor/ardor.properties.template',
to: 'ardor.properties.template'},
{from: 'src/ardor/ardor-default.env', to: 'ardor-default.env'}
]
t.repository_name = 'eth-quest/aws-ardor'
t.repository_url = lambda do
backend_config =
configuration
.for_overrides(
shared_deployment_identifier: 'default')
.for_scope(
role: 'ardor-image-repository',
deployment: 'default')
.backend_config
TerraformOutput.for(
name: 'repository_url',
source_directory: 'infra/image-repository',
work_directory: 'build',
backend_config: backend_config)
end
t.credentials = lambda do
configuration =
configuration
.for_overrides(
shared_deployment_identifier: 'default')
.for_scope(
role: 'ardor-image-repository',
deployment: 'default')
backend_config = configuration.backend_config
region = configuration.region
authentication_factory = RakeDocker::Authentication::ECR.new do |c|
c.region = region
c.registry_id = TerraformOutput.for(
name: 'registry_id',
source_directory: 'infra/image-repository',
work_directory: 'build',
backend_config: backend_config)
end
authentication_factory.call
end
t.tags = lambda do
[version.refresh.to_s, 'latest']
end
end
task :publish => [
'version:bump',
'ardor:image:clean',
'ardor:image:build',
'ardor:image:tag',
'ardor:image:push'
]
end
namespace :service do
RakeTerraform.define_command_tasks do |t|
t.argument_names = [
:specific_deployment_identifier,
:shared_deployment_identifier,
:environment_deployment_identifier
]
t.configuration_name = 'Ardor service'
t.source_directory = 'infra/ardor-service'
t.work_directory = 'build'
t.backend_config = lambda do |args|
deployment_identifier =
configuration
.for_overrides(args)
.deployment_identifier
configuration
.for_overrides(args)
.for_scope(
role: 'ardor-service',
deployment: deployment_identifier)
.backend_config
end
t.vars = lambda do |args|
deployment =
configuration
.for_overrides(args)
.for_scope(role: 'ardor-service')
.specific_deployment_identifier
ardor_node_config = YAML.load_file(
'config/secrets/ardor/%s.yaml' % deployment)
configuration
.for_overrides(args.to_hash.merge(
'ardor_node_version_number' => version.refresh.to_s,
'admin_password' => ardor_node_config['admin_password'],
'key_store_password' => ardor_node_config['key_store_password']))
.for_scope(
role: 'ardor-service',
deployment: deployment)
.vars
end
end
end
end
namespace :cert_manager do
namespace :task do
RakeTerraform.define_command_tasks do |t|
t.argument_names = [
:specific_deployment_identifier,
:shared_deployment_identifier,
:environment_deployment_identifier
]
t.configuration_name = 'cert manager task'
t.source_directory = 'infra/cert-manager-task'
t.work_directory = 'build'
t.backend_config = lambda do |args|
deployment_identifier =
configuration
.for_overrides(args)
.deployment_identifier
configuration
.for_overrides(args)
.for_scope(
role: 'cert-manager-task',
deployment: deployment_identifier)
.backend_config
end
t.vars = lambda do |args|
deployment =
configuration
.for_overrides(args)
.for_scope(role: 'cert-manager-task')
.specific_deployment_identifier
ardor_node_config = YAML.load_file(
'config/secrets/ardor/%s.yaml' % deployment)
configuration
.for_overrides(args.to_hash.merge(
'key_store_password' => ardor_node_config['key_store_password']))
.for_scope(
role: 'cert-manager-task',
deployment: deployment)
.vars
end
end
end
end
def sh_in_virtualenv command, argument_string
sh "#{File.expand_path('vendor/virtualenv/bin')}/#{command} " +
"#{argument_string}"
end