railsmachine 1.0.1 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +1 -1
- data/LICENSE +1 -1
- data/README +76 -16
- data/Rakefile +6 -4
- data/lib/railsmachine/generators/railsmachine/USAGE +1 -1
- data/lib/railsmachine/generators/railsmachine/templates/deploy.rb +21 -11
- data/lib/railsmachine/recipes.rb +150 -62
- data/lib/railsmachine/recipes/app/deploy.rb +28 -0
- data/lib/railsmachine/recipes/{mongrel.rb → app/mongrel.rb} +19 -26
- data/lib/railsmachine/recipes/app/passenger.rb +20 -0
- data/lib/railsmachine/recipes/{mysql.rb → db/mysql.rb} +1 -1
- data/lib/railsmachine/recipes/{pgsql.rb → db/postgresql.rb} +1 -1
- data/lib/railsmachine/recipes/db/sqlite3.rb +14 -0
- data/lib/railsmachine/recipes/scm/git.rb +44 -0
- data/lib/railsmachine/recipes/scm/subversion.rb +47 -0
- data/lib/railsmachine/recipes/{apache.rb → web/apache.rb} +26 -15
- data/lib/railsmachine/recipes/{templates → web/templates/mongrel}/httpd-ssl.conf +14 -8
- data/lib/railsmachine/recipes/{templates → web/templates/mongrel}/httpd.conf +14 -10
- data/lib/railsmachine/recipes/web/templates/passenger/httpd-ssl.conf +60 -0
- data/lib/railsmachine/recipes/web/templates/passenger/httpd.conf +40 -0
- metadata +31 -19
- data/lib/railsmachine/generators/railsmachine/templates/deploy.rb~ +0 -95
- data/lib/railsmachine/recipes/svn.rb +0 -46
data/COPYING
CHANGED
data/LICENSE
CHANGED
data/README
CHANGED
@@ -1,23 +1,83 @@
|
|
1
|
-
|
1
|
+
Five Minute Rails Application Deployment
|
2
2
|
|
3
|
-
|
3
|
+
Ready to deploy your Rails application to Rails Machine? Follow these steps and you’ll have it running in no time! Free to utilize Rails Machine’s Ask Us Anything Support and contact us with any questions you have along the way.
|
4
4
|
|
5
|
-
|
5
|
+
Update Gems
|
6
6
|
|
7
|
-
|
8
|
-
capify .
|
9
|
-
railsmachine --apply-to . --name <app_name> --domain <yourdomain.com>
|
10
|
-
cap repos:setup
|
11
|
-
cd ../<app_name>_machine
|
12
|
-
cap servers:setup deploy:cold
|
7
|
+
Install the latest version of the railsmachine gem:
|
13
8
|
|
14
|
-
|
15
|
-
|
9
|
+
$ sudo gem install railsmachine
|
10
|
+
|
11
|
+
Install Phusion Passenger and Ruby Enterprise Edition
|
16
12
|
|
17
|
-
|
18
|
-
/etc/mongrel_cluster/ - Mongrel cluster configurations
|
19
|
-
/var/www/apps/ - Rails applications
|
13
|
+
If you do not have Phusion Passenger and Ruby Enterprise Edition installed on your Rails Machine yet you can run this installer on your server.
|
20
14
|
|
21
|
-
|
22
|
-
|
15
|
+
$ wget http://assets.railsmachine.com/wiki/centos_passenger_install.sh
|
16
|
+
$ sh centos_passenger_install.sh
|
17
|
+
|
18
|
+
Setup Capistrano
|
23
19
|
|
20
|
+
Capify your application:
|
21
|
+
|
22
|
+
$ capify .
|
23
|
+
|
24
|
+
Configure Capistrano for Rails Machine
|
25
|
+
|
26
|
+
The following step customizes your config/deploy.rb with two bits of information you provide:
|
27
|
+
|
28
|
+
--name: a simple name for your application. no spaces, please.
|
29
|
+
example: my-cool-app
|
30
|
+
--domain: the primary domain name for your application. please omit the ‘www’ – we automaticaly alias www.whateveryouprovide.com as needed.
|
31
|
+
example: my-cool-app.com
|
32
|
+
$ railsmachine --apply-to . --name my-cool-app --domain my-cool-app.com
|
33
|
+
|
34
|
+
Please note that the domain name provided will need to be correctly pointed at your Rails Machine account. If you don’t have a DNS provider, we’ve been more than happy with DNS Made Easy.
|
35
|
+
|
36
|
+
Update Database Config
|
37
|
+
|
38
|
+
Update your applications config/database.yml’s section with your desired MySQL datbase name, username, and password. The database and user will be created for you in a forthcoming step.
|
39
|
+
|
40
|
+
Application Setup
|
41
|
+
|
42
|
+
Rails Machine defaults to using mongrel + mod_proxy_balancer to run your Rails Application. If you’d like to switch to Phusion Passenger, edit the line in your application’s config/deploy.rb that begins set :app_server to reflect your choice. For example:
|
43
|
+
|
44
|
+
set :app_server, :passenger
|
45
|
+
|
46
|
+
Run the following Capistrano task to setup your MySQL databases and configure your application servers (mongrel/passenger):
|
47
|
+
|
48
|
+
$ cap servers:setup
|
49
|
+
|
50
|
+
Source Control
|
51
|
+
|
52
|
+
If you’re already using Source Control…
|
53
|
+
|
54
|
+
...edit the lines in your application’s config/deploy.rb that begin set :repository and set :repository. For example:
|
55
|
+
|
56
|
+
set :scm, :git
|
57
|
+
set :repository, "git@github.com:yourname/my-cool-app.git"
|
58
|
+
|
59
|
+
If you’re not yet using Source Control…
|
60
|
+
|
61
|
+
...you can easily setup a Git/Subversion repository on your Rails Machine. Subversion is the default, edit the line in your application’s config/deploy.rb that begins set :scm if you’d like to change it to git. For example:
|
62
|
+
|
63
|
+
set :scm, :git
|
64
|
+
|
65
|
+
Next, run the following task to import your application into a Git/SVN repository on your Rails Machine:
|
66
|
+
|
67
|
+
$ cap repos:setup
|
68
|
+
|
69
|
+
Initial Deploy
|
70
|
+
|
71
|
+
That’s it! You’re ready to use Capistrano to deploy your app for the first time:
|
72
|
+
|
73
|
+
$ cap deploy:cold
|
74
|
+
|
75
|
+
Once that’s done, open your application in a web browser and test it out!
|
76
|
+
|
77
|
+
To perform a subsequent deploy with Capistrano:
|
78
|
+
|
79
|
+
$ cap deploy
|
80
|
+
|
81
|
+
or, if you need to run migrations as well:
|
82
|
+
|
83
|
+
$ cap deploy:migrations
|
data/Rakefile
CHANGED
@@ -15,22 +15,24 @@ setup_rdoc ['README', 'LICENSE', 'COPYING', 'lib/**/*.rb', 'doc/**/*.rdoc']
|
|
15
15
|
desc "Does a full compile, test run"
|
16
16
|
task :default => [:test, :package]
|
17
17
|
|
18
|
-
version="1.0.
|
18
|
+
version="1.0.3"
|
19
19
|
name="railsmachine"
|
20
20
|
|
21
21
|
setup_gem(name, version) do |spec|
|
22
22
|
spec.summary = "The Rails Machine task library"
|
23
23
|
spec.description = spec.summary
|
24
|
-
spec.author="
|
25
|
-
spec.add_dependency('capistrano', '>= 2.
|
24
|
+
spec.author="Rails Machine"
|
25
|
+
spec.add_dependency('capistrano', '>= 2.1.0')
|
26
26
|
spec.has_rdoc = false
|
27
27
|
spec.files += Dir.glob("bin/*")
|
28
28
|
spec.files += Dir.glob("resources/**/*")
|
29
29
|
spec.default_executable = "railsmachine"
|
30
30
|
spec.executables = ["railsmachine"]
|
31
|
+
spec.email = "support@railsmachine.com"
|
32
|
+
spec.homepage = "http://railsmachine.com/"
|
33
|
+
spec.rubyforge_project = "railsmachine"
|
31
34
|
end
|
32
35
|
|
33
|
-
|
34
36
|
task :install => [:test, :package] do
|
35
37
|
sh %{sudo gem install pkg/#{name}-#{version}.gem}
|
36
38
|
end
|
@@ -27,10 +27,6 @@ set :user, "deploy"
|
|
27
27
|
set :runner, user
|
28
28
|
set :admin_runner, user
|
29
29
|
|
30
|
-
|
31
|
-
# URL of your source repository.
|
32
|
-
set :repository, "svn+ssh://#{user}@#{domain}#{deploy_to}/repos/trunk"
|
33
|
-
|
34
30
|
# Rails environment. Used by application setup tasks and migrate tasks.
|
35
31
|
set :rails_env, "production"
|
36
32
|
|
@@ -52,38 +48,52 @@ role :app, domain
|
|
52
48
|
role :db, domain, :primary => true
|
53
49
|
role :scm, domain
|
54
50
|
|
51
|
+
|
55
52
|
# =============================================================================
|
56
|
-
#
|
53
|
+
# APPLICATION SERVER OPTIONS
|
54
|
+
# =============================================================================
|
55
|
+
# set :app_server, :mongrel # :mongrel or :passenger
|
56
|
+
|
57
|
+
# =============================================================================
|
58
|
+
# WEB SERVER OPTIONS
|
57
59
|
# =============================================================================
|
60
|
+
# set :httpd, "apache" # apache
|
58
61
|
# set :apache_server_name, domain
|
59
62
|
# set :apache_server_aliases, %w{alias1 alias2}
|
60
|
-
# set :apache_default_vhost, true # force use of
|
63
|
+
# set :apache_default_vhost, true # force use of apache_default_vhost_config
|
61
64
|
# set :apache_default_vhost_conf, "/etc/httpd/conf/default.conf"
|
62
65
|
# set :apache_conf, "/etc/httpd/conf/apps/#{application}.conf"
|
63
|
-
# set :apache_ctl, "/etc/init.d/httpd"
|
64
66
|
# set :apache_proxy_port, 8000
|
65
67
|
# set :apache_proxy_servers, 2
|
66
68
|
# set :apache_proxy_address, "127.0.0.1"
|
67
69
|
# set :apache_ssl_enabled, false
|
68
70
|
# set :apache_ssl_ip, "127.0.0.1"
|
69
71
|
# set :apache_ssl_forward_all, false
|
72
|
+
# set :apache_ctl, "/etc/init.d/httpd"
|
73
|
+
|
74
|
+
|
70
75
|
|
71
76
|
# =============================================================================
|
72
77
|
# MONGREL OPTIONS
|
73
78
|
# =============================================================================
|
74
|
-
# set :mongrel_servers,
|
75
|
-
# set :mongrel_port,
|
76
|
-
# set :mongrel_address,
|
79
|
+
# set :mongrel_servers, apache_proxy_servers
|
80
|
+
# set :mongrel_port, apache_proxy_port
|
81
|
+
# set :mongrel_address, apache_proxy_address
|
77
82
|
# set :mongrel_environment, "production"
|
78
83
|
# set :mongrel_pid_file, "/var/run/mongrel_cluster/#{application}.pid"
|
79
84
|
# set :mongrel_conf, "/etc/mongrel_cluster/#{application}.conf"
|
80
85
|
# set :mongrel_user, user
|
81
86
|
# set :mongrel_group, group
|
82
87
|
|
88
|
+
# =============================================================================
|
89
|
+
# DATABASE OPTIONS
|
90
|
+
# =============================================================================
|
91
|
+
# set :database, "mysql" # mysql or postgresql
|
92
|
+
|
83
93
|
# =============================================================================
|
84
94
|
# SCM OPTIONS
|
85
95
|
# =============================================================================
|
86
|
-
#set :scm,
|
96
|
+
# set :scm, :subversion # :subversion or :git
|
87
97
|
|
88
98
|
# =============================================================================
|
89
99
|
# SSH OPTIONS
|
data/lib/railsmachine/recipes.rb
CHANGED
@@ -1,14 +1,46 @@
|
|
1
|
-
require 'railsmachine/recipes/svn'
|
2
|
-
require 'railsmachine/recipes/mysql'
|
3
|
-
require 'railsmachine/recipes/pgsql'
|
4
|
-
require 'railsmachine/recipes/apache'
|
5
|
-
require 'railsmachine/recipes/mongrel'
|
6
|
-
|
7
1
|
Capistrano::Configuration.instance(:must_exist).load do
|
8
|
-
|
2
|
+
|
9
3
|
default_run_options[:pty] = true
|
10
4
|
set :keep_releases, 3
|
11
5
|
set :app_symlinks, nil
|
6
|
+
set :scm, :subversion
|
7
|
+
set :httpd, :apache
|
8
|
+
set :app_server, :mongrel
|
9
|
+
set :db_adapter, :mysql
|
10
|
+
set :rails_env, "production"
|
11
|
+
|
12
|
+
load 'config/deploy'
|
13
|
+
|
14
|
+
set :repository do
|
15
|
+
scm = fetch(:scm)
|
16
|
+
repos_base = "#{user}@#{domain}#{deploy_to}"
|
17
|
+
if scm.to_s == 'subversion'
|
18
|
+
"svn+ssh://#{repos_base}/repos/trunk"
|
19
|
+
elsif scm.to_s == 'git'
|
20
|
+
"ssh://#{repos_base}/repos/#{application}.git"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
task :validate_required_variables do
|
26
|
+
validate_option(:scm, :in => [:subversion, :git])
|
27
|
+
validate_option(:app_server, :in => [:mongrel, :passenger])
|
28
|
+
validate_option(:httpd, :in => [:apache])
|
29
|
+
validate_option(:db_adapter, :in => [:mysql, :postgresql, :sqlite3])
|
30
|
+
end
|
31
|
+
|
32
|
+
before :require_recipes, :validate_required_variables
|
33
|
+
|
34
|
+
require "railsmachine/recipes/app/deploy"
|
35
|
+
require "railsmachine/recipes/app/mongrel"
|
36
|
+
require "railsmachine/recipes/app/passenger"
|
37
|
+
|
38
|
+
# defer requires until variables have been set
|
39
|
+
task :require_recipes do
|
40
|
+
require "railsmachine/recipes/scm/#{scm}"
|
41
|
+
require "railsmachine/recipes/web/#{httpd}"
|
42
|
+
require "railsmachine/recipes/db/#{db_adapter}"
|
43
|
+
end
|
12
44
|
|
13
45
|
namespace :servers do
|
14
46
|
|
@@ -17,6 +49,7 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
17
49
|
Used to configure your deployment environment in one command.
|
18
50
|
DESC
|
19
51
|
task :setup do
|
52
|
+
sudo "chown -R #{user}:#{user} #{deploy_to.gsub(application,'')}"
|
20
53
|
deploy.setup
|
21
54
|
begin
|
22
55
|
db.setup
|
@@ -27,7 +60,9 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
27
60
|
web.setup
|
28
61
|
end
|
29
62
|
|
30
|
-
desc
|
63
|
+
desc <<-DESC
|
64
|
+
A macro task that restarts the application and web servers
|
65
|
+
DESC
|
31
66
|
task :restart do
|
32
67
|
app.restart
|
33
68
|
web.restart
|
@@ -37,45 +72,65 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
37
72
|
|
38
73
|
namespace :app do
|
39
74
|
|
40
|
-
desc
|
75
|
+
desc <<-DESC
|
76
|
+
Setup #{app_server}
|
77
|
+
DESC
|
41
78
|
task :setup, :roles => :app do
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
mongrel.cluster.configure
|
79
|
+
case app_server.to_s
|
80
|
+
when "mongrel"
|
81
|
+
setup_mongrel
|
82
|
+
when "passenger"
|
83
|
+
# do nothing
|
84
|
+
end
|
49
85
|
end
|
50
86
|
|
51
|
-
desc
|
87
|
+
desc <<-DESC
|
88
|
+
Restart application server.
|
89
|
+
DESC
|
52
90
|
task :restart, :roles => :app do
|
53
|
-
|
54
|
-
mongrel.cluster.restart
|
91
|
+
application_servlet.restart
|
55
92
|
end
|
56
93
|
|
57
|
-
desc
|
94
|
+
desc <<-DESC
|
95
|
+
Start application server.
|
96
|
+
DESC
|
58
97
|
task :start, :roles => :app do
|
59
|
-
|
60
|
-
mongrel.cluster.start
|
98
|
+
application_servlet.start
|
61
99
|
end
|
62
100
|
|
63
|
-
desc
|
101
|
+
desc <<-DESC
|
102
|
+
Stop application server.
|
103
|
+
DESC
|
64
104
|
task :stop, :roles => :app do
|
65
|
-
|
66
|
-
|
105
|
+
application_servlet.stop
|
106
|
+
end
|
107
|
+
|
108
|
+
desc <<-DESC
|
109
|
+
Switch your application to run on mongrel or passenger.
|
110
|
+
DESC
|
111
|
+
task :switch do
|
112
|
+
case app_server.to_s
|
113
|
+
when "mongrel"
|
114
|
+
switch_to_mongrel
|
115
|
+
when "passenger"
|
116
|
+
switch_to_passenger
|
117
|
+
end
|
67
118
|
end
|
68
119
|
|
69
120
|
namespace :symlinks do
|
70
121
|
|
71
|
-
desc
|
122
|
+
desc <<-DESC
|
123
|
+
Setup application symlinks in the public
|
124
|
+
DESC
|
72
125
|
task :setup, :roles => [:app, :web] do
|
73
126
|
if app_symlinks
|
74
127
|
app_symlinks.each { |link| run "mkdir -p #{shared_path}/public/#{link}" }
|
75
128
|
end
|
76
129
|
end
|
77
130
|
|
78
|
-
desc
|
131
|
+
desc <<-DESC
|
132
|
+
Link public directories to shared location.
|
133
|
+
DESC
|
79
134
|
task :update, :roles => [:app, :web] do
|
80
135
|
if app_symlinks
|
81
136
|
app_symlinks.each { |link| run "ln -nfs #{shared_path}/public/#{link} #{current_path}/public/#{link}" }
|
@@ -88,74 +143,107 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
88
143
|
|
89
144
|
namespace :web do
|
90
145
|
|
91
|
-
desc
|
146
|
+
desc <<-DESC
|
147
|
+
Setup web server.
|
148
|
+
DESC
|
92
149
|
task :setup, :roles => :web do
|
93
|
-
set :apache_server_name, domain unless
|
150
|
+
set :apache_server_name, domain unless apache_server_name
|
94
151
|
apache.configure
|
95
152
|
end
|
96
153
|
|
97
|
-
desc
|
154
|
+
desc <<-DESC
|
155
|
+
Restart web server.
|
156
|
+
DESC
|
98
157
|
task :restart, :roles => :web do
|
99
158
|
apache.restart
|
100
159
|
end
|
101
160
|
|
102
|
-
desc
|
161
|
+
desc <<-DESC
|
162
|
+
Reload web server configuration.
|
163
|
+
DESC
|
103
164
|
task :reload, :roles => :web do
|
104
165
|
apache.reload
|
105
166
|
end
|
106
167
|
|
107
|
-
desc
|
168
|
+
desc <<-DESC
|
169
|
+
Start web server.
|
170
|
+
DESC
|
108
171
|
task :start, :roles => :web do
|
109
172
|
apache.start
|
110
173
|
end
|
111
174
|
|
112
|
-
desc
|
175
|
+
desc <<-DESC
|
176
|
+
Stop web server.
|
177
|
+
DESC
|
113
178
|
task :stop, :roles => :web do
|
114
179
|
apache.stop
|
115
180
|
end
|
116
181
|
|
117
182
|
end
|
118
183
|
|
119
|
-
namespace :db do
|
120
|
-
|
121
|
-
desc "Setup database server."
|
122
|
-
task :setup, :roles => :db, :only => { :primary => true } do
|
123
|
-
db_config = YAML.load_file('config/database.yml')
|
124
|
-
db_type = db_config[rails_env]["adapter"]
|
125
|
-
case db_config[rails_env]["adapter"]
|
126
|
-
when "mysql"
|
127
|
-
mysql.setup
|
128
|
-
when "postgresql"
|
129
|
-
postgresql.setup
|
130
|
-
else
|
131
|
-
puts "Only MySQL or Postgres can be configured by db:setup."
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
end
|
136
|
-
|
137
184
|
namespace :repos do
|
138
|
-
|
139
|
-
|
185
|
+
desc <<-DESC
|
186
|
+
Setup source control repository.
|
187
|
+
DESC
|
140
188
|
task :setup, :roles => :scm do
|
141
|
-
begin
|
142
|
-
|
189
|
+
begin
|
190
|
+
sudo "chown -R #{user}:#{user} #{deploy_to.gsub(application,'')}"
|
191
|
+
localrepo.setup
|
143
192
|
rescue
|
144
|
-
puts "
|
193
|
+
puts "repos:setup failed!"
|
194
|
+
end
|
195
|
+
localrepo.import
|
145
196
|
end
|
146
|
-
svn.import
|
147
|
-
end
|
148
197
|
|
149
198
|
end
|
150
199
|
|
151
|
-
|
200
|
+
on :start, :require_recipes
|
152
201
|
before 'deploy:update_code', 'app:symlinks:setup'
|
153
202
|
after 'deploy:symlink', 'app:symlinks:update'
|
154
203
|
after 'deploy:cold', 'web:reload'
|
155
204
|
after :deploy,'deploy:cleanup'
|
156
205
|
|
157
|
-
def
|
158
|
-
|
159
|
-
|
206
|
+
def setup_mongrel
|
207
|
+
set_mongrel_conf
|
208
|
+
set :mongrel_environment, rails_env
|
209
|
+
set :mongrel_port, apache_proxy_port
|
210
|
+
set :mongrel_servers, apache_proxy_servers
|
211
|
+
set :mongrel_user, user unless mongrel_user
|
212
|
+
set :mongrel_group, mongrel_user unless mongrel_group
|
213
|
+
mongrel.cluster.configure
|
214
|
+
end
|
215
|
+
|
216
|
+
def switch_to_mongrel
|
217
|
+
app.setup
|
218
|
+
app.start
|
219
|
+
web.setup
|
220
|
+
web.restart
|
221
|
+
end
|
222
|
+
|
223
|
+
def switch_to_passenger
|
224
|
+
web.setup
|
225
|
+
mongrel.cluster.remove
|
226
|
+
web.restart
|
227
|
+
end
|
228
|
+
|
229
|
+
def validate_option(key, options = {})
|
230
|
+
if !(options[:in].map{|o| o.to_s } + ['']).include?(self[key].to_s)
|
231
|
+
raise(ArgumentError, error_msg("Invalid value '#{self[key]}' for option '#{key}' must be one of the following: '#{options[:in].join(', ')}'"))
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
def application_servlet
|
236
|
+
case app_server.to_s
|
237
|
+
when 'mongrel'
|
238
|
+
mongrel.cluster
|
239
|
+
when 'passenger'
|
240
|
+
passenger
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
def error_msg(msg)
|
245
|
+
banner = ''; msg.length.times { banner << "+" }
|
246
|
+
return "\n\n#{banner}\n#{msg}\n#{banner}\n\n"
|
247
|
+
end
|
160
248
|
|
161
249
|
end
|