sumodev_deploy 0.2.6 → 0.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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) { fetch(:stage, 'production').to_sym == :staging ? 1 : 3 }
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 #{db_name}" do |ch, stream, out|
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 #{db_name} > #{current_path}/#{release_name}.sql" rescue nil
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 #{db_name} < #{dump_path} &&
108
+ mysql #{options} #{real_db_name} < #{dump_path} &&
86
109
  rm #{dump_path}
87
110
  }
88
111
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "sumodev_deploy"
5
- s.version = "0.2.6"
5
+ s.version = "0.2.7"
6
6
 
7
7
  s.authors = ["Jan De Poorter"]
8
8
  s.date = "2012-04-18"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sumodev_deploy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: