Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: fea96051bf
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 51 lines (40 sloc) 1.272 kb
1 2 3 4 5 6 7 8 9 10 11 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 43 44 45 46 47 48 49 50
require 'fileutils'
require 'tmpdir'

class Deployer

  def self.deploy_to_bucket_from_commit( *args )
    new.deploy_to_bucket_from_commit( *args )
  end
  
  def deploy_to_bucket_from_commit( bucket_name, commit_sha )
    using_a_temporary_dir do |temp_dir|
      extract_commit_into_dir( commit_sha, temp_dir )
      prep_gems_in_dir( temp_dir )
      Dir.chdir temp_dir do
        generate_site
        deploy_site_to_bucket( bucket_name )
      end
    end
  end

  private

  def using_a_temporary_dir &block
    Dir.mktmpdir("octopress_deployment",&block)
    #temp_dir = Dir.mktmpdir
    #puts "temp dir is #{temp_dir}"
    #yield temp_dir
  end

  def extract_commit_into_dir( commit_sha, dir )
    `git archive --format=tar #{commit_sha} | tar -x -C #{dir}`
    raise 'git archive failed' unless $?.success?
  end

  def prep_gems_in_dir( dir )
    FileUtils.cp_r( '.bundle', dir )
    FileUtils.cp_r( 'vendor', dir )
  end

  def generate_site
    success = system 'bundle exec rake generate'
    raise 'rake generate failed' unless success
  end

  def deploy_site_to_bucket( bucket_name )
    success = system "s3cmd sync --acl-public --no-delete-removed --reduced-redundancy public/* s3://#{bucket_name}/"
    raise 'deploy failed' unless success
  end

end
Something went wrong with that request. Please try again.