/
application.rb
84 lines (70 loc) · 2.26 KB
/
application.rb
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
81
82
83
84
include_recipe "joy_of_cooking::daemontools"
include_recipe "joy_of_cooking::mysql"
include_recipe "joy_of_cooking::sqlite"
app_user = "mkocher"
# nokogiri docs recomend installing from source, but aren't
{
"libxml2" => "2.6.26-2.1.2.8.el5_5.1",
"libxml2-devel" => "2.6.26-2.1.2.8.el5_5.1",
"libxslt" => "1.1.17-2",
"libxslt-devel" => "1.1.17-2.el5_2.2",
}.each do |package_name, version_string|
['i386', 'x86_64'].each do |arch_string|
package package_name do
action :install
version "#{version_string}.#{arch_string}"
end
end
end
execute "trust github" do
command "mkdir -p ~/.ssh/ && echo 'github.com,207.97.227.239 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==' > ~/.ssh/known_hosts"
user app_user
end
execute "user owns app dir" do
command "chown -R #{app_user} #{ENV['APP_DIR']}"
end
execute "git clone" do
command "git clone git://github.com/mkocher/chef_deploy.git src"
cwd ENV['APP_DIR']
not_if { File.exists?("#{ENV['APP_DIR']}/src/.git/")}
user app_user
end
execute "checkout HEAD" do
command "git reset HEAD --hard && git pull"
cwd "#{ENV['APP_DIR']}/src"
user app_user
end
execute "bundle" do
command "bundle"
user app_user
cwd "#{ENV['APP_DIR']}/src"
end
execute "create db" do
command "bundle exec rake db:create"
user app_user
environment 'RACK_ENV' => 'staging'
cwd "#{ENV['APP_DIR']}/src"
end
execute "rake db:migrate" do
command "bundle exec rake db:migrate"
user app_user
environment 'RACK_ENV' => 'staging'
cwd "#{ENV['APP_DIR']}/src"
end
execute "create daemontools directory" do
command "mkdir -p /service/unicorn"
end
file "/service/unicorn/run" do
content %{#!/bin/bash
cd /var/staging/foo/src
rvm_path=/home/mkocher/.rvm/
export RAILS_ENV=staging
source /home/mkocher/.rvm/scripts/rvm
rvm use ruby-1.8.7-p299@captest
exec /command/setuidgid mkocher rackup -p 3000
}
mode "0755"
end
execute "restart unicorn" do
command "svc -k /service/unicorn"
end