cfhighlander 0.4.0.alpha.1531791475 → 0.4.0.alpha.1531985380
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cfhighlander.compiler.rb +77 -62
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b1b127f5a658380bc3c38b939b0812378c87cc871ff4bba6842173dcf7bb977
|
4
|
+
data.tar.gz: 64d4ecf0310154bf373ee27b0b702208c566710b02e9a7c30dbdcce5bb56927d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7116eb1edd2fcf36279df045c919e67cd79637ad6d54b82c398092e95516d6dc74e2fffa5b96c587e45724351ffbdd9ca737c0eb736246ab9cea0d30f084f4b
|
7
|
+
data.tar.gz: b288e065aa468fbe04861f06b4a354af8ead3a8c2581079cd74bcff6a60e686599ae3c54f77f0d6317e4cf792766c19a91f968bbab8eb5a480b781918baa9306
|
@@ -248,78 +248,93 @@ module Cfhighlander
|
|
248
248
|
# download file if code remote archive
|
249
249
|
puts "Packaging AWS Lambda function #{name}...\n"
|
250
250
|
puts "Destination archive is #{full_destination_path}"
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
251
|
+
|
252
|
+
md5 = Digest::MD5.new
|
253
|
+
md5.update lambda_config['code']
|
254
|
+
hash = md5.hexdigest
|
255
|
+
cached_location = "#{@workdir}/.cache/lambdas/#{hash}"
|
256
|
+
if cached_downloads.key? lambda_config['code']
|
257
|
+
puts "Using already downloaded archive #{lambda_config['code']}"
|
258
|
+
FileUtils.copy(cached_downloads[lambda_config['code']], full_destination_path)
|
259
|
+
elsif File.file? cached_location
|
260
|
+
puts "Using cached download - '#{cached_location}'"
|
261
|
+
FileUtils.copy(cached_location, full_destination_path)
|
262
|
+
else
|
263
|
+
if lambda_config['code'].include? 'http'
|
264
|
+
puts "INFO Downloading lambda #{name} source from #{lambda_config['code']}"
|
264
265
|
download = open(lambda_config['code'])
|
265
266
|
IO.copy_stream(download, "#{out_folder}/src.zip")
|
266
267
|
FileUtils.mkdir_p('.cache/lambdas')
|
267
268
|
FileUtils.copy("#{out_folder}/src.zip", cached_location)
|
268
269
|
FileUtils.copy("#{out_folder}/src.zip", full_destination_path)
|
269
|
-
puts "
|
270
|
+
puts "INFO lambda #{name} source cached to #{cached_location}"
|
270
271
|
cached_downloads[lambda_config['code']] = cached_location
|
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
|
-
lambda_source_dir = tmp_source_dir
|
302
|
-
|
303
|
-
# Lambda function source code allows pre-processing (e.g. install code dependencies)
|
304
|
-
unless lambda_config['package_cmd'].nil?
|
305
|
-
puts "Following code will be executed to generate lambda function #{name}:\n\n#{lambda_config['package_cmd']}\n\n"
|
306
|
-
|
307
|
-
if @confirm_code_execution
|
308
|
-
exit -7 unless HighLine.agree('Proceed (y/n)?')
|
272
|
+
elsif lambda_config['code'].include? 's3://'
|
273
|
+
parts = lambda_config['code'].split('/')
|
274
|
+
if parts.size < 4
|
275
|
+
STDERR.puts "ERROR: Lambda function source code from s3 should be in s3://bucket/path format"
|
276
|
+
exit -8
|
277
|
+
end
|
278
|
+
bucket = parts[2]
|
279
|
+
key = parts.drop(3).join('/')
|
280
|
+
s3 = Aws::S3::Client.new({ region: s3_bucket_region(bucket) })
|
281
|
+
puts "INFO Downloading lambda #{name} source from #{lambda_config['code']}"
|
282
|
+
s3.get_object({ bucket: bucket, key: key, response_target: cached_location })
|
283
|
+
puts "INFO lambda #{name} source cached to #{cached_location}"
|
284
|
+
FileUtils.copy(cached_location, full_destination_path)
|
285
|
+
cached_downloads[lambda_config['code']] = cached_location
|
286
|
+
else
|
287
|
+
# zip local code
|
288
|
+
component = @component
|
289
|
+
component_dir = component.template.template_location
|
290
|
+
full_path = "#{component_dir}/lambdas/#{lambda_config['code']}"
|
291
|
+
|
292
|
+
until (File.exist? full_path or component_dir.nil?)
|
293
|
+
parent_exists = (not component.extended_component.nil?)
|
294
|
+
component = component.extended_component if parent_exists
|
295
|
+
component_dir = component.template.template_location if parent_exists
|
296
|
+
full_path = "#{component_dir}/lambdas/#{lambda_config['code']}" if parent_exists
|
297
|
+
component_dir = nil unless parent_exists
|
298
|
+
end
|
299
|
+
if component_dir.nil?
|
300
|
+
STDERR.puts "ERROR: Could not find source code directory for lambda function #{name} in component #{@component.name}"
|
301
|
+
exit -9
|
309
302
|
end
|
310
303
|
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
304
|
+
# lambda source can be either path to file or directory within that file
|
305
|
+
# optionally, lambda source code
|
306
|
+
lambda_source_dir = File.dirname(full_path)
|
307
|
+
lambda_source_dir = full_path if Pathname.new(full_path).directory?
|
308
|
+
|
309
|
+
# executing package command can generate files. We DO NOT want this file in source directory,
|
310
|
+
# but rather in intermediate directory
|
311
|
+
tmp_source_dir = "#{@workdir}/out/lambdas/tmp/#{name}"
|
312
|
+
FileUtils.rmtree(File.dirname(tmp_source_dir)) if File.exist? tmp_source_dir
|
313
|
+
FileUtils.mkpath(File.dirname(tmp_source_dir))
|
314
|
+
FileUtils.copy_entry(lambda_source_dir, tmp_source_dir)
|
315
|
+
lambda_source_dir = tmp_source_dir
|
316
|
+
|
317
|
+
# Lambda function source code allows pre-processing (e.g. install code dependencies)
|
318
|
+
unless lambda_config['package_cmd'].nil?
|
319
|
+
puts "Following code will be executed to generate lambda function #{name}:\n\n#{lambda_config['package_cmd']}\n\n"
|
320
|
+
|
321
|
+
if @confirm_code_execution
|
322
|
+
exit -7 unless HighLine.agree('Proceed (y/n)?')
|
323
|
+
end
|
324
|
+
|
325
|
+
package_cmd = "cd #{lambda_source_dir} && #{lambda_config['package_cmd']}"
|
326
|
+
puts 'Processing package command...'
|
327
|
+
package_result = system(package_cmd)
|
328
|
+
unless package_result
|
329
|
+
puts "Error packaging lambda function, following command failed\n\n#{package_cmd}\n\n"
|
330
|
+
exit -4
|
331
|
+
end
|
317
332
|
end
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
zip_generator.write
|
333
|
+
File.delete full_destination_path if File.exist? full_destination_path
|
334
|
+
zip_generator = Cfhighlander::Util::ZipFileGenerator.new(lambda_source_dir, full_destination_path)
|
335
|
+
zip_generator.write
|
322
336
|
|
337
|
+
end
|
323
338
|
end
|
324
339
|
# add version information to avoid same package ever deployed 2 times
|
325
340
|
Zip::File.open(full_destination_path) do |zipfile|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cfhighlander
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.0.alpha.
|
4
|
+
version: 0.4.0.alpha.1531985380
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nikola Tosic
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-07-
|
12
|
+
date: 2018-07-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: highline
|