brightbox 0.25 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +619 -0
- data/Rakefile +23 -0
- data/bin/brightbox +291 -20
- data/brightbox-gemspec.rb +46 -0
- data/lib/brightbox/recipes.rb +21 -120
- data/lib/brightbox/recipes/callbacks.rb +48 -0
- data/lib/brightbox/recipes/configure.rb +178 -0
- data/lib/brightbox/recipes/database.rb +40 -0
- data/lib/brightbox/recipes/deploy.rb +81 -0
- data/lib/brightbox/recipes/gems.rb +30 -0
- data/lib/brightbox/recipes/helpers.rb +33 -0
- data/lib/brightbox/recipes/shared_local.rb +68 -0
- data/lib/brightbox/recipes/variables.rb +44 -0
- data/lib/brightbox/version.rb +3 -0
- metadata +23 -34
- data/bin/brightbox-apache +0 -84
- data/bin/brightbox-monit +0 -68
- data/lib/brightbox/generators/brightbox/brightbox_generator.rb +0 -26
- data/lib/brightbox/generators/brightbox/brightboxapache_generator.rb +0 -27
- data/lib/brightbox/generators/brightbox/templates/deploy.rb +0 -41
- data/lib/brightbox/generators/loader.rb +0 -40
@@ -0,0 +1,48 @@
|
|
1
|
+
# Brightbox - Easy Ruby Web Application Deployment
|
2
|
+
# Copyright (C) 2008, Neil Wilson, Brightbox Systems
|
3
|
+
#
|
4
|
+
# This file is part of the Brightbox deployment system
|
5
|
+
#
|
6
|
+
# Brightbox gem is free software: you can redistribute it and/or modify it
|
7
|
+
# under the terms of the GNU Affero General Public License as published
|
8
|
+
# by the Free Software Foundation, either version 3 of the License,
|
9
|
+
# or (at your option) any later version.
|
10
|
+
#
|
11
|
+
# This program is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
# Affero General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU Affero General
|
17
|
+
# Public License along with this program. If not, see
|
18
|
+
# <http://www.gnu.org/licenses/>.
|
19
|
+
#
|
20
|
+
# Hook tasks into the standard deployment system
|
21
|
+
|
22
|
+
after "deploy:setup",
|
23
|
+
"deploy:shared:local:setup",
|
24
|
+
"configure:logrotation",
|
25
|
+
"configure:monit",
|
26
|
+
"configure:mongrel",
|
27
|
+
"configure:apache",
|
28
|
+
"configure:nginx"
|
29
|
+
|
30
|
+
after "deploy:cold",
|
31
|
+
"deploy:monit:reload"
|
32
|
+
|
33
|
+
after "deploy:finalize_update",
|
34
|
+
"deploy:shared:local:symlink",
|
35
|
+
"gems:install"
|
36
|
+
|
37
|
+
after "deploy:update",
|
38
|
+
"deploy:cleanup"
|
39
|
+
|
40
|
+
before "deploy:migrate",
|
41
|
+
"db:check:config",
|
42
|
+
"db:create"
|
43
|
+
|
44
|
+
after "deploy:start",
|
45
|
+
"deploy:web:reload_if_new"
|
46
|
+
|
47
|
+
after "deploy:restart",
|
48
|
+
"deploy:web:reload_if_new"
|
@@ -0,0 +1,178 @@
|
|
1
|
+
# Brightbox - Easy Ruby Web Application Deployment
|
2
|
+
# Copyright (C) 2008, Neil Wilson, Brightbox Systems
|
3
|
+
#
|
4
|
+
# This file is part of the Brightbox deployment system
|
5
|
+
#
|
6
|
+
# Brightbox gem is free software: you can redistribute it and/or modify it
|
7
|
+
# under the terms of the GNU Affero General Public License as published
|
8
|
+
# by the Free Software Foundation, either version 3 of the License,
|
9
|
+
# or (at your option) any later version.
|
10
|
+
#
|
11
|
+
# This program is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
# Affero General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU Affero General
|
17
|
+
# Public License along with this program. If not, see
|
18
|
+
# <http://www.gnu.org/licenses/>.
|
19
|
+
#
|
20
|
+
|
21
|
+
def monit_setup
|
22
|
+
"/usr/bin/railsapp-monit"
|
23
|
+
end
|
24
|
+
depend :remote, :command, monit_setup
|
25
|
+
|
26
|
+
def apache_setup
|
27
|
+
"/usr/bin/railsapp-apache"
|
28
|
+
end
|
29
|
+
depend :remote, :command, apache_setup
|
30
|
+
|
31
|
+
def nginx_setup
|
32
|
+
"/usr/bin/railsapp-nginx"
|
33
|
+
end
|
34
|
+
depend :remote, :command, nginx_setup
|
35
|
+
|
36
|
+
def mongrel_setup
|
37
|
+
"/usr/bin/railsapp-mongrel"
|
38
|
+
end
|
39
|
+
depend :remote, :command, mongrel_setup
|
40
|
+
|
41
|
+
def logrotate_setup
|
42
|
+
"/usr/bin/railsapp-logrotate"
|
43
|
+
end
|
44
|
+
depend :remote, :command, logrotate_setup
|
45
|
+
|
46
|
+
def mysql_setup
|
47
|
+
"/usr/bin/railsapp-check"
|
48
|
+
end
|
49
|
+
depend :remote, :command, mysql_setup
|
50
|
+
|
51
|
+
namespace :configure do
|
52
|
+
|
53
|
+
[:nginx, :apache].each do |webserver|
|
54
|
+
desc %Q{
|
55
|
+
[internal]Create #{webserver.to_s} config. Creates a load balancing virtual host \
|
56
|
+
configuration based upon your specified settings
|
57
|
+
|
58
|
+
:application Name of the application
|
59
|
+
:domain Domain name which will point to the application
|
60
|
+
:domain_aliases Comma separated list of aliased for the main domain
|
61
|
+
:mongrel_host Name of application layer host (default localhost)
|
62
|
+
:mongrel_port Start port of the mongrel cluster (default 8000)
|
63
|
+
:mongrel_servers Number of servers on app host (default 2)
|
64
|
+
:ssl_certificate Create SSL configuration with certificate
|
65
|
+
:ssl_key Name of private key to use with certificate
|
66
|
+
|
67
|
+
}
|
68
|
+
task webserver, :roles => :web, :except => {:no_release => true} do
|
69
|
+
sudo on_one_line( <<-END
|
70
|
+
#{send(webserver.to_s + "_setup")}
|
71
|
+
-n #{application}
|
72
|
+
-d #{domain}
|
73
|
+
#{'-a '+domain_aliases if domain_aliases}
|
74
|
+
-w #{File.join(current_path, 'public')}
|
75
|
+
-h #{mongrel_host}
|
76
|
+
-p #{mongrel_port}
|
77
|
+
-s #{mongrel_servers}
|
78
|
+
#{'-c '+ssl_certificate if ssl_certificate}
|
79
|
+
#{'-k '+ssl_key if ssl_key}
|
80
|
+
END
|
81
|
+
)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
desc %Q{
|
86
|
+
[internal]Create Mongrel config. Creates a set of mongrels running \
|
87
|
+
on the specified ports of the application server(s).
|
88
|
+
|
89
|
+
:application Name of the application
|
90
|
+
:mongrel_host Name of application layer host (default localhost)
|
91
|
+
:mongrel_port Start port of the mongrel cluster (default 8000)
|
92
|
+
:mongrel_servers Number of servers on app host (default 2)
|
93
|
+
:mongrel_pid_file The name of the file containing the mongrel PID
|
94
|
+
|
95
|
+
}
|
96
|
+
task :mongrel, :roles => :app, :except => {:no_release => true} do
|
97
|
+
sudo on_one_line( <<-END
|
98
|
+
#{mongrel_setup}
|
99
|
+
-n #{application}
|
100
|
+
-r #{current_path}
|
101
|
+
-p #{mongrel_port}
|
102
|
+
-s #{mongrel_servers}
|
103
|
+
-h #{mongrel_host}
|
104
|
+
-C #{mongrel_config_file}
|
105
|
+
-P #{mongrel_pid_file}
|
106
|
+
END
|
107
|
+
)
|
108
|
+
end
|
109
|
+
|
110
|
+
desc %Q{
|
111
|
+
[internal]Create Monit config. Build a monit configuraton file \
|
112
|
+
to look after this application
|
113
|
+
|
114
|
+
:application Name of the application
|
115
|
+
:mongrel_host Name of application layer host (default localhost)
|
116
|
+
:mongrel_port Start port of the mongrel cluster (default 8000)
|
117
|
+
:mongrel_servers Number of servers on app host (default 2)
|
118
|
+
|
119
|
+
}
|
120
|
+
task :monit, :except => {:no_release => true} do
|
121
|
+
sudo on_one_line( <<-END
|
122
|
+
#{monit_setup}
|
123
|
+
-n #{application}
|
124
|
+
-u #{user}
|
125
|
+
-r #{current_path}
|
126
|
+
-h #{mongrel_host}
|
127
|
+
-p #{mongrel_port}
|
128
|
+
-s #{mongrel_servers}
|
129
|
+
-C #{mongrel_config_file}
|
130
|
+
-P #{mongrel_pid_file}
|
131
|
+
END
|
132
|
+
)
|
133
|
+
end
|
134
|
+
|
135
|
+
desc %Q{
|
136
|
+
[internal]Create logrotation config. Build a logrotate configuraton file \
|
137
|
+
so that logrotate will look after the log files.
|
138
|
+
|
139
|
+
:application Name of the application
|
140
|
+
:log_max_size Rotate when log reaches this size
|
141
|
+
:log_keep Number of compressed logs to keep
|
142
|
+
|
143
|
+
}
|
144
|
+
task :logrotation, :roles => :app, :except => {:no_release => true} do
|
145
|
+
sudo on_one_line( <<-END
|
146
|
+
#{logrotate_setup}
|
147
|
+
-n #{application}
|
148
|
+
-l #{log_dir}
|
149
|
+
-s #{log_max_size}
|
150
|
+
-k #{log_keep}
|
151
|
+
END
|
152
|
+
)
|
153
|
+
end
|
154
|
+
|
155
|
+
desc %Q{
|
156
|
+
[internal]Run the check command if this application hasn't been
|
157
|
+
deployed yet
|
158
|
+
}
|
159
|
+
task :check, :except => {:no_release => true} do
|
160
|
+
begin
|
161
|
+
deploy.check unless releases.length > 0
|
162
|
+
rescue
|
163
|
+
puts "Error detected. Have you run 'cap deploy:setup'?"
|
164
|
+
raise
|
165
|
+
ensure
|
166
|
+
reset! :releases
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
desc %Q{
|
171
|
+
[internal]Check the current database.yml file and update the
|
172
|
+
details from the .my.cnf file on the server if it exists.
|
173
|
+
}
|
174
|
+
task :mysql, :roles => :db, :only => {:primary => true} do
|
175
|
+
try_sudo "#{mysql_setup} -n #{application} #{latest_release}/config/database.yml"
|
176
|
+
end
|
177
|
+
|
178
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# Brightbox - Easy Ruby Web Application Deployment
|
2
|
+
# Copyright (C) 2008, Neil Wilson, Brightbox Systems
|
3
|
+
#
|
4
|
+
# This file is part of the Brightbox deployment system
|
5
|
+
#
|
6
|
+
# Brightbox gem is free software: you can redistribute it and/or modify it
|
7
|
+
# under the terms of the GNU Affero General Public License as published
|
8
|
+
# by the Free Software Foundation, either version 3 of the License,
|
9
|
+
# or (at your option) any later version.
|
10
|
+
#
|
11
|
+
# This program is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
# Affero General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU Affero General
|
17
|
+
# Public License along with this program. If not, see
|
18
|
+
# <http://www.gnu.org/licenses/>.
|
19
|
+
#
|
20
|
+
|
21
|
+
namespace :db do
|
22
|
+
|
23
|
+
desc %Q{
|
24
|
+
[internal]Create the database if it doesn't exist
|
25
|
+
}
|
26
|
+
task :create, :roles => :db, :only => { :primary => true } do
|
27
|
+
run rake_task("db:create")
|
28
|
+
end
|
29
|
+
|
30
|
+
namespace :check do
|
31
|
+
desc %Q{
|
32
|
+
[internal]Check the database configuration to make sure that
|
33
|
+
it conforms to the Brightbox standard
|
34
|
+
}
|
35
|
+
task :config, :roles => :db, :only => {:primary => true} do
|
36
|
+
run rake_task("db:check:config")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# Brightbox - Easy Ruby Web Application Deployment
|
2
|
+
# Copyright (C) 2008, Neil Wilson, Brightbox Systems
|
3
|
+
#
|
4
|
+
# This file is part of the Brightbox deployment system
|
5
|
+
#
|
6
|
+
# Brightbox gem is free software: you can redistribute it and/or modify it
|
7
|
+
# under the terms of the GNU Affero General Public License as published
|
8
|
+
# by the Free Software Foundation, either version 3 of the License,
|
9
|
+
# or (at your option) any later version.
|
10
|
+
#
|
11
|
+
# This program is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
# Affero General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU Affero General
|
17
|
+
# Public License along with this program. If not, see
|
18
|
+
# <http://www.gnu.org/licenses/>.
|
19
|
+
#
|
20
|
+
# Override standard tasks that don't do what we want
|
21
|
+
|
22
|
+
namespace :deploy do
|
23
|
+
|
24
|
+
def mongrel_command
|
25
|
+
"/usr/bin/mongrel_rails"
|
26
|
+
end
|
27
|
+
depend :remote, :command, mongrel_command
|
28
|
+
|
29
|
+
def monit_command
|
30
|
+
"/usr/sbin/monit"
|
31
|
+
end
|
32
|
+
depend :remote, :command, monit_command
|
33
|
+
|
34
|
+
#Override start, stop and restart so that they use Monit to restart the
|
35
|
+
#application servers
|
36
|
+
%W(start stop restart status).each do |event|
|
37
|
+
desc "Ask mongrel to #{event} your application."
|
38
|
+
task event, :roles => :app, :except => {:no_release => true } do
|
39
|
+
try_sudo "#{mongrel_command} cluster::#{event} -C #{mongrel_config_file} --clean"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
namespace :web do
|
44
|
+
|
45
|
+
desc %Q{
|
46
|
+
Reload the apache webserver
|
47
|
+
}
|
48
|
+
task :reload, :roles => :web, :except => {:no_release => true } do
|
49
|
+
sudo "/usr/sbin/invoke-rc.d apache2 reload"
|
50
|
+
end
|
51
|
+
|
52
|
+
desc %Q{
|
53
|
+
[internal]reload web server if first release
|
54
|
+
}
|
55
|
+
task :reload_if_new, :roles => :web, :except => {:no_release => true} do
|
56
|
+
reset! :releases
|
57
|
+
reload if releases.length == 1
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
namespace :monit do
|
63
|
+
|
64
|
+
desc %Q{
|
65
|
+
Reload monit
|
66
|
+
}
|
67
|
+
task :reload do
|
68
|
+
sudo "#{monit_command} reload"
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
desc %Q{Setup the directories and deploy the initial version of the
|
74
|
+
application
|
75
|
+
}
|
76
|
+
task :initial do
|
77
|
+
setup
|
78
|
+
cold
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# Brightbox - Easy Ruby Web Application Deployment
|
2
|
+
# Copyright (C) 2008, Neil Wilson, Brightbox Systems
|
3
|
+
#
|
4
|
+
# This file is part of the Brightbox deployment system
|
5
|
+
#
|
6
|
+
# Brightbox gem is free software: you can redistribute it and/or modify it
|
7
|
+
# under the terms of the GNU Affero General Public License as published
|
8
|
+
# by the Free Software Foundation, either version 3 of the License,
|
9
|
+
# or (at your option) any later version.
|
10
|
+
#
|
11
|
+
# This program is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
# Affero General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU Affero General
|
17
|
+
# Public License along with this program. If not, see
|
18
|
+
# <http://www.gnu.org/licenses/>.
|
19
|
+
#
|
20
|
+
|
21
|
+
namespace :gems do
|
22
|
+
|
23
|
+
desc %Q{
|
24
|
+
[internal]Run the gems install task in the application.
|
25
|
+
}
|
26
|
+
task :install, :roles => :app do
|
27
|
+
sudo rake_task("gems:install")
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# Brightbox - Easy Ruby Web Application Deployment
|
2
|
+
# Copyright (C) 2008, Neil Wilson, Brightbox Systems
|
3
|
+
#
|
4
|
+
# This file is part of the Brightbox deployment system
|
5
|
+
#
|
6
|
+
# Brightbox gem is free software: you can redistribute it and/or modify it
|
7
|
+
# under the terms of the GNU Affero General Public License as published
|
8
|
+
# by the Free Software Foundation, either version 3 of the License,
|
9
|
+
# or (at your option) any later version.
|
10
|
+
#
|
11
|
+
# This program is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
# Affero General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU Affero General
|
17
|
+
# Public License along with this program. If not, see
|
18
|
+
# <http://www.gnu.org/licenses/>.
|
19
|
+
#
|
20
|
+
def rake_task(taskname)
|
21
|
+
rake = fetch(:rake, "rake")
|
22
|
+
rails_env = fetch(:rails_env, "production")
|
23
|
+
rake_env = fetch(:rake_env, "")
|
24
|
+
directory = current_release
|
25
|
+
|
26
|
+
"cd #{directory}; #{rake} RAILS_ENV=#{rails_env} #{rake_env} #{taskname}"
|
27
|
+
end
|
28
|
+
|
29
|
+
def on_one_line(cmd_list)
|
30
|
+
cmd_list.gsub!(/\n/m, ' ')
|
31
|
+
end
|
32
|
+
|
33
|
+
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# Brightbox - Easy Ruby Web Application Deployment
|
2
|
+
# Copyright (C) 2008, Neil Wilson, Brightbox Systems
|
3
|
+
#
|
4
|
+
# This file is part of the Brightbox deployment system
|
5
|
+
#
|
6
|
+
# Brightbox gem is free software: you can redistribute it and/or modify it
|
7
|
+
# under the terms of the GNU Affero General Public License as published
|
8
|
+
# by the Free Software Foundation, either version 3 of the License,
|
9
|
+
# or (at your option) any later version.
|
10
|
+
#
|
11
|
+
# This program is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
# Affero General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU Affero General
|
17
|
+
# Public License along with this program. If not, see
|
18
|
+
# <http://www.gnu.org/licenses/>.
|
19
|
+
#
|
20
|
+
# Manage the local shared area
|
21
|
+
|
22
|
+
namespace :deploy do
|
23
|
+
namespace :shared do
|
24
|
+
namespace :local do
|
25
|
+
|
26
|
+
desc %Q(
|
27
|
+
[internal] Creates shared directories. This is called by the setup
|
28
|
+
routine to create the directory structure within the shared area. It
|
29
|
+
references two arrays.
|
30
|
+
|
31
|
+
:local_shared_files - the list of files that should be shared
|
32
|
+
between releases.
|
33
|
+
:local_shared_dirs - the list of directories that should be
|
34
|
+
shared between releases.
|
35
|
+
)
|
36
|
+
task :setup, :except => {:no_release => true} do
|
37
|
+
dirs = local_shared_files.collect do |file|
|
38
|
+
File.join(shared_path, File.dirname(file))
|
39
|
+
end
|
40
|
+
dirs += local_shared_dirs.collect do |dir|
|
41
|
+
File.join(shared_path, dir)
|
42
|
+
end
|
43
|
+
try_sudo "umask 02 && mkdir -p #{dirs.join(' ')}" unless dirs.empty?
|
44
|
+
end
|
45
|
+
|
46
|
+
desc %Q{
|
47
|
+
[internal] Sets up the symlinks between the latest release and all
|
48
|
+
the shared items described in :local_shared_dirs and
|
49
|
+
:local_shared_files
|
50
|
+
}
|
51
|
+
task :symlink, :except => {:no_release => true} do
|
52
|
+
resources = local_shared_dirs+local_shared_files
|
53
|
+
run %Q{
|
54
|
+
cd #{latest_release} &&
|
55
|
+
rm -rf #{resources.join(' ')}
|
56
|
+
}
|
57
|
+
links = resources.collect do |resource|
|
58
|
+
"ln -sf #{File.join(shared_path,resource)} #{File.join(latest_release, resource)}"
|
59
|
+
end.join(" && ")
|
60
|
+
run links unless links.empty?
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
|