capistrano-exts 1.1.5 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -64,11 +64,11 @@ Capistrano::Configuration.instance(:must_exist).load do
64
64
  end
65
65
 
66
66
  # Helper for some mysql tasks
67
- def mysql_credentials
67
+ def mysql_credentials_formatted(mysql_credentials)
68
68
  return <<-EOS
69
- hostname: localhost
70
- username: #{mysql_db_user}
71
- password: #{fetch :mysql_db_pass}
69
+ hostname: #{mysql_credentials[:host]}
70
+ username: #{mysql_credentials[:user]}
71
+ password: #{mysql_credentials[:pass]}
72
72
  EOS
73
73
  end
74
74
  end
@@ -55,7 +55,24 @@ Capistrano::Configuration.instance(:must_exist).load do
55
55
  '#{mysql_db_name}'
56
56
  CMD
57
57
  rescue
58
- puts "WARNING: The database doesn't exist."
58
+ puts "WARNING: The database doesn't exist or you do not have permissions to drop it, trying to drop all tables inside of it."
59
+ begin
60
+ run <<-CMD
61
+ mysqldump \
62
+ --host='#{mysql_credentials[:host]}' \
63
+ --user='#{mysql_credentials[:user]}' \
64
+ --password='#{mysql_credentials[:pass]}' \
65
+ --add-drop-table --no-data '#{mysql_db_name}' |\
66
+ grep '^DROP' | \
67
+ mysql \
68
+ --host='#{mysql_credentials[:host]}' \
69
+ --user='#{mysql_credentials[:user]}' \
70
+ --password='#{mysql_credentials[:pass]}' \
71
+ '#{mysql_db_name}'
72
+ CMD
73
+ rescue
74
+ puts "WARNING: The database doesn't exist or you do not have permissions to drop it."
75
+ end
59
76
  end
60
77
  end
61
78
  end
@@ -94,31 +111,22 @@ Capistrano::Configuration.instance(:must_exist).load do
94
111
  rm -f #{random_file}
95
112
  CMD
96
113
 
97
- find_and_execute_task("mysql:write_db_credentials")
114
+ set :mysql_credentials, {
115
+ # TODO: The host is not always localhost, it should be the primary
116
+ # database server
117
+ host: 'localhost',
118
+ user: mysql_db_user,
119
+ pass: fetch(:mysql_db_pass),
120
+ }
121
+
122
+ find_and_execute_task("mysql:write_credentials")
98
123
  rescue
99
- puts "WARNING: The user #{application} already exists."
100
- find_and_execute_task("mysql:print_db_credentials")
124
+ puts "WARNING: The user #{application} already exists or you do not have permissions to create it."
125
+ find_and_execute_task("mysql:print_credentials")
101
126
  end
102
127
  end
103
128
  end
104
129
 
105
- desc "write database credentials"
106
- task :write_db_credentials do
107
- mysql_credentials_file = fetch :mysql_credentials_file
108
- unless exists?(:mysql_credentials_file) and remote_file_exists?(mysql_credentials_file)
109
- put mysql_credentials, mysql_credentials_file
110
- end
111
- end
112
-
113
- desc "print database credentials"
114
- task :print_db_credentials do
115
- mysql_credentials_file = fetch :mysql_credentials_file
116
- unless exists?(:mysql_credentials_file) and remote_file_exists?(mysql_credentials_file)
117
- puts "WARNING: mysql_credentials_file is not defined in config.rb you have to manually copy the following info into a credential file and define it"
118
- puts mysql_credentials
119
- end
120
- end
121
-
122
130
  desc "create database"
123
131
  task :create_db, :roles => :db, :except => { :no_release => true } do
124
132
  mysql_credentials = fetch :mysql_credentials
@@ -134,7 +142,7 @@ Capistrano::Configuration.instance(:must_exist).load do
134
142
  create '#{mysql_db_name}'
135
143
  CMD
136
144
  rescue
137
- puts "WARNING: The database already exists, it hasn't been modified, drop it manually if necessary."
145
+ puts "WARNING: The database already exists or you do not have permissions to create it."
138
146
  end
139
147
  end
140
148
  end
@@ -208,6 +216,25 @@ Capistrano::Configuration.instance(:must_exist).load do
208
216
  end
209
217
  end
210
218
 
219
+ # TODO: credentials and root_credentials are exactly the same code with
220
+ # one variable changing, we need some meta-programming for them!!
221
+
222
+ desc "print database credentials"
223
+ task :print_credentials do
224
+ puts mysql_credentials_formatted(fetch :mysql_credentials)
225
+ end
226
+
227
+ desc "[internal] write database credentials"
228
+ task :write_credentials do
229
+ mysql_credentials_file = fetch :mysql_credentials_file
230
+ unless exists?(:mysql_credentials_file) and remote_file_exists?(mysql_credentials_file)
231
+ put mysql_credentials_formatted(fetch :mysql_credentials), mysql_credentials_file
232
+ else
233
+ puts "WARNING: mysql_credentials_file is not defined in config.rb you have to manually copy the following info into a credential file and define it"
234
+ find_and_execute_task("mysql:print_credentials")
235
+ end
236
+ end
237
+
211
238
  desc "Get Mysql credentials"
212
239
  task :credentials, :roles => :app, :except => { :no_release => true } do
213
240
  mysql_credentials_file = fetch :mysql_credentials_file
@@ -230,31 +257,58 @@ Capistrano::Configuration.instance(:must_exist).load do
230
257
  user: mysql_credentials_file_contents.match(mysql_credentials_user_regex).try(:[], mysql_credentials_user_regex_match).try(:chomp),
231
258
  pass: mysql_credentials_file_contents.match(mysql_credentials_pass_regex).try(:[], mysql_credentials_pass_regex_match).try(:chomp),
232
259
  }
233
-
234
- if mysql_credentials[:user].present? and mysql_credentials[:pass].present?
235
- set :mysql_credentials, mysql_credentials
236
- end
237
260
  end
238
261
  end
239
262
  end
240
263
 
241
264
  # Verify that we got them!
242
- if !exists?(:mysql_credentials)
243
- set :mysql_credentials, {
244
- host: ask("What is the hostname used to access the database", default: 'localhost', validate: /.+/),
245
- user: ask("What is the username used to access the database", default: nil, validate: /.+/),
246
- pass: ask("What is the password used to access the database", default: nil, validate: /.+/, echo: false),
265
+ if mysql_credentials.blank? or mysql_credentials[:user].blank? or mysql_credentials[:pass].blank?
266
+ mysql_credentials = {
267
+ host: ask("What is the hostname used to access the database",
268
+ default: mysql_credentials.try(:[], :host) || 'localhost',
269
+ validate: /.+/),
270
+ user: ask("What is the username used to access the database",
271
+ default: mysql_credentials.try(:[], :user),
272
+ validate: /.+/),
273
+ pass: ask("What is the password used to access the database",
274
+ default: mysql_credentials.try(:[], :pass),
275
+ validate: /.+/,
276
+ echo: false),
247
277
  }
248
278
  end
279
+
280
+ # Finally set it so it's available and write it to the server.
281
+ if mysql_credentials[:user].present? and mysql_credentials[:pass].present?
282
+ set :mysql_credentials, mysql_credentials
283
+ find_and_execute_task("mysql:write_credentials")
284
+ end
285
+ end
286
+ end
287
+
288
+ # REFACTOR!!
289
+ desc "print database root credentials"
290
+ task :print_root_credentials do
291
+ puts mysql_credentials_formatted(fetch :mysql_root_credentials)
292
+ end
293
+
294
+ desc "[internal] write database root credentials"
295
+ task :write_root_credentials do
296
+ mysql_root_credentials = fetch :mysql_root_credentials
297
+ mysql_root_credentials_file = fetch :mysql_root_credentials_file
298
+ unless exists?(:mysql_root_credentials_file) and remote_file_exists?(mysql_root_credentials_file)
299
+ put mysql_credentials_formatted(fetch :mysql_root_credentials), mysql_root_credentials_file
300
+ else
301
+ puts "WARNING: mysql_root_credentials_file is not defined in config.rb you have to manually copy the following info into a credential file and define it"
302
+ find_and_execute_task("mysql:print_root_credentials")
249
303
  end
250
304
  end
251
305
 
252
- desc "Get Mysql root credentials"
306
+ desc "Get Mysql root_credentials"
253
307
  task :root_credentials, :roles => :app, :except => { :no_release => true } do
254
308
  mysql_root_credentials_file = fetch :mysql_root_credentials_file
255
309
 
256
310
  unless exists?(:mysql_root_credentials)
257
- # We haven't got the credentials yet, look for them
311
+ # We haven't got the root_credentials yet, look for them
258
312
  if exists?(:mysql_root_credentials_file) and remote_file_exists?(mysql_root_credentials_file)
259
313
  begin
260
314
  set :mysql_root_credentials_file_contents, capture("cat #{mysql_root_credentials_file}")
@@ -264,30 +318,42 @@ Capistrano::Configuration.instance(:must_exist).load do
264
318
 
265
319
  if exists?(:mysql_root_credentials_file_contents)
266
320
  mysql_root_credentials_file_contents = fetch :mysql_root_credentials_file_contents
321
+
267
322
  unless mysql_root_credentials_file_contents.blank?
268
323
  mysql_root_credentials = {
269
324
  host: mysql_root_credentials_file_contents.match(mysql_root_credentials_host_regex).try(:[], mysql_root_credentials_host_regex_match).try(:chomp),
270
325
  user: mysql_root_credentials_file_contents.match(mysql_root_credentials_user_regex).try(:[], mysql_root_credentials_user_regex_match).try(:chomp),
271
326
  pass: mysql_root_credentials_file_contents.match(mysql_root_credentials_pass_regex).try(:[], mysql_root_credentials_pass_regex_match).try(:chomp),
272
327
  }
273
-
274
- if mysql_root_credentials[:user].present? and mysql_root_credentials[:pass].present?
275
- set :mysql_root_credentials, mysql_root_credentials
276
- end
277
328
  end
278
329
  end
279
330
  end
280
331
 
281
332
  # Verify that we got them!
282
- if !exists?(:mysql_root_credentials)
283
- set :mysql_root_credentials, {
284
- host: ask("What is the hostname used to access the database", default: 'localhost', validate: /.+/),
285
- user: ask("What is the username used to access the database", default: nil, validate: /.+/),
286
- pass: ask("What is the password used to access the database", default: nil, validate: /.+/, echo: false),
333
+ if mysql_root_credentials.blank? or mysql_root_credentials[:user].blank? or mysql_root_credentials[:pass].blank?
334
+ mysql_root_credentials = {
335
+ host: ask("What is the hostname used to access the database",
336
+ default: mysql_root_credentials.try(:[], :host) || 'localhost',
337
+ validate: /.+/),
338
+ user: ask("What is the username used to access the database",
339
+ default: mysql_root_credentials.try(:[], :user),
340
+ validate: /.+/),
341
+ pass: ask("What is the password used to access the database",
342
+ default: mysql_root_credentials.try(:[], :pass),
343
+ validate: /.+/,
344
+ echo: false),
287
345
  }
288
346
  end
347
+
348
+ # Finally set it so it's available and write it to the server.
349
+ if mysql_root_credentials[:user].present? and mysql_root_credentials[:pass].present?
350
+ set :mysql_root_credentials, mysql_root_credentials
351
+ find_and_execute_task("mysql:write_root_credentials")
352
+ end
289
353
  end
290
354
  end
355
+ # REFACTOR!!
356
+
291
357
  end
292
358
 
293
359
  before "mysql:backup_db", "mysql:credentials"
@@ -297,4 +363,7 @@ Capistrano::Configuration.instance(:must_exist).load do
297
363
  before "mysql:export_db_dump", "mysql:backup_db"
298
364
  before "mysql:create_db_user", "mysql:root_credentials"
299
365
  after "mysql:create_db_user", "mysql:create_db"
366
+
367
+ before "mysql:print_credentials", "mysql:credentials"
368
+ before "mysql:print_root_credentials", "mysql:root_credentials"
300
369
  end
@@ -94,6 +94,11 @@ Capistrano::Configuration.instance(:must_exist).load do
94
94
  end
95
95
  end
96
96
 
97
+ desc "print authentification file"
98
+ task :print_web_server_auth_file do
99
+ puts capture("cat #{fetch :deploy_to}/.http_basic_auth")
100
+ end
101
+
97
102
  desc "[internal] Write web configuration file"
98
103
  task :write_web_conf_file do
99
104
  if exists?(:web_conf_file)
@@ -2,8 +2,8 @@ module Capistrano
2
2
  module Extensions
3
3
  module Version #:nodoc:
4
4
  MAJOR = 1
5
- MINOR = 1
6
- TINY = 5
5
+ MINOR = 2
6
+ TINY = 0
7
7
 
8
8
  ARRAY = [MAJOR, MINOR, TINY]
9
9
  STRING = ARRAY.join(".")
data/spec/spec_helper.rb CHANGED
@@ -19,7 +19,7 @@ RSpec.configure do |config|
19
19
  #
20
20
  # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
21
21
  #
22
- config.mock_with :mocha
22
+ # config.mock_with :mocha
23
23
  # config.mock_with :flexmock
24
24
  # config.mock_with :rr
25
25
  # config.mock_with :rspec
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-exts
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.5
4
+ version: 1.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-03 00:00:00.000000000 Z
12
+ date: 2011-09-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capistrano
16
- requirement: &2157484500 !ruby/object:Gem::Requirement
16
+ requirement: &2160791120 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 2.8.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2157484500
24
+ version_requirements: *2160791120
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: i18n
27
- requirement: &2157484000 !ruby/object:Gem::Requirement
27
+ requirement: &2160790620 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 0.6.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2157484000
35
+ version_requirements: *2160790620
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: activesupport
38
- requirement: &2157483540 !ruby/object:Gem::Requirement
38
+ requirement: &2160790160 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 3.1.0
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *2157483540
46
+ version_requirements: *2160790160
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: guard
49
- requirement: &2157483080 !ruby/object:Gem::Requirement
49
+ requirement: &2160789700 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 0.6.2
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *2157483080
57
+ version_requirements: *2160789700
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: guard-bundler
60
- requirement: &2157482620 !ruby/object:Gem::Requirement
60
+ requirement: &2160789240 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 0.1.3
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *2157482620
68
+ version_requirements: *2160789240
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: guard-rspec
71
- requirement: &2157482160 !ruby/object:Gem::Requirement
71
+ requirement: &2160788780 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: 0.4.3
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *2157482160
79
+ version_requirements: *2160788780
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: rspec
82
- requirement: &2157481700 !ruby/object:Gem::Requirement
82
+ requirement: &2160788320 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,7 +87,7 @@ dependencies:
87
87
  version: 2.6.0
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *2157481700
90
+ version_requirements: *2160788320
91
91
  description: Handy extensions for Capistrano
92
92
  email:
93
93
  - wael.nasreddine@gmail.com