Class: DeployS3::Main

Inherits:
Object
  • Object
show all
Defined in:
lib/deploy_s3/main.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Main

Returns a new instance of Main.



5
6
7
8
9
10
11
12
13
14
# 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

Instance Method Details

#commit_countObject



81
82
83
# File 'lib/deploy_s3/main.rb', line 81

def commit_count
  diff.split("\n").size
end

#connectionObject



39
40
41
# File 'lib/deploy_s3/main.rb', line 39

def connection
  @_connection ||= Fog::Storage.new(:provider => 'AWS')
end

#diffObject



68
69
70
# 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

#environmentObject



16
17
18
# File 'lib/deploy_s3/main.rb', line 16

def environment
  @options[:environment]
end

#filenameObject



51
52
53
# File 'lib/deploy_s3/main.rb', line 51

def filename
  [environment, 'sha'].join('.')
end

#keyObject



55
56
57
# File 'lib/deploy_s3/main.rb', line 55

def key
  [@path, filename].join("/")
end

#local_shaObject



63
64
65
66
# 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_shaObject



76
77
78
79
# 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_shaObject



43
44
45
46
47
48
49
# 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_diffObject



72
73
74
# 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!Object



27
28
29
30
31
32
33
34
35
36
37
# 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_shaObject



20
21
22
23
24
25
# 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_dateObject



59
60
61
# File 'lib/deploy_s3/main.rb', line 59

def up_to_date
  local_sha == remote_sha
end