Class: Wakame::Actor::Deploy

Inherits:
Object
  • Object
show all
Includes:
Wakame::Actor
Defined in:
lib/wakame/actor/deploy.rb

Constant Summary

Constants included from Wakame::Actor

STATUS_CANCELED, STATUS_FAILED, STATUS_RUNNING, STATUS_SUCCESS

Instance Method Summary collapse

Methods included from Wakame::Actor

included

Instance Method Details

#checkout(ticket, repo_type, repo_uri, deploy_rev, app_root, app_name, options = {}) ⇒ Object

Download the application from repo_uri using arbitrary SCM tool.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/wakame/actor/deploy.rb', line 9

def checkout(ticket, repo_type, repo_uri, deploy_rev, app_root, app_name, options={})
  
  case repo_type
  when 's3'
    tmp_dest = checkout_s3(repo_uri, deploy_rev, options)
  when 'curl'
    tmp_dest = checkout_curl(repo_uri, deploy_rev, options)
  else
    raise "Unsupported repository type: #{repo_type}"
  end

  dest = File.expand_path(File.join(app_name, ticket), app_root)
  
  begin
    FileUtils.mkpath(File.dirname(dest))
    Wakame.log.debug("FileUtils.move('#{tmp_dest}', '#{dest}')")
    FileUtils.move(tmp_dest, dest)

    FileUtils.rm_f(File.join(File.dirname(dest), 'latest'))
    FileUtils.symlink(File.basename(dest), File.join(File.dirname(dest), 'latest'))
  rescue
    FileUtils.rm_r(dest) rescue nil
  end
end

Swap the symlink “current” in /app_root/app_name to point the location as same as “latest” in the same folder.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/wakame/actor/deploy.rb', line 36

def swap_current_link(app_root, app_name)
  raise "Invalid application root path. Must be an absolute path: #{app_root}" unless app_root =~ /\A\//

  latest_lnk_path = File.join(app_root, app_name, 'latest')
  cur_lnk_path = File.join(app_root, app_name, 'current')
  raise "'latest' symlink does not exist in #{File.join(app_root, app_name)}" unless File.symlink?(latest_lnk_path)
  

  tgt = File.readlink(latest_lnk_path)
  raise "'latest' symlink may point the target in differnt folder: #{tgt}" if tgt =~ /[\/]/

  if File.symlink?(cur_lnk_path)
    FileUtils.rm_f(cur_lnk_path)
  end
  FileUtils.symlink(tgt, cur_lnk_path)
end