class Awestruct::Deploy::S3Deploy

Public Class Methods

new( site_config, deploy_config ) click to toggle source
Calls superclass method Awestruct::Deploy::Base::new
# 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

Public Instance Methods

add_header(key, value) click to toggle source
# File lib/awestruct/deploy/s3_deploy.rb, line 44
def add_header(key, value)
  " --add-header '#{key}:#{value}'"
end
publish_site() click to toggle source
# 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) click to toggle source
# 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