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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/cfhighlander.compiler.rb +77 -62
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f23bce250ee476c3abf51e8fb906fad9c8bc6879c44407a60c3743e74958f861
4
- data.tar.gz: 697281f867a0551f8275fd3f679d9b141d988cda2f35b5411df05ad0f8a1e035
3
+ metadata.gz: 9b1b127f5a658380bc3c38b939b0812378c87cc871ff4bba6842173dcf7bb977
4
+ data.tar.gz: 64d4ecf0310154bf373ee27b0b702208c566710b02e9a7c30dbdcce5bb56927d
5
5
  SHA512:
6
- metadata.gz: 74aaa9b9514d93e33574cd2e2c1f1ca7bcbf334e0c7164916f8c73120f84c1fc5df86492b1b48c583cd94406415985aaae2d808effd6b62415284510467e52f8
7
- data.tar.gz: 77f9f2780801de2f721c9699d9aa94d6d1d39612ebda33ba5dfa876c3459e778d83f866196ce133997733b2d173812630a8dec93c474de58867b9cbae4b0c9dd
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
- if lambda_config['code'].include? 'http'
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
- puts "Downloading file #{lambda_config['code']} ..."
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 "Download complete, caching in #{cached_location}"
270
+ puts "INFO lambda #{name} source cached to #{cached_location}"
270
271
  cached_downloads[lambda_config['code']] = cached_location
271
- end
272
- else
273
- # zip local code
274
- component = @component
275
- component_dir = component.template.template_location
276
- full_path = "#{component_dir}/lambdas/#{lambda_config['code']}"
277
-
278
- until (File.exist? full_path or component_dir.nil?)
279
- parent_exists = (not component.extended_component.nil?)
280
- component = component.extended_component if parent_exists
281
- component_dir = component.template.template_location if parent_exists
282
- full_path = "#{component_dir}/lambdas/#{lambda_config['code']}" if parent_exists
283
- component_dir = nil unless parent_exists
284
- end
285
- if component_dir.nil?
286
- STDERR.puts "ERROR: Could not find source code directory for lambda function #{name} in component #{@component.name}"
287
- exit -9
288
- end
289
-
290
- # lambda source can be either path to file or directory within that file
291
- # optionally, lambda source code
292
- lambda_source_dir = File.dirname(full_path)
293
- lambda_source_dir = full_path if Pathname.new(full_path).directory?
294
-
295
- # executing package command can generate files. We DO NOT want this file in source directory,
296
- # but rather in intermediate directory
297
- tmp_source_dir = "#{@workdir}/out/lambdas/tmp/#{name}"
298
- FileUtils.rmtree(File.dirname(tmp_source_dir)) if File.exist? tmp_source_dir
299
- FileUtils.mkpath(File.dirname(tmp_source_dir))
300
- FileUtils.copy_entry(lambda_source_dir, tmp_source_dir)
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
- package_cmd = "cd #{lambda_source_dir} && #{lambda_config['package_cmd']}"
312
- puts 'Processing package command...'
313
- package_result = system(package_cmd)
314
- unless package_result
315
- puts "Error packaging lambda function, following command failed\n\n#{package_cmd}\n\n"
316
- exit -4
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
- end
319
- File.delete full_destination_path if File.exist? full_destination_path
320
- zip_generator = Cfhighlander::Util::ZipFileGenerator.new(lambda_source_dir, full_destination_path)
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.1531791475
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-17 00:00:00.000000000 Z
12
+ date: 2018-07-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: highline