winton-ubistrano 1.2.2 → 1.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +49 -11
- data/Rakefile +2 -2
- data/bin/ubify +13 -0
- data/changelog.markdown +7 -0
- data/example/deploy.rb +6 -0
- data/lib/ubistrano/deploy.rb +1 -1
- data/lib/ubistrano/helpers.rb +17 -4
- data/lib/ubistrano/mysql.rb +7 -16
- data/lib/ubistrano/ubuntu.rb +4 -6
- data/lib/ubistrano.rb +15 -15
- data/templates/rails/database.yml.erb +2 -2
- data/ubistrano.gemspec +4 -2
- metadata +4 -3
data/README.markdown
CHANGED
@@ -1,20 +1,22 @@
|
|
1
1
|
Ubistrano
|
2
2
|
=========
|
3
3
|
|
4
|
-
Provision and deploy to an Ubuntu/God/Apache/Passenger stack using Capistrano.
|
4
|
+
Provision and deploy to an Ubuntu/God/Apache/Passenger stack using Capistrano and EC2.
|
5
5
|
|
6
6
|
Goals
|
7
7
|
-----
|
8
8
|
|
9
|
+
* Create an Ubuntu Hardy EC2 instance in one command (<code>cap ec2</code>)
|
9
10
|
* Provision a solid Ubuntu Hardy application server in one command (<code>cap ubuntu</code>)
|
10
11
|
* Deploy PHP, Rails, and Sinatra apps
|
11
12
|
* Be descriptive about what is going on and allow the user to opt out
|
12
|
-
* Simplify the deploy.rb file
|
13
|
+
* Simplify the <code>deploy.rb</code> file
|
13
14
|
|
14
15
|
The stack
|
15
16
|
---------
|
16
17
|
|
17
18
|
* Apache
|
19
|
+
* EC2 (optional)
|
18
20
|
* Git
|
19
21
|
* MySQL
|
20
22
|
* MySQLTuner
|
@@ -37,11 +39,18 @@ Getting started
|
|
37
39
|
|
38
40
|
gem install winton-ubistrano
|
39
41
|
|
40
|
-
###
|
42
|
+
### Ubify your project
|
41
43
|
|
42
|
-
|
44
|
+
cd your\_project
|
45
|
+
ubify .
|
43
46
|
|
44
|
-
|
47
|
+
* Runs <code>capify</code>
|
48
|
+
* Creates <code>config/deploy.example.rb</code>
|
49
|
+
* Adds <code>config/deploy.rb</code> to your project's <code>.gitignore</code>
|
50
|
+
|
51
|
+
### Copy config/deploy.example.rb to config/deploy.rb
|
52
|
+
|
53
|
+
It should look like this:
|
45
54
|
|
46
55
|
<pre>
|
47
56
|
set :ubistrano, {
|
@@ -54,6 +63,10 @@ set :ubistrano, {
|
|
54
63
|
:secret_key => ''
|
55
64
|
},
|
56
65
|
|
66
|
+
:mysql => {
|
67
|
+
:password => ''
|
68
|
+
},
|
69
|
+
|
57
70
|
:production => {
|
58
71
|
:domains => [ 'myapp.com', 'www.myapp.com' ],
|
59
72
|
:ssl => [ 'myapp.com' ],
|
@@ -71,25 +84,50 @@ require 'ubistrano'
|
|
71
84
|
|
72
85
|
Ubistrano uses the same Capistrano options you've come to love, but provides defaults and a few extra options as well.
|
73
86
|
|
74
|
-
|
87
|
+
Edit deploy.rb to the best of your ability. If setting up an EC2 instance, be sure to provide your AWS keys. Your IP address will be provided later.
|
88
|
+
|
89
|
+
Feel free to move any options into or out of the stage groups.
|
90
|
+
|
91
|
+
Create your EC2 instance
|
92
|
+
------------------------
|
93
|
+
|
94
|
+
### From your app directory
|
95
|
+
|
96
|
+
cap ec2
|
97
|
+
|
98
|
+
### Example output
|
99
|
+
|
100
|
+
<pre>
|
101
|
+
================================================================================
|
102
|
+
Press enter for Ubuntu Hardy or enter an AMI image id:
|
103
|
+
</pre>
|
75
104
|
|
76
105
|
Set up your Ubuntu Hardy server
|
77
106
|
-------------------------------
|
78
107
|
|
79
108
|
### From your app directory
|
80
109
|
|
81
|
-
|
110
|
+
cap ubuntu
|
82
111
|
|
83
112
|
### Example output
|
84
113
|
|
85
114
|
<pre>
|
86
|
-
|
115
|
+
================================================================================
|
87
116
|
Let's set up an Ubuntu server! (Tested with 8.04 LTS Hardy)
|
88
117
|
|
89
118
|
With each task, Ubistrano will describe what it is doing, and wait for a yes/no.
|
90
119
|
|
91
|
-
|
92
|
-
|
120
|
+
================================================================================
|
121
|
+
Please ssh into your server (use -i only for EC2):
|
122
|
+
ssh root@174.129.232.34 -i ~/.ssh/id_rsa-studicious
|
123
|
+
|
124
|
+
Edit your sudoers file:
|
125
|
+
visudo
|
126
|
+
|
127
|
+
Add the following line:
|
128
|
+
deploy ALL=NOPASSWD: ALL
|
129
|
+
|
130
|
+
Continue? (y/n)
|
93
131
|
</pre>
|
94
132
|
|
95
133
|
Deploy your app
|
@@ -109,7 +147,7 @@ All apps should have a <code>public</code> directory.
|
|
109
147
|
Deploy to staging
|
110
148
|
-----------------
|
111
149
|
|
112
|
-
Use any capistrano task, but replace
|
150
|
+
Use any capistrano task, but replace <code>cap</code> with <code>cap staging</code>.
|
113
151
|
|
114
152
|
### Example
|
115
153
|
|
data/Rakefile
CHANGED
data/bin/ubify
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
UBISTRANO = File.expand_path("../", File.dirname(__FILE__))
|
4
|
+
TO = File.expand_path("#{ARGV.join(' ')}", FileUtils.pwd)
|
5
|
+
|
6
|
+
# Capify
|
7
|
+
`capify #{TO}`
|
8
|
+
|
9
|
+
# Copy config/deploy.example.rb
|
10
|
+
FileUtils.cp "#{UBISTRANO}/example/deploy.rb", "#{TO}/config/deploy.example.rb"
|
11
|
+
|
12
|
+
# Add config/deploy.rb to .gitignore
|
13
|
+
File.open("#{TO}/.gitignore", 'a') { |f| f.write("\nconfig/deploy.rb\n") }
|
data/changelog.markdown
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
Version 1.2.3
|
2
|
+
-------------
|
3
|
+
|
4
|
+
* Added bin/ubify which executes capify in addition to copying config/deploy.example.rb and adding config/deploy.rb to the project's .gitignore
|
5
|
+
* Added mysql option in deploy.rb
|
6
|
+
* Minor ubuntu:install fixes
|
7
|
+
|
1
8
|
Version 1.2.2
|
2
9
|
-------------
|
3
10
|
|
data/example/deploy.rb
CHANGED
@@ -8,6 +8,12 @@ set :ubistrano, {
|
|
8
8
|
:secret_key => ''
|
9
9
|
},
|
10
10
|
|
11
|
+
:mysql => {
|
12
|
+
:root_password => '',
|
13
|
+
:app_password => ''
|
14
|
+
# Ubistrano creates a mysql user for each app
|
15
|
+
},
|
16
|
+
|
11
17
|
:production => {
|
12
18
|
:domains => [ 'myapp.com', 'www.myapp.com' ],
|
13
19
|
:ssl => [ 'myapp.com' ],
|
data/lib/ubistrano/deploy.rb
CHANGED
data/lib/ubistrano/helpers.rb
CHANGED
@@ -98,8 +98,7 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
98
98
|
end
|
99
99
|
|
100
100
|
def mysql_call
|
101
|
-
|
102
|
-
"mysql -u root --password=#{@mysql_root_password}"
|
101
|
+
"mysql -f -u root --password=#{mysql_root_password || ''}"
|
103
102
|
end
|
104
103
|
|
105
104
|
|
@@ -197,6 +196,13 @@ See #{File.expand_path '../../', File.dirname(__FILE__)}/templates/ubuntu/mysql.
|
|
197
196
|
when :god_sshd
|
198
197
|
"Would you like God to monitor sshd?
|
199
198
|
See #{File.expand_path '../../', File.dirname(__FILE__)}/templates/ubuntu/sshd.god.erb"
|
199
|
+
when :god_finished
|
200
|
+
"Please run the following commands:
|
201
|
+
ssh #{user}@#{host}
|
202
|
+
sudo /etc/init.d/god start
|
203
|
+
sudo /etc/init.d/god start
|
204
|
+
|
205
|
+
Continue?"
|
200
206
|
when :iptables
|
201
207
|
"May I update your server's iptables, limiting access to SSH, HTTP, HTTPS, and ping only?
|
202
208
|
See #{File.expand_path '../../', File.dirname(__FILE__)}/templates/ubuntu/iptables.rules.erb"
|
@@ -209,7 +215,10 @@ See #{File.expand_path '../../', File.dirname(__FILE__)}/templates/log/rotate.co
|
|
209
215
|
"Please ssh to your server and run `sudo mysqltuner`.
|
210
216
|
Continue?"
|
211
217
|
when :passenger
|
212
|
-
"Please run
|
218
|
+
"Please run the following commands:
|
219
|
+
ssh #{user}@#{host}
|
220
|
+
sudo passenger-install-apache2-module
|
221
|
+
|
213
222
|
The apache config file is found at /etc/apache2/apache2.conf.
|
214
223
|
Reload apache?"
|
215
224
|
when :run_ubuntu_install
|
@@ -217,9 +226,13 @@ Reload apache?"
|
|
217
226
|
|
218
227
|
Please run the second half of the install:
|
219
228
|
cap ubuntu:install
|
229
|
+
|
220
230
|
"
|
221
231
|
when :secure_mysql
|
222
|
-
"It is highly recommended you run mysql_secure_installation manually
|
232
|
+
"It is highly recommended you run mysql_secure_installation manually:
|
233
|
+
ssh #{user}@#{host}
|
234
|
+
mysql_secure_installation
|
235
|
+
|
223
236
|
See http://dev.mysql.com/doc/refman/5.1/en/mysql-secure-installation.html
|
224
237
|
Continue?"
|
225
238
|
when :sinatra_install
|
data/lib/ubistrano/mysql.rb
CHANGED
@@ -4,8 +4,8 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
4
4
|
namespace :create do
|
5
5
|
desc "Create database and user"
|
6
6
|
task :default, :roles => :db do
|
7
|
-
mysql.create.db
|
8
7
|
mysql.create.user
|
8
|
+
mysql.create.db
|
9
9
|
end
|
10
10
|
|
11
11
|
desc "Create database"
|
@@ -16,20 +16,11 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
16
16
|
desc "Create database user"
|
17
17
|
task :user, :roles => :db do
|
18
18
|
mysql_run [
|
19
|
-
"CREATE USER '#{
|
20
|
-
"GRANT ALL PRIVILEGES ON
|
19
|
+
"CREATE USER '#{application}'@'localhost' IDENTIFIED BY '#{mysql_password}'",
|
20
|
+
"GRANT ALL PRIVILEGES ON #{db_table}.* TO '#{application}'@'localhost'"
|
21
21
|
]
|
22
22
|
end
|
23
23
|
end
|
24
|
-
|
25
|
-
namespace :update do
|
26
|
-
desc 'Update mysql root password'
|
27
|
-
task :root_password, :roles => :db do
|
28
|
-
old_pass = ask "Current root password? (default: none)"
|
29
|
-
new_pass = ask "New root password? (default: none)"
|
30
|
-
sudo "mysqladmin -u root #{old_pass.empty? ? '' : "--password=#{old_pass} "}password #{new_pass}"
|
31
|
-
end
|
32
|
-
end
|
33
24
|
|
34
25
|
namespace :destroy do
|
35
26
|
desc "Destroy database and user"
|
@@ -46,8 +37,8 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
46
37
|
desc "Destroy database user"
|
47
38
|
task :user, :roles => :db do
|
48
39
|
mysql_run [
|
49
|
-
"REVOKE ALL PRIVILEGES, GRANT OPTION FROM '#{
|
50
|
-
"DROP USER '#{
|
40
|
+
"REVOKE ALL PRIVILEGES, GRANT OPTION FROM '#{application}'@'localhost'",
|
41
|
+
"DROP USER '#{application}'@'localhost'"
|
51
42
|
]
|
52
43
|
end
|
53
44
|
end
|
@@ -66,7 +57,7 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
66
57
|
|
67
58
|
desc "Restore remote database from backup"
|
68
59
|
task :restore, :roles => :db do
|
69
|
-
run_each "bunzip2 < #{shared_path}/db_backups/#{backup_name}.bz2 | mysql -u #{
|
60
|
+
run_each "bunzip2 < #{shared_path}/db_backups/#{backup_name}.bz2 | mysql -u #{application} --password=#{mysql_password} #{db_table}"
|
70
61
|
end
|
71
62
|
|
72
63
|
desc "Backup database to local"
|
@@ -80,7 +71,7 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
80
71
|
task :to_server, :roles => :db do
|
81
72
|
run_each [
|
82
73
|
"mkdir -p #{shared_path}/db_backups",
|
83
|
-
"mysqldump --add-drop-table -u #{
|
74
|
+
"mysqldump --add-drop-table -u #{application} -p#{mysql_password} #{db_table}_production | bzip2 -c > #{shared_path}/db_backups/#{backup_name}.bz2"
|
84
75
|
]
|
85
76
|
end
|
86
77
|
|
data/lib/ubistrano/ubuntu.rb
CHANGED
@@ -120,7 +120,7 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
120
120
|
task :apache, :roles => :web do
|
121
121
|
if yes("May I install Apache?")
|
122
122
|
sudo_puts [
|
123
|
-
'aptitude install apache2 apache2-mpm-prefork apache2-utils apache2.2-common libapr1 libaprutil1 ssl-cert -q -y',
|
123
|
+
'aptitude install apache2 apache2-mpm-prefork apache2-utils apache2.2-common libapr1 libaprutil1 ssl-cert apache2-prefork-dev -q -y',
|
124
124
|
'a2enmod rewrite',
|
125
125
|
'a2enmod ssl',
|
126
126
|
'a2dissite default'
|
@@ -142,7 +142,7 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
142
142
|
task :mysql, :roles => :db do
|
143
143
|
if yes("May I install MySQL?")
|
144
144
|
sudo_puts 'aptitude install mysql-client-5.0 mysql-common mysql-server mysql-server-5.0 libmysqlclient15-dev libmysqlclient15off -q -y'
|
145
|
-
|
145
|
+
sudo "mysqladmin -u root password #{mysql_root_password || ''}"
|
146
146
|
exit unless yes(msg(:secure_mysql))
|
147
147
|
end
|
148
148
|
end
|
@@ -202,7 +202,6 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
202
202
|
sudo_puts "aptitude install libopenssl-ruby -q -y"
|
203
203
|
install_source(:ruby) do |path|
|
204
204
|
sudo_puts make_install(path)
|
205
|
-
sudo_puts make_install(path) # install twice because openssl doesn't the first time
|
206
205
|
end
|
207
206
|
end
|
208
207
|
end
|
@@ -220,7 +219,6 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
220
219
|
desc 'Install Passenger'
|
221
220
|
task :passenger, :roles => :app do
|
222
221
|
if yes("May I install Passenger (mod_rails)?")
|
223
|
-
sudo_puts 'aptitude install apache2-prefork-dev -q -y'
|
224
222
|
gem_install :passenger
|
225
223
|
ROOT.apache.reload if yes(msg(:passenger))
|
226
224
|
end
|
@@ -240,9 +238,9 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
240
238
|
upload_from_erb('/usr/local/etc/god/mysql.god', binding, :folder => 'ubuntu') if yes(msg(:god_mysql))
|
241
239
|
upload_from_erb('/usr/local/etc/god/sshd.god', binding, :folder => 'ubuntu') if yes(msg(:god_sshd))
|
242
240
|
sudo_puts [
|
243
|
-
'update-rc.d god defaults'
|
244
|
-
'/etc/init.d/god start'
|
241
|
+
'update-rc.d god defaults'
|
245
242
|
]
|
243
|
+
exit unless yes(msg(:god_finished))
|
246
244
|
end
|
247
245
|
end
|
248
246
|
|
data/lib/ubistrano.rb
CHANGED
@@ -10,21 +10,21 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
10
10
|
|
11
11
|
# Default capistrano/ubistrano values
|
12
12
|
set :ubistrano, {
|
13
|
-
:base_dir
|
14
|
-
:
|
15
|
-
:
|
16
|
-
:
|
17
|
-
:
|
18
|
-
:platform
|
19
|
-
:plugins
|
20
|
-
:port
|
21
|
-
:repository_cache
|
22
|
-
:scm
|
23
|
-
:ssl
|
24
|
-
:stage
|
25
|
-
:use_sudo
|
26
|
-
:user
|
27
|
-
:versions
|
13
|
+
:base_dir => '/var/www',
|
14
|
+
:deploy_via => :remote_cache,
|
15
|
+
:domains => [],
|
16
|
+
:mysql_root_password => '',
|
17
|
+
:mysql_app_password => '',
|
18
|
+
:platform => :rails,
|
19
|
+
:plugins => {},
|
20
|
+
:port => 22,
|
21
|
+
:repository_cache => 'git_cache',
|
22
|
+
:scm => :git,
|
23
|
+
:ssl => [],
|
24
|
+
:stage => :production,
|
25
|
+
:use_sudo => false,
|
26
|
+
:user => 'deploy',
|
27
|
+
:versions => {}
|
28
28
|
}.merge(ubistrano)
|
29
29
|
|
30
30
|
# Default plugins
|
data/ubistrano.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'ubistrano'
|
3
|
-
s.version = '1.2.
|
3
|
+
s.version = '1.2.3'
|
4
4
|
s.date = '2008-02-22'
|
5
5
|
|
6
6
|
s.summary = "Provision and deploy to an Ubuntu/God/Apache/Passenger stack using Capistrano"
|
@@ -10,14 +10,16 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.email = 'mail@wintoni.us'
|
11
11
|
s.homepage = 'http://github.com/winton/ubistrano'
|
12
12
|
|
13
|
-
s.has_rdoc = false
|
14
13
|
s.add_dependency 'amazon-ec2', '>= 0.3.2'
|
14
|
+
s.executables = ["ubify"]
|
15
|
+
s.has_rdoc = false
|
15
16
|
|
16
17
|
# = MANIFEST =
|
17
18
|
s.files = %w[
|
18
19
|
MIT-LICENSE
|
19
20
|
README.markdown
|
20
21
|
Rakefile
|
22
|
+
bin/ubify
|
21
23
|
changelog.markdown
|
22
24
|
example/deploy.rb
|
23
25
|
lib/ubistrano.rb
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: winton-ubistrano
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Winton Welsh
|
@@ -24,8 +24,8 @@ dependencies:
|
|
24
24
|
version:
|
25
25
|
description: Provision and deploy to an Ubuntu/God/Apache/Passenger stack using Capistrano
|
26
26
|
email: mail@wintoni.us
|
27
|
-
executables:
|
28
|
-
|
27
|
+
executables:
|
28
|
+
- ubify
|
29
29
|
extensions: []
|
30
30
|
|
31
31
|
extra_rdoc_files: []
|
@@ -34,6 +34,7 @@ files:
|
|
34
34
|
- MIT-LICENSE
|
35
35
|
- README.markdown
|
36
36
|
- Rakefile
|
37
|
+
- bin/ubify
|
37
38
|
- changelog.markdown
|
38
39
|
- example/deploy.rb
|
39
40
|
- lib/ubistrano.rb
|