class DeployS3::Main

Public Class Methods

new(options) click to toggle source
# File lib/deploy_s3/main.rb, line 5
def initialize(options)
  config_path = options[:config_file] || "./.deploy"
  @config = options[:config] || YAML::load_file(config_path)

  raise "Missing s3: option in .deploy file" unless @config['s3']

  @path = @config['s3'].split("/")
  @bucket = @path.shift
  @options = options
end

Public Instance Methods

commit_count() click to toggle source
# File lib/deploy_s3/main.rb, line 81
def commit_count
  diff.split("\n").size
end
connection() click to toggle source
# File lib/deploy_s3/main.rb, line 39
def connection
  @_connection ||= Fog::Storage.new(:provider => 'AWS')
end
diff() click to toggle source
# File lib/deploy_s3/main.rb, line 68
def diff
  execute "git log --pretty=format:'    %h %<(20)%an %ar\t   %s' -10 #{remote_sha}..#{local_sha}"
end
environment() click to toggle source
# File lib/deploy_s3/main.rb, line 16
def environment
  @options[:environment]
end
filename() click to toggle source
# File lib/deploy_s3/main.rb, line 51
def filename
  [environment, 'sha'].join('.')
end
key() click to toggle source
# File lib/deploy_s3/main.rb, line 55
def key
  [@path, filename].join("/")
end
local_sha() click to toggle source
# File lib/deploy_s3/main.rb, line 63
def local_sha
  rev = @options[:rev] || @config[:branch] || 'head'
  execute("git rev-parse --verify #{rev}").chomp
end
older_local_sha() click to toggle source
# File lib/deploy_s3/main.rb, line 76
def older_local_sha
  return false unless remote_sha
  execute("git merge-base --is-ancestor #{local_sha} #{remote_sha}") && $?.exitstatus == 0
end
remote_sha() click to toggle source
# File lib/deploy_s3/main.rb, line 43
def remote_sha
  return @_remote_sha if @_remote_sha

  directory = connection.directories.get(@bucket)
  file = directory.files.get(key)
  @_remote_sha = file.body if file
end
reverse_diff() click to toggle source
# File lib/deploy_s3/main.rb, line 72
def reverse_diff
  execute "git log --pretty=format:'    %h %<(20)%an %ar\t   %s' -10 #{local_sha}..#{remote_sha}"
end
run!() click to toggle source
# File lib/deploy_s3/main.rb, line 27
def run!
  if @config['before_hook']
    `#{@config['before_hook']}`
  end

  save_sha

  if @config['after_hook']
    `#{@config['after_hook']}`
  end
end
save_sha() click to toggle source
# File lib/deploy_s3/main.rb, line 20
def save_sha
  directory = connection.directories.get(@bucket)
  file = directory.files.create(:key => key,
                                :body => local_sha)
  @_remote_sha = nil
end
up_to_date() click to toggle source
# File lib/deploy_s3/main.rb, line 59
def up_to_date
  local_sha == remote_sha
end

Protected Instance Methods

execute(cmd) click to toggle source
# File lib/deploy_s3/main.rb, line 87
def execute(cmd)
  `#{cmd}`
end