nomagic_capistrano_recipes 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,172 +2,162 @@ require "nomagic_capistrano_recipes/version"
2
2
 
3
3
  module NomagicCapistranoRecipes
4
4
 
5
- Capistrano::Configuration.instance(:must_exist).load do
6
- set :enable_local_db_export, false
7
- set :enable_local_asset_export, false
8
-
9
- namespace :import do
10
- desc "Dump remote database and import to local"
11
- task :remote_database do
12
- puts "-----------------------------------------------------------------------------------------"
13
- puts "Importing database from #{domain} to local machine"
14
- puts "-----------------------------------------------------------------------------------------"
15
-
16
- get("#{shared_path}/config/database.yml", "tmp/#{stage}-database.yml")
17
-
18
- remote_settings = YAML::load_file("tmp/#{stage}-database.yml")["#{rails_env}"]
19
- local_settings = YAML::load_file("config/database.yml")["development"]
20
-
21
- # Dump on remote
22
- puts "-----------------------------------------------------------------------------------------"
23
- puts "Dumping database on #{domain}"
24
- puts "-----------------------------------------------------------------------------------------"
25
- run "mysqldump -u#{remote_settings["username"]} #{"-p#{remote_settings["password"]}" if remote_settings["password"]} #{"-h#{remote_settings['host']}" if remote_settings['host']} #{remote_settings["database"]} > #{shared_path}/tmp/#{stage}-#{remote_settings["database"]}-dump.sql"
26
-
27
- # Rsync to local
28
- puts "-----------------------------------------------------------------------------------------"
29
- puts "Rsyncing database from #{domain} to local"
30
- puts "-----------------------------------------------------------------------------------------"
31
- run_locally("rsync --times --rsh='ssh -p#{port}' --compress --human-readable --progress #{user}@#{domain}:#{shared_path}/tmp/#{stage}-#{remote_settings["database"]}-dump.sql tmp/#{stage}-#{remote_settings["database"]}-dump.sql")
32
-
33
- # Update database on local
34
- puts "-----------------------------------------------------------------------------------------"
35
- puts "Updating database on local"
36
- puts "-----------------------------------------------------------------------------------------"
37
- run_locally("mysql -u#{local_settings["username"]} #{"-p#{local_settings["password"]}" if local_settings["password"]} #{"-h#{local_settings['host']}" if local_settings['host']} #{local_settings["database"]} < tmp/#{stage}-#{remote_settings["database"]}-dump.sql")
38
-
39
- # Remove temporary files
40
- puts "-----------------------------------------------------------------------------------------"
41
- puts "Removing temporary files"
42
- puts "-----------------------------------------------------------------------------------------"
43
- run "rm #{shared_path}/tmp/#{stage}-#{remote_settings["database"]}-dump.sql"
44
- run_locally("rm tmp/#{stage}-#{remote_settings["database"]}-dump.sql")
45
- run_locally("rm tmp/#{stage}-database.yml")
46
- end
47
-
48
- desc "Download remote (system) assets to local machine"
49
- task :remote_assets do
50
- puts "-----------------------------------------------------------------------------------------"
51
- puts "Importing assets from #{domain} to local machine"
52
- puts "-----------------------------------------------------------------------------------------"
53
- system "rsync --recursive --times --rsh='ssh -p#{port}' --delete --compress --human-readable --progress #{user}@#{domain}:#{shared_path}/system/ public/system/"
54
- end
55
- end
56
-
57
- namespace :export do
58
- desc "Dump local database and export to remote"
59
- task :local_database do
60
- if enable_local_db_export
61
-
62
- # Confirm that we really want to override the database
5
+ if Capistrano::Configuration.instance
6
+ Capistrano::Configuration.instance(:must_exist).load do
7
+ namespace :import do
8
+ desc "Dump remote database and import to local"
9
+ task :remote_database do
63
10
  puts "-----------------------------------------------------------------------------------------"
64
- puts "Do you really want to override #{stage} database with your local version?"
11
+ puts "Importing database from #{domain} to local machine"
65
12
  puts "-----------------------------------------------------------------------------------------"
66
- set :continue, Proc.new { Capistrano::CLI.ui.ask(' continue (y/n): ') }
67
- abort "Export to #{stage} was stopped" unless continue == 'y'
68
13
 
69
- # If stage is production - double check that we want to do this
70
- if "#{stage}" == 'production'
71
- puts "-----------------------------------------------------------------------------------------"
72
- puts "WARNING: You are overriding the PRODUCTION database, are you COMPLETELY sure?"
73
- puts "-----------------------------------------------------------------------------------------"
74
- set :continue, Proc.new { Capistrano::CLI.ui.ask('continue (y/n): ') }
75
- abort "Export to production was stopped" unless continue == 'y'
76
- end
77
-
78
- puts "-----------------------------------------------------------------------------------------"
79
- puts "Exporting database from local machine to #{domain}"
80
- puts "-----------------------------------------------------------------------------------------"
81
-
82
14
  get("#{shared_path}/config/database.yml", "tmp/#{stage}-database.yml")
83
-
15
+
84
16
  remote_settings = YAML::load_file("tmp/#{stage}-database.yml")["#{rails_env}"]
85
17
  local_settings = YAML::load_file("config/database.yml")["development"]
86
18
 
87
- # Dump local database
88
19
  puts "-----------------------------------------------------------------------------------------"
89
- puts "Dumping local database"
20
+ puts "Dumping database on #{domain}"
90
21
  puts "-----------------------------------------------------------------------------------------"
91
- run_locally("mysqldump -u#{local_settings['username']} #{"-p#{local_settings['password']}" if local_settings['password']} #{"-h#{local_settings['host']}" if local_settings['host']} #{local_settings['database']} > tmp/local-#{local_settings['database']}-dump.sql")
22
+ run "mysqldump -u#{remote_settings["username"]} #{"-p#{remote_settings["password"]}" if remote_settings["password"]} #{"-h#{remote_settings['host']}" if remote_settings['host']} #{remote_settings["database"]} > #{shared_path}/tmp/#{stage}-#{remote_settings["database"]}-dump.sql"
92
23
 
93
- # Rsync to remote
94
24
  puts "-----------------------------------------------------------------------------------------"
95
- puts "Rsyncing database from local to #{domain}"
25
+ puts "Rsyncing database from #{domain} to local"
96
26
  puts "-----------------------------------------------------------------------------------------"
97
- run_locally("rsync --times --rsh='ssh -p#{port}' --compress --human-readable --progress tmp/local-#{local_settings["database"]}-dump.sql #{user}@#{domain}:#{shared_path}/tmp/local-#{local_settings["database"]}-dump.sql")
27
+ run_locally("rsync --times --rsh='ssh -p#{port}' --compress --human-readable --progress #{user}@#{domain}:#{shared_path}/tmp/#{stage}-#{remote_settings["database"]}-dump.sql tmp/#{stage}-#{remote_settings["database"]}-dump.sql")
98
28
 
99
- # Update database on remote
100
29
  puts "-----------------------------------------------------------------------------------------"
101
- puts "Updating database on #{domain}"
30
+ puts "Updating database on local"
102
31
  puts "-----------------------------------------------------------------------------------------"
103
- run "mysql -u#{remote_settings['username']} #{"-p#{remote_settings['password']}" if remote_settings['password']} #{"-h#{remote_settings['host']}" if remote_settings['host']} #{remote_settings["database"]} < #{shared_path}/tmp/local-#{local_settings["database"]}-dump.sql"
104
-
105
- # Remove temporary files
32
+ run_locally("mysql -u#{local_settings["username"]} #{"-p#{local_settings["password"]}" if local_settings["password"]} #{"-h#{local_settings['host']}" if local_settings['host']} #{local_settings["database"]} < tmp/#{stage}-#{remote_settings["database"]}-dump.sql")
33
+
106
34
  puts "-----------------------------------------------------------------------------------------"
107
35
  puts "Removing temporary files"
108
36
  puts "-----------------------------------------------------------------------------------------"
109
- run_locally("rm tmp/local-#{local_settings["database"]}-dump.sql")
37
+ run "rm #{shared_path}/tmp/#{stage}-#{remote_settings["database"]}-dump.sql"
38
+ run_locally("rm tmp/#{stage}-#{remote_settings["database"]}-dump.sql")
110
39
  run_locally("rm tmp/#{stage}-database.yml")
111
- run "rm #{shared_path}/tmp/local-#{local_settings["database"]}-dump.sql"
112
- else
40
+ end
41
+
42
+ desc "Download remote (system) assets to local machine"
43
+ task :remote_assets do
113
44
  puts "-----------------------------------------------------------------------------------------"
114
- puts "NOTE: exporting your local database to #{stage} is disabled"
45
+ puts "Importing assets from #{domain} to local machine"
115
46
  puts "-----------------------------------------------------------------------------------------"
47
+ system "rsync --recursive --times --rsh='ssh -p#{port}' --delete --compress --human-readable --progress #{user}@#{domain}:#{shared_path}/system/ public/system/"
116
48
  end
117
49
  end
118
50
 
119
- desc "Downloads remote (system) assets to the local development machine"
120
- task :local_assets do
121
- if enable_local_asset_export
122
- # Confirm that we really want to upload local assets
123
- puts "-----------------------------------------------------------------------------------------"
124
- puts "Do you really want to upload local assets to #{stage} at #{domain}?"
125
- puts "-----------------------------------------------------------------------------------------"
126
- set :continue, Proc.new { Capistrano::CLI.ui.ask(' continue (y/n): ') }
127
- abort "Export to #{stage} was stopped" unless continue == 'y'
51
+ namespace :export do
52
+ set :enable_local_db_export, false
53
+ set :enable_local_asset_export, false
54
+
55
+ desc "Dump local database and export to remote"
56
+ task :local_database do
57
+ if enable_local_db_export
58
+
59
+ puts "-----------------------------------------------------------------------------------------"
60
+ puts "Do you really want to override #{stage} database with your local version?"
61
+ puts "-----------------------------------------------------------------------------------------"
62
+ set :continue, Proc.new { Capistrano::CLI.ui.ask(' continue (y/n): ') }
63
+ abort "Export to #{stage} was stopped" unless continue == 'y'
64
+
65
+ if "#{stage}" == 'production'
66
+ puts "-----------------------------------------------------------------------------------------"
67
+ puts "WARNING: You are overriding the PRODUCTION database, are you COMPLETELY sure?"
68
+ puts "-----------------------------------------------------------------------------------------"
69
+ set :continue, Proc.new { Capistrano::CLI.ui.ask('continue (y/n): ') }
70
+ abort "Export to production was stopped" unless continue == 'y'
71
+ end
72
+
73
+ puts "-----------------------------------------------------------------------------------------"
74
+ puts "Exporting database from local machine to #{domain}"
75
+ puts "-----------------------------------------------------------------------------------------"
76
+
77
+ get("#{shared_path}/config/database.yml", "tmp/#{stage}-database.yml")
78
+
79
+ remote_settings = YAML::load_file("tmp/#{stage}-database.yml")["#{rails_env}"]
80
+ local_settings = YAML::load_file("config/database.yml")["development"]
81
+
82
+ puts "-----------------------------------------------------------------------------------------"
83
+ puts "Dumping local database"
84
+ puts "-----------------------------------------------------------------------------------------"
85
+ run_locally("mysqldump -u#{local_settings['username']} #{"-p#{local_settings['password']}" if local_settings['password']} #{"-h#{local_settings['host']}" if local_settings['host']} #{local_settings['database']} > tmp/local-#{local_settings['database']}-dump.sql")
86
+
87
+ puts "-----------------------------------------------------------------------------------------"
88
+ puts "Rsyncing database from local to #{domain}"
89
+ puts "-----------------------------------------------------------------------------------------"
90
+ run_locally("rsync --times --rsh='ssh -p#{port}' --compress --human-readable --progress tmp/local-#{local_settings["database"]}-dump.sql #{user}@#{domain}:#{shared_path}/tmp/local-#{local_settings["database"]}-dump.sql")
91
+
92
+ puts "-----------------------------------------------------------------------------------------"
93
+ puts "Updating database on #{domain}"
94
+ puts "-----------------------------------------------------------------------------------------"
95
+ run "mysql -u#{remote_settings['username']} #{"-p#{remote_settings['password']}" if remote_settings['password']} #{"-h#{remote_settings['host']}" if remote_settings['host']} #{remote_settings["database"]} < #{shared_path}/tmp/local-#{local_settings["database"]}-dump.sql"
128
96
 
129
- # If stage is production - double check that we want to do this
130
- if "#{stage}" == 'production'
131
97
  puts "-----------------------------------------------------------------------------------------"
132
- puts "WARNING: You are overriding the PRODUCTION assets, are you COMPLETELY sure?"
98
+ puts "Removing temporary files"
99
+ puts "-----------------------------------------------------------------------------------------"
100
+ run_locally("rm tmp/local-#{local_settings["database"]}-dump.sql")
101
+ run_locally("rm tmp/#{stage}-database.yml")
102
+ run "rm #{shared_path}/tmp/local-#{local_settings["database"]}-dump.sql"
103
+ else
104
+ puts "-----------------------------------------------------------------------------------------"
105
+ puts "NOTE: exporting your local database to #{stage} is disabled"
133
106
  puts "-----------------------------------------------------------------------------------------"
134
- set :continue, Proc.new { Capistrano::CLI.ui.ask('continue (y/n): ') }
135
- abort "Export to production was stopped" unless continue == 'y'
136
107
  end
108
+ end
137
109
 
138
- puts "-----------------------------------------------------------------------------------------"
139
- puts "Exporting assets from local machine to #{domain}"
140
- puts "-----------------------------------------------------------------------------------------"
141
- system "rsync --recursive --times --rsh='ssh -p#{port}' --delete --compress --human-readable --progress public/system/ #{user}@#{domain}:#{shared_path}/system/"
142
- else
143
- puts "-----------------------------------------------------------------------------------------"
144
- puts "NOTE: exporting your local assets to #{stage} is disabled"
145
- puts "-----------------------------------------------------------------------------------------"
110
+ desc "Downloads remote (system) assets to the local development machine"
111
+ task :local_assets do
112
+ if enable_local_asset_export
113
+ puts "-----------------------------------------------------------------------------------------"
114
+ puts "Do you really want to upload local assets to #{stage} at #{domain}?"
115
+ puts "-----------------------------------------------------------------------------------------"
116
+ set :continue, Proc.new { Capistrano::CLI.ui.ask(' continue (y/n): ') }
117
+ abort "Export to #{stage} was stopped" unless continue == 'y'
118
+
119
+ if "#{stage}" == 'production'
120
+ puts "-----------------------------------------------------------------------------------------"
121
+ puts "WARNING: You are overriding the PRODUCTION assets, are you COMPLETELY sure?"
122
+ puts "-----------------------------------------------------------------------------------------"
123
+ set :continue, Proc.new { Capistrano::CLI.ui.ask('continue (y/n): ') }
124
+ abort "Export to production was stopped" unless continue == 'y'
125
+ end
126
+
127
+ puts "-----------------------------------------------------------------------------------------"
128
+ puts "Exporting assets from local machine to #{domain}"
129
+ puts "-----------------------------------------------------------------------------------------"
130
+ system "rsync --recursive --times --rsh='ssh -p#{port}' --delete --compress --human-readable --progress public/system/ #{user}@#{domain}:#{shared_path}/system/"
131
+ else
132
+ puts "-----------------------------------------------------------------------------------------"
133
+ puts "NOTE: exporting your local assets to #{stage} is disabled"
134
+ puts "-----------------------------------------------------------------------------------------"
135
+ end
146
136
  end
147
137
  end
148
- end
149
138
 
150
- namespace :unicorn do
151
- set(:unicorn_conf) { "#{deploy_to}/#{shared_dir}/config/unicorn.rb" }
152
- set(:unicorn_pid) { "#{deploy_to}/#{shared_dir}/pids/unicorn.pid" }
139
+ namespace :unicorn do
140
+ set(:unicorn_conf) { "#{deploy_to}/#{shared_dir}/config/unicorn.rb" }
141
+ set(:unicorn_pid) { "#{deploy_to}/#{shared_dir}/pids/unicorn.pid" }
153
142
 
154
- task :restart do
155
- puts "-----------------------------------------------------------------------------------------"
156
- puts "Restarting unicorn"
157
- puts "-----------------------------------------------------------------------------------------"
158
- run "if [ -f #{unicorn_pid} ] && [ -e /proc/$(cat #{unicorn_pid}) ]; then kill -USR2 `cat #{unicorn_pid}`; else cd #{deploy_to}/current && bundle exec unicorn -c #{unicorn_conf} -E #{rails_env} -D; fi"
159
- end
160
- task :start do
161
- puts "-----------------------------------------------------------------------------------------"
162
- puts "Starting unicorn"
163
- puts "-----------------------------------------------------------------------------------------"
164
- run "cd #{deploy_to}/current && bundle exec unicorn -c #{unicorn_conf} -E #{rails_env} -D"
165
- end
166
- task :stop do
167
- puts "-----------------------------------------------------------------------------------------"
168
- puts "Stopping unicorn"
169
- puts "-----------------------------------------------------------------------------------------"
170
- run "if [ -f #{unicorn_pid} ] && [ -e /proc/$(cat #{unicorn_pid}) ]; then kill -QUIT `cat #{unicorn_pid}`; fi"
143
+ task :restart do
144
+ puts "-----------------------------------------------------------------------------------------"
145
+ puts "Restarting unicorn"
146
+ puts "-----------------------------------------------------------------------------------------"
147
+ run "if [ -f #{unicorn_pid} ] && [ -e /proc/$(cat #{unicorn_pid}) ]; then kill -USR2 `cat #{unicorn_pid}`; else cd #{deploy_to}/current && bundle exec unicorn -c #{unicorn_conf} -E #{rails_env} -D; fi"
148
+ end
149
+ task :start do
150
+ puts "-----------------------------------------------------------------------------------------"
151
+ puts "Starting unicorn"
152
+ puts "-----------------------------------------------------------------------------------------"
153
+ run "cd #{deploy_to}/current && bundle exec unicorn -c #{unicorn_conf} -E #{rails_env} -D"
154
+ end
155
+ task :stop do
156
+ puts "-----------------------------------------------------------------------------------------"
157
+ puts "Stopping unicorn"
158
+ puts "-----------------------------------------------------------------------------------------"
159
+ run "if [ -f #{unicorn_pid} ] && [ -e /proc/$(cat #{unicorn_pid}) ]; then kill -QUIT `cat #{unicorn_pid}`; fi"
160
+ end
171
161
  end
172
162
  end
173
163
  end
@@ -1,3 +1,3 @@
1
1
  module NomagicCapistranoRecipes
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nomagic_capistrano_recipes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-16 00:00:00.000000000 Z
12
+ date: 2012-09-17 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Useful capistrano recipes
15
15
  email: