capistrano_transmit 0.2.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +8 -9
- data/capistrano_transmit.gemspec +1 -1
- data/lib/capistrano/transmit.rb +41 -13
- metadata +1 -1
data/README.rdoc
CHANGED
@@ -24,7 +24,7 @@ Mac OS X development.
|
|
24
24
|
|
25
25
|
or in your +Gemfile+:
|
26
26
|
|
27
|
-
gem 'capistrano_transmit'
|
27
|
+
gem 'capistrano_transmit', '~> 1.0.0'
|
28
28
|
|
29
29
|
Then add to your deploy.rb:
|
30
30
|
|
@@ -32,19 +32,18 @@ Then add to your deploy.rb:
|
|
32
32
|
|
33
33
|
== Examples
|
34
34
|
|
35
|
-
cap transmit:get:mysql # Fetch the
|
36
|
-
# and overwrite your local development database with it
|
37
|
-
cap transmit:get:assets # Fetch the remote assets into your local development environment
|
38
|
-
|
39
|
-
|
35
|
+
cap transmit:get:mysql # Fetch the production database into local development
|
40
36
|
cap transmit:put:mysql # Overwrite the production MySQL database with your development data
|
41
37
|
|
42
38
|
== Prerequisites
|
43
39
|
|
44
|
-
|
40
|
+
You need Capistrano 2 for this gem to work.
|
41
|
+
|
42
|
+
A couple variables can be overridden by setting them in config/deploy.rb:
|
45
43
|
|
46
|
-
user
|
47
|
-
deploy_host
|
44
|
+
user # SSH user, defaults to nil, which falls back to your unix user
|
45
|
+
deploy_host # the host on which to run the db dump, falls back to your first db
|
46
|
+
dumpfile # remote pathname to dump the database in, defaults to tmp/${production}.sql.gz
|
48
47
|
|
49
48
|
|
50
49
|
Copyright (c) 2010-2011 Joost Baaij, released under the MIT license.
|
data/capistrano_transmit.gemspec
CHANGED
data/lib/capistrano/transmit.rb
CHANGED
@@ -4,11 +4,9 @@ end
|
|
4
4
|
|
5
5
|
Capistrano::Configuration.instance.load do
|
6
6
|
|
7
|
-
_cset :user,
|
8
|
-
_cset
|
9
|
-
_cset
|
10
|
-
_cset :db_local, { YAML::load_file("config/database.yml")['development'] }
|
11
|
-
_cset :dumpfile, { "#{current_path}/tmp/#{db_remote['database']}.sql.gz" }
|
7
|
+
_cset :user, nil
|
8
|
+
_cset(:deploy_host) { find_servers(:roles => :db).first.host }
|
9
|
+
_cset(:dumpfile) { "#{current_path}/tmp/#{_db_remote['database']}.sql.gz" }
|
12
10
|
|
13
11
|
after "transmit:get:mysql", "transmit:cleanup"
|
14
12
|
after "transmit:put:mysql", "transmit:cleanup"
|
@@ -17,32 +15,62 @@ Capistrano::Configuration.instance.load do
|
|
17
15
|
namespace :get do
|
18
16
|
desc 'Fetch the remote production database and overwrite your local development database with it'
|
19
17
|
task :mysql, :roles => :db do
|
20
|
-
run "mysqldump --opt --quick --extended-insert --skip-lock-tables
|
18
|
+
run "mysqldump --opt --quick --extended-insert --skip-lock-tables #{_remote_db_auth} | gzip > #{dumpfile}"
|
21
19
|
|
22
|
-
system "rsync -vP #{
|
23
|
-
system "gunzip < tmp/#{
|
20
|
+
system "rsync -vP #{_user_with_host}:#{dumpfile} tmp/#{_db_local["database"]}.sql.gz"
|
21
|
+
system "gunzip < tmp/#{_db_local["database"]}.sql.gz | mysql #{_local_db_auth}"
|
24
22
|
end
|
25
23
|
|
26
24
|
desc 'Fetch the assets from the production server to the development environment'
|
27
25
|
task :assets, :roles => :app do
|
28
|
-
system "rsync -Lcrvz #{
|
26
|
+
system "rsync -Lcrvz #{_user_with_host}:#{current_path}/public ."
|
29
27
|
end
|
30
28
|
end
|
31
29
|
|
32
30
|
namespace :put do
|
33
31
|
desc 'Upload the local development database to the remote production database and overwrite it'
|
34
32
|
task :mysql, :roles => :db do
|
35
|
-
system "mysqldump --opt
|
33
|
+
system "mysqldump --opt #{_local_db_auth} > tmp/#{_db_local['database']}.sql"
|
36
34
|
|
37
|
-
system "rsync -vP tmp/#{
|
38
|
-
run "mysql
|
35
|
+
system "rsync -vP tmp/#{_db_local['database']}.sql #{_user_with_host}:#{dumpfile}"
|
36
|
+
run "mysql #{_remote_db_auth} < #{dumpfile}"
|
39
37
|
end
|
40
38
|
end
|
41
39
|
|
42
40
|
task :cleanup do
|
43
41
|
run "rm #{dumpfile}"
|
44
|
-
system "rm tmp/#{
|
42
|
+
system "rm tmp/#{_db_local['database']}.sql.gz"
|
45
43
|
end
|
46
44
|
end
|
47
45
|
|
46
|
+
# Return just the deploy host when user not set.
|
47
|
+
def _user_with_host
|
48
|
+
user.nil? ? deploy_host : "#{user}@#{deploy_host}"
|
49
|
+
end
|
50
|
+
|
51
|
+
# Output of the entire database.yml on the remote server.
|
52
|
+
def _db_config
|
53
|
+
@_db_config ||= capture("cat #{current_path}/config/database.yml")
|
54
|
+
end
|
55
|
+
|
56
|
+
# Production database configuration hash.
|
57
|
+
def _db_remote
|
58
|
+
@_db_remote ||= YAML::load(_db_config)['production']
|
59
|
+
end
|
60
|
+
|
61
|
+
# Development database configuration hash.
|
62
|
+
def _db_local
|
63
|
+
@_db_local ||= YAML::load_file("config/database.yml")['development']
|
64
|
+
end
|
65
|
+
|
66
|
+
# Complete remote database connection string.
|
67
|
+
def _remote_db_auth
|
68
|
+
@_remote_db_auth ||= "-u #{_db_remote['username']} --password='#{_db_remote['password']}' --host='#{_db_remote['host']}' #{_db_remote['database']}"
|
69
|
+
end
|
70
|
+
|
71
|
+
# Complete local database connection string.
|
72
|
+
def _local_db_auth
|
73
|
+
@_local_db_auth ||= "-u #{_db_local['username']} --password='#{_db_local['password']}' --host='#{_db_local['host']}' #{_db_local['database']}"
|
74
|
+
end
|
75
|
+
|
48
76
|
end
|