Class: Awestruct::Deploy::S3Deploy
- Defined in:
- lib/awestruct/deploy/s3_deploy.rb
Constant Summary
Constants inherited from Base
Instance Method Summary collapse
- #add_header(key, value) ⇒ Object
-
#initialize(site_config, deploy_config) ⇒ S3Deploy
constructor
A new instance of S3Deploy.
- #publish_site ⇒ Object
- #s3_sync(site_path, bucket, exclude = nil, include = nil, headersCmd = nil) ⇒ Object
Methods inherited from Base
#compress_site, #existing_changes, #gzip_file, #gzip_site, #init_scm, #is_gzipped, #run
Constructor Details
#initialize(site_config, deploy_config) ⇒ S3Deploy
Returns a new instance of S3Deploy.
6 7 8 9 10 |
# File 'lib/awestruct/deploy/s3_deploy.rb', line 6 def initialize( site_config, deploy_config ) super @bucket = deploy_config['bucket'] @metadata = deploy_config['metadata'] end |
Instance Method Details
#add_header(key, value) ⇒ Object
44 45 46 |
# File 'lib/awestruct/deploy/s3_deploy.rb', line 44 def add_header(key, value) " --add-header '#{key}:#{value}'" end |
#publish_site ⇒ Object
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 |
# File 'lib/awestruct/deploy/s3_deploy.rb', line 12 def publish_site $LOG.info "Syncing #{@site_path} to bucket #{@bucket}" if $LOG.info? if @metadata and !@metadata.empty? @metadata.each do |fileType, headers| # Build the add-header command because the s3cmd-dsl gem doesn't support multi-headers headerCmd = "" if headers && !headers.empty? headers.each do |key, value| headerCmd << add_header(key, value) end end # If gzip is enabled, add 'Content-Encoding: gzip' on js, css and html files if @gzip and ['js', 'css', 'html'].include? fileType headerCmd << add_header("Content-Encoding", "gzip") end # Sync files of current type with specified headers s3_sync(@site_path, @bucket, "*", "*.#{fileType}", headerCmd) end end # If gzip is enabled, add 'Content-Encoding: gzip' on not processed js, css and html files if @gzip remainingFileType = ['js', 'css', 'html'].find_all { |fileType| !@metadata.keys.include? fileType } remainingFileType.each do |fileType| headerCmd = add_header("Content-Encoding", "gzip") s3_sync(@site_path, @bucket, "*", "*.#{fileType}", headerCmd) end end # Finally, sync others files s3_sync(@site_path, @bucket) $LOG.info "DONE" if $LOG.info? end |
#s3_sync(site_path, bucket, exclude = nil, include = nil, headersCmd = nil) ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/awestruct/deploy/s3_deploy.rb', line 48 def s3_sync(site_path, bucket, exclude = nil, include = nil, headersCmd = nil) cmd="s3cmd sync '#{site_path}' '#{bucket}'" cmd << " --exclude '#{exclude}'" if exclude cmd << " --include '#{include}'" if include cmd << " #{headersCmd}" if headersCmd $LOG.info "Execute #{cmd}" `#{cmd}` end |