Class: Cfhighlander::Publisher::ComponentPublisher
- Inherits:
-
Object
- Object
- Cfhighlander::Publisher::ComponentPublisher
- Defined in:
- lib/cfhighlander.publisher.rb
Instance Method Summary collapse
- #getLaunchStackUrl ⇒ Object
- #getTemplateUrl ⇒ Object
-
#initialize(component, cleanup, template_format) ⇒ ComponentPublisher
constructor
A new instance of ComponentPublisher.
- #publishComponent ⇒ Object
- #publishFiles(file_list) ⇒ Object
Constructor Details
#initialize(component, cleanup, template_format) ⇒ ComponentPublisher
Returns a new instance of ComponentPublisher.
10 11 12 13 14 |
# File 'lib/cfhighlander.publisher.rb', line 10 def initialize(component, cleanup, template_format) @component = component @cleanup_destination = cleanup @template_format = template_format end |
Instance Method Details
#getLaunchStackUrl ⇒ Object
52 53 54 55 56 57 |
# File 'lib/cfhighlander.publisher.rb', line 52 def getLaunchStackUrl template_url = getTemplateUrl region = s3_bucket_region(@component.highlander_dsl.distribution_bucket) return "https://console.aws.amazon.com/cloudformation/home?region=#{region}#/stacks/create/review?filter=active&templateURL=" + "#{CGI::escape(template_url)}&stackName=#{@component.name}" end |
#getTemplateUrl ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/cfhighlander.publisher.rb', line 44 def getTemplateUrl template_url = "https://#{@component.highlander_dsl.distribution_bucket}.s3.amazonaws.com/" template_url += @component.highlander_dsl.distribution_prefix + "/" template_url += @component.highlander_dsl.version template_url += "/#{@component.name}.compiled.#{@template_format}" return template_url end |
#publishComponent ⇒ Object
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 |
# File 'lib/cfhighlander.publisher.rb', line 16 def publishComponent bucket = @component.highlander_dsl.distribution_bucket prefix = @component.highlander_dsl.distribution_prefix version = @component.highlander_dsl.version s3_create_bucket_if_not_exists(bucket) s3 = Aws::S3::Client.new({ region: s3_bucket_region(bucket) }) existing_objects = s3.list_objects_v2({bucket: bucket, prefix: "#{prefix}/#{@component.name}/#{version}"}) existing_objects.contents.each do |s3obj| print "Deleting previously published #{s3obj.key} ..." s3.delete_object(bucket: bucket, key: s3obj.key) print " [OK] \n" end if @cleanup_destination @component.component_files.each do |file_path| File.open(file_path, 'rb') do |file| file_path = file_path.gsub(@component.component_dir, '')[1..-1] s3_key = "#{prefix}/#{@component.name}/#{version}/#{file_path}" print "Publish component file #{file_path} to s3://#{bucket}/#{s3_key} ... " s3.put_object(bucket: bucket, key: s3_key, body: file) print " [OK] \n" end end end |
#publishFiles(file_list) ⇒ Object
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 |
# File 'lib/cfhighlander.publisher.rb', line 59 def publishFiles(file_list) bucket = @component.highlander_dsl.distribution_bucket prefix = @component.highlander_dsl.distribution_prefix version = @component.highlander_dsl.version s3_create_bucket_if_not_exists(bucket) s3 = Aws::S3::Client.new({ region: s3_bucket_region(bucket) }) s3.list_objects_v2(bucket: bucket, prefix: "#{prefix}/#{version}").contents.each do |s3obj| print "\nDeleting previously published #{s3obj.key} ..." s3.delete_object(bucket: bucket, key: s3obj.key) print ' [OK]' end if @cleanup_destination file_list.each do |file| file_name = File.basename file s3_key = "#{prefix}/#{version}/#{file_name}" print "\nPublishing #{file} to s3://#{bucket}/#{s3_key} ..." s3.put_object({ body: File.read(file), bucket: bucket, key: s3_key }) print ' [OK] ' end print "\n" @component.highlander_dsl.publish_artifacts.each do |artifact| s3_key = artifact[:key].nil? ? "#{prefix}/#{version}/#{artifact[:file]}" : artifact[:key] print "\nPublishing artifact: #{artifact[:file]} to s3://#{bucket}/#{s3_key} ..." s3.put_object({ body: File.read(artifact[:file]), bucket: bucket, key: s3_key }) print ' [OK] ' end end |