sumodev_deploy 0.2.6 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/sumodev_deploy.rb +27 -4
- data/sumodev_deploy.gemspec +1 -1
- metadata +1 -1
data/lib/sumodev_deploy.rb
CHANGED
@@ -7,6 +7,14 @@ configuration.load do
|
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
|
+
def staging?
|
11
|
+
fetch(:stage, '').to_sym == :staging
|
12
|
+
end
|
13
|
+
|
14
|
+
def production?
|
15
|
+
fetch(:stage, '').to_sym == :production
|
16
|
+
end
|
17
|
+
|
10
18
|
_cset(:client) { abort "sumodev_deploy requires that you set client and project names in your capfile" }
|
11
19
|
_cset(:project) { abort "sumodev_deploy requires that you set client and project names in your capfile"}
|
12
20
|
|
@@ -23,7 +31,7 @@ configuration.load do
|
|
23
31
|
_cset(:app_path) { "apps/#{client}/#{project}" }
|
24
32
|
_cset(:shared_files_path) { "#{shared_path}/files/"}
|
25
33
|
_cset(:document_root) { "#{homedir}#{client}/#{project}" }
|
26
|
-
_cset(:keep_releases) {
|
34
|
+
_cset(:keep_releases) { staging? ? 1 : 3 }
|
27
35
|
|
28
36
|
set(:application) { project }
|
29
37
|
set(:deploy_to) { "#{homedir}#{app_path}"}
|
@@ -36,6 +44,20 @@ configuration.load do
|
|
36
44
|
|
37
45
|
namespace :sumodev do
|
38
46
|
namespace :db do
|
47
|
+
def remote_db_name
|
48
|
+
production? && !fetch(:production_db, '').empty? ?
|
49
|
+
production_db :
|
50
|
+
db_name
|
51
|
+
end
|
52
|
+
|
53
|
+
def remote_db_options
|
54
|
+
{:db_host => 'host', :db_username => 'user', :db_password => 'password'}.inject('') do |options, (key, param)|
|
55
|
+
value = fetch(key, '')
|
56
|
+
options << "--#{param}=#{value} " unless value.empty?
|
57
|
+
options
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
39
61
|
desc "Create the database. Reads :db_name variable, or it is composed from client / project"
|
40
62
|
task :create, :roles => :db do
|
41
63
|
run "create_db #{db_name}"
|
@@ -57,7 +79,7 @@ configuration.load do
|
|
57
79
|
run_locally %{mysqladmin create #{db_name}} rescue nil
|
58
80
|
|
59
81
|
mysql = IO.popen("mysql #{db_name}", 'r+')
|
60
|
-
run "mysqldump --set-charset #{
|
82
|
+
run "mysqldump --set-charset #{remote_db_options} #{remote_db_name}" do |ch, stream, out|
|
61
83
|
if stream == :err
|
62
84
|
ch[:options][:logger].send(:important, out, "#{stream} :: #{ch[:server]}" )
|
63
85
|
else
|
@@ -76,13 +98,14 @@ configuration.load do
|
|
76
98
|
|
77
99
|
desc "Imports the database from your local server to the remote one"
|
78
100
|
task :put, :roles => :db, :only => {:primary => true} do
|
79
|
-
run "mysqldump --set-charset #{
|
101
|
+
run "mysqldump --set-charset #{remote_db_options} #{remote_db_name} > #{current_path}/#{release_name}.sql" rescue nil
|
80
102
|
|
81
103
|
dump = StringIO.new(run_locally "mysqldump --set-charset #{db_name}")
|
82
104
|
dump_path = "#{shared_path}/db_upload.tmp.sql"
|
83
105
|
upload dump, dump_path
|
106
|
+
|
84
107
|
run %{
|
85
|
-
mysql #{
|
108
|
+
mysql #{options} #{real_db_name} < #{dump_path} &&
|
86
109
|
rm #{dump_path}
|
87
110
|
}
|
88
111
|
end
|
data/sumodev_deploy.gemspec
CHANGED