Class: Billy::Commands::Walk

Inherits:
Command
  • Object
show all
Defined in:
lib/billy/commands/walk.rb

Instance Method Summary collapse

Methods inherited from Command

instance, #name, register_self!

Instance Method Details

#prepare_capistrano(destination) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/billy/commands/walk.rb', line 39

def prepare_capistrano( destination )
  
  cap = Capistrano::Configuration.new
  cap.load "standard"
  cap.load "deploy"
  cap.trigger( :load )
  config = Billy::Config.instance
  
  if config.deploy_to.nil?
    Billy::Util::UI.err "Billy doesn't know remote deploy path. Please provide it in config under deploy_to key."
    exit 1
  end
  cap.set :deploy_to, File.join( config.deploy_to, destination )
  cap.set :normalize_asset_timestamps, false
  
  reject_keys = [ :deploy_to, :server ]
  
  {
    :scm => :git,
    :use_sudo => false,
    :deploy_via => :remote_cache,
    :application => destination
  }.merge( config.storage.reject{ |k, v| reject_keys.include?( k.to_sym ) } ).each_pair do |k, v|
    cap.set k, v
  end
  
  Billy::Util::Scm.configure!( cap, config )
  
  cap.server config.server, :app, :web, :db, :primary => true
  
  cap.namespace :deploy do
    cap.task :start, :roles => :app do; end
    cap.task :stop, :roles => :app do; end
    cap.task :restart, :roles => :app do; end
  end
  
  cap
end

#proceed!(arguments = nil) ⇒ Object



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
# File 'lib/billy/commands/walk.rb', line 8

def proceed!( arguments = nil )
  
  if !Billy::Config.load
    Billy::Util::UI.inform "Billy config could not be found. Say Billy hello."
    exit 1
  end
  
  destination = ( arguments.shift rescue nil ) || Billy::Config.instance.destination
  
  if destination.nil?
    Billy::Util::UI.err "Billy doesn't know where to walk."
    Billy::Util::UI.err "You have to provide deploy folder, e.g.: billy walk my_super_project."
    exit 1
  end
  
  begin
    cap = prepare_capistrano( destination )
    %w(deploy:setup deploy).each do |command|
      cap.find_and_execute_task(command, :before => :start, :after => :finish)
    end
    cap.trigger( :exit )
    Billy::Util::UI.succ 'Billy has successfully deployed project!'
    Billy::Util::UI.succ "Check http://#{Billy::Config.instance.server}/#{cap.application}/"
  rescue Exception => e
    Billy::Util::UI.err "Billy could not complete task: #{e.message}"
    exit 1
  end
  
  Billy::Util::UI.succ "All done! Billy is a clever boy!"
end