-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCapfile
80 lines (64 loc) · 2.15 KB
/
Capfile
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
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
77
78
79
80
$:.unshift(File.dirname(__FILE__) + '/lib')
require 'overcast/data_provider'
require 'overcast/configuration'
groups.each { |group|
next unless role_servers(group.to_sym).compact.length > 0
role(group.to_sym) { role_servers(group.to_sym).compact }
}
require 'yaml'
default_run_options[:pty] = true
ssh_options[:user] = 'root'
ssh_options[:forward_agent] = true
ssh_options[:identify_file] = File.dirname(__FILE__) + '/keys'
set :dataroot, "/data/ops"
set :chefroot, "/data/ops/current/chef"
set :repository, "[email protected]:davidx/overcast.git"
set :timestamp, Time.now.strftime("%s")
set :release_path, "#{dataroot}/releases/#{timestamp}"
def emerge(packages=[])
run "emerge #{packages.join(" ")}"
end
def gem_install(gems=[])
run "gem install #{gems.join(' ')} --no-ri --no-rdoc"
end
def run_commands(commands)
commands.each { |c| "echo [command:][#{c}] && echo [result:][#{`#{c}`}]" }.join(" && ")
end
namespace :overcast do
task :bootstrap do
run_commands bootstrap_commands
emerge bootstrap_packages
gem_install bootstrap_gems
strict_host_key_prehack
end
task :strict_host_key_prehack do
# initial alter to allow git repo pull after which ssh_config is rendered from recipe
run "su - -c \"echo 'StrictHostKeyChecking no' >> /etc/ssh/ssh_config\" "
end
task :deploy do
cmd = ["mkdir -p #{dataroot}/releases"]
cmd << "cd #{dataroot} && git clone #{repository} #{release_path}"
cmd << "rm -f #{dataroot}/current"
cmd << "ln -sf #{release_path} #{dataroot}/current"
run cmd.join(" && ")
end
task :runsolo do
update
solo
end
task :solo do
profile = ENV.key?('PROFILE') ? ENV['PROFILE'] : 'default'
commands = ["cd #{chefroot}"]
commands << "gem install bundler --no-ri --no-rdoc && bundle install"
commands << "rake chef:runsolo PROFILE=#{profile}"
run_commands commands
end
task :update do
git_command = ENV['branch'] ? "git checkout #{ENV['branch']} && git pull" : "git pull"
run "cd #{chefroot} && #{git_command}"
end
task :grow do
profile = ENV.key?('PROFILE') ? ENV['PROFILE'] : 'default'
system "ruby bin/grow.rb --profile=#{profile}"
end
end