capistrano-exts 1.7.0 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -17,7 +17,7 @@ gem install capistrano-exts
17
17
  or add it to your Gemfile
18
18
 
19
19
  ```ruby
20
- gem 'capistrano-exts', '>=1.7.0'
20
+ gem 'capistrano-exts', '>=1.8.0'
21
21
  ```
22
22
 
23
23
  Setup
@@ -74,4 +74,9 @@ Capistrano::Configuration.instance(:must_exist).load do
74
74
  password: #{mysql_credentials[:pass]}
75
75
  EOS
76
76
  end
77
+
78
+ # Read a remote file
79
+ def read(file)
80
+ capture("cat #{file}")
81
+ end
77
82
  end
@@ -21,7 +21,7 @@ Capistrano::Configuration.instance(:must_exist).load do
21
21
  desc "Check if this revision has already been deployed."
22
22
  task :check_revision, :roles => :app, :except => { :no_release => true } do
23
23
  if remote_file_exists?("#{deploy_to}/current/REVISION")
24
- if `git rev-parse #{branch}`.strip == capture("cat #{deploy_to}/current/REVISION").strip
24
+ if `git rev-parse #{branch}`.strip == read("#{deploy_to}/current/REVISION").strip
25
25
  response = ask("The verison you are trying to deploy is already deployed, should I continue (Yes, [No], Abort)", default: 'No')
26
26
  if response =~ /(no?)|(a(bort)?|\n)/i
27
27
  abort "Canceled by the user."
@@ -250,165 +250,94 @@ Capistrano::Configuration.instance(:must_exist).load do
250
250
  end
251
251
  end
252
252
 
253
- # TODO: credentials and root_credentials are exactly the same code with
254
- # one variable changing, we need some meta-programming for them!!
255
-
256
- desc "print database credentials"
257
- task :print_credentials do
258
- puts mysql_credentials_formatted(fetch :mysql_credentials)
259
- end
260
-
261
- desc "[internal] write database credentials"
262
- task :write_credentials do
263
- unless exists?(:mysql_credentials_file) and remote_file_exists?(fetch :mysql_credentials_file)
264
- mysql_credentials_file = fetch :mysql_credentials_file
265
- random_file = random_tmp_file(mysql_credentials_formatted(fetch :mysql_credentials))
266
- put mysql_credentials_formatted(fetch :mysql_credentials), random_file
267
-
268
- begin
269
- run <<-CMD
270
- #{try_sudo} cp #{random_file} #{mysql_credentials_file}; \
271
- #{try_sudo} rm -f #{random_file}
272
- CMD
273
- rescue Capistrano::CommandError
274
- puts "WARNING: Apparently you do not have permissions to write to #{mysql_credentials_file}."
275
- find_and_execute_task("mysql:print_credentials")
276
- end
277
- else
278
- puts "WARNING: mysql_credentials_file is not defined or it already exists on the server."
279
- find_and_execute_task("mysql:print_credentials")
253
+ ['credentials', 'root_credentials'].each do |var|
254
+ desc "print database #{var.gsub(/_/, ' ')}"
255
+ task "print_#{var}" do
256
+ puts mysql_credentials_formatted(fetch "mysql_#{var}".to_sym)
280
257
  end
281
- end
282
258
 
283
- desc "Get Mysql credentials"
284
- task :credentials, :roles => :app, :except => { :no_release => true } do
285
- unless exists?(:mysql_credentials)
286
- # We haven't got the credentials yet, look for them
287
- if exists?(:mysql_credentials_file) and remote_file_exists?(fetch :mysql_credentials_file)
288
- mysql_credentials_file = fetch :mysql_credentials_file
259
+ desc "[internal] write database #{var.gsub(/_/, ' ')}"
260
+ task "write_#{var}" do
261
+ unless exists?("mysql_#{var}_file".to_sym) and remote_file_exists?(fetch "mysql_#{var}_file".to_sym)
262
+ mysql_credentials_file = fetch "mysql_#{var}_file".to_sym
263
+ random_file = random_tmp_file(mysql_credentials_formatted(fetch "mysql_#{var}".to_sym))
264
+ put mysql_credentials_formatted(fetch "mysql_#{var}".to_sym), random_file
289
265
 
290
266
  begin
291
- set :mysql_credentials_file_contents, capture("cat #{mysql_credentials_file}")
267
+ run <<-CMD
268
+ #{try_sudo} cp #{random_file} #{mysql_credentials_file}; \
269
+ #{try_sudo} rm -f #{random_file}
270
+ CMD
292
271
  rescue Capistrano::CommandError
293
- set :mysql_credentials, false
272
+ puts "WARNING: Apparently you do not have permissions to write to #{mysql_credentials_file}."
273
+ find_and_execute_task("mysql:print_#{var}")
294
274
  end
295
-
296
- if exists?(:mysql_credentials_file_contents)
297
- mysql_credentials_file_contents = fetch :mysql_credentials_file_contents
298
-
299
- unless mysql_credentials_file_contents.blank?
300
- mysql_credentials = {
301
- host: mysql_credentials_file_contents.match(mysql_credentials_host_regex).try(:[], mysql_credentials_host_regex_match).try(:chomp),
302
- user: mysql_credentials_file_contents.match(mysql_credentials_user_regex).try(:[], mysql_credentials_user_regex_match).try(:chomp),
303
- pass: mysql_credentials_file_contents.match(mysql_credentials_pass_regex).try(:[], mysql_credentials_pass_regex_match).try(:chomp),
304
- }
305
- end
306
- end
307
- end
308
-
309
- # Verify that we got them!
310
- if mysql_credentials.blank? or mysql_credentials[:user].blank? or mysql_credentials[:pass].blank?
311
- mysql_credentials = {
312
- host: ask("What is the hostname used to access the database",
313
- default: mysql_credentials.try(:[], :host) || fetch(:mysql_db_server, 'localhost'),
314
- validate: /.+/),
315
- user: ask("What is the username used to access the database",
316
- default: mysql_credentials.try(:[], :user) || fetch(:mysql_db_user),
317
- validate: /.+/),
318
- pass: ask("What is the password used to access the database",
319
- default: mysql_credentials.try(:[], :pass),
320
- validate: /.+/,
321
- echo: false),
322
- }
323
- end
324
-
325
- # Finally set it so it's available and write it to the server.
326
- if mysql_credentials[:user].present? and mysql_credentials[:pass].present?
327
- set :mysql_credentials, mysql_credentials
328
- find_and_execute_task("mysql:write_credentials")
275
+ else
276
+ puts "WARNING: mysql_#{var}_file is not defined or it already exists on the server."
277
+ find_and_execute_task("mysql:print_#{var}") unless ARGV.include?("mysql:print_#{var}")
329
278
  end
330
279
  end
331
- end
332
280
 
333
- # REFACTOR!!
334
- desc "print database root credentials"
335
- task :print_root_credentials do
336
- puts mysql_credentials_formatted(fetch :mysql_root_credentials)
337
- end
281
+ desc "Get Mysql #{var.gsub(/_/, ' ')}"
282
+ task "#{var}", :roles => :app, :except => { :no_release => true } do
283
+ unless exists?("mysql_#{var}".to_sym)
284
+ # Fetch configs
285
+ mysql_credentials_host_regex = fetch "mysql_#{var}_host_regex".to_sym
286
+ mysql_credentials_host_regex_match = fetch "mysql_#{var}_host_regex_match".to_sym
338
287
 
339
- desc "[internal] write database root credentials"
340
- task :write_root_credentials do
341
- unless exists?(:mysql_root_credentials_file) and remote_file_exists?(fetch :mysql_root_credentials_file)
342
- mysql_root_credentials_file = fetch :mysql_root_credentials_file
343
- random_file = random_tmp_file(mysql_credentials_formatted(fetch :mysql_root_credentials))
344
- put mysql_credentials_formatted(fetch :mysql_root_credentials), random_file
288
+ mysql_credentials_user_regex = fetch "mysql_#{var}_user_regex".to_sym
289
+ mysql_credentials_user_regex_match = fetch "mysql_#{var}_user_regex_match".to_sym
345
290
 
346
- begin
347
- run <<-CMD
348
- #{try_sudo} cp #{random_file} #{mysql_root_credentials_file}; \
349
- #{try_sudo} rm -f #{random_file}
350
- CMD
351
- rescue Capistrano::CommandError
352
- puts "WARNING: Apparently you do not have permissions to write to #{mysql_root_credentials_file}."
353
- find_and_execute_task("mysql:print_root_credentials")
354
- end
355
- else
356
- puts "WARNING: mysql_root_credentials_file is not defined or it already exists on the server."
357
- find_and_execute_task("mysql:print_root_credentials")
358
- end
359
- end
291
+ mysql_credentials_pass_regex = fetch "mysql_#{var}_pass_regex".to_sym
292
+ mysql_credentials_pass_regex_match = fetch "mysql_#{var}_pass_regex_match".to_sym
360
293
 
361
- desc "Get Mysql root_credentials"
362
- task :root_credentials, :roles => :app, :except => { :no_release => true } do
363
- unless exists?(:mysql_root_credentials)
364
- # We haven't got the root_credentials yet, look for them
365
- if exists?(:mysql_root_credentials_file) and remote_file_exists?(fetch :mysql_root_credentials_file)
366
- mysql_root_credentials_file = fetch :mysql_root_credentials_file
294
+ # We haven't got the credentials yet, look for them
295
+ if exists?("mysql_#{var}_file".to_sym) and remote_file_exists?(fetch "mysql_#{var}_file".to_sym)
296
+ mysql_credentials_file = fetch "mysql_#{var}_file".to_sym
367
297
 
368
- begin
369
- set :mysql_root_credentials_file_contents, capture("cat #{mysql_root_credentials_file}")
370
- rescue Capistrano::CommandError
371
- set :mysql_root_credentials, false
372
- end
298
+ begin
299
+ set "mysql_#{var}_file_contents".to_sym, read(mysql_credentials_file)
300
+ rescue Capistrano::CommandError
301
+ set "mysql_#{var}".to_sym, false
302
+ end
373
303
 
374
- if exists?(:mysql_root_credentials_file_contents)
375
- mysql_root_credentials_file_contents = fetch :mysql_root_credentials_file_contents
304
+ if exists?("mysql_#{var}_file_contents".to_sym)
305
+ mysql_credentials_file_contents = fetch "mysql_#{var}_file_contents".to_sym
376
306
 
377
- unless mysql_root_credentials_file_contents.blank?
378
- mysql_root_credentials = {
379
- host: mysql_root_credentials_file_contents.match(mysql_root_credentials_host_regex).try(:[], mysql_root_credentials_host_regex_match).try(:chomp),
380
- user: mysql_root_credentials_file_contents.match(mysql_root_credentials_user_regex).try(:[], mysql_root_credentials_user_regex_match).try(:chomp),
381
- pass: mysql_root_credentials_file_contents.match(mysql_root_credentials_pass_regex).try(:[], mysql_root_credentials_pass_regex_match).try(:chomp),
382
- }
307
+ unless mysql_credentials_file_contents.blank?
308
+ mysql_credentials = {
309
+ host: mysql_credentials_file_contents.match(mysql_credentials_host_regex).try(:[], mysql_credentials_host_regex_match).try(:chomp),
310
+ user: mysql_credentials_file_contents.match(mysql_credentials_user_regex).try(:[], mysql_credentials_user_regex_match).try(:chomp),
311
+ pass: mysql_credentials_file_contents.match(mysql_credentials_pass_regex).try(:[], mysql_credentials_pass_regex_match).try(:chomp),
312
+ }
313
+ end
383
314
  end
384
315
  end
385
- end
386
316
 
387
- # Verify that we got them!
388
- if mysql_root_credentials.blank? or mysql_root_credentials[:user].blank? or mysql_root_credentials[:pass].blank?
389
- mysql_root_credentials = {
390
- host: ask("What is the hostname used to access the database",
391
- default: mysql_root_credentials.try(:[], :host) || fetch(:mysql_db_server, 'localhost'),
392
- validate: /.+/),
393
- user: ask("What is the username used to access the database",
394
- default: mysql_root_credentials.try(:[], :user),
395
- validate: /.+/),
396
- pass: ask("What is the password used to access the database",
397
- default: mysql_root_credentials.try(:[], :pass),
398
- validate: /.+/,
399
- echo: false),
400
- }
401
- end
317
+ # Verify that we got them!
318
+ if mysql_credentials.blank? or mysql_credentials[:user].blank? or mysql_credentials[:pass].blank?
319
+ mysql_credentials = {
320
+ host: ask("What is the hostname used to access the database",
321
+ default: mysql_credentials.try(:[], :host) || fetch(:mysql_db_server, 'localhost'),
322
+ validate: /.+/),
323
+ user: ask("What is the username used to access the database",
324
+ default: mysql_credentials.try(:[], :user) || ((var == 'credentials') ? fetch(:mysql_db_user) : nil),
325
+ validate: /.+/),
326
+ pass: ask("What is the password used to access the database",
327
+ default: mysql_credentials.try(:[], :pass),
328
+ validate: /.+/,
329
+ echo: false),
330
+ }
331
+ end
402
332
 
403
- # Finally set it so it's available and write it to the server.
404
- if mysql_root_credentials[:user].present? and mysql_root_credentials[:pass].present?
405
- set :mysql_root_credentials, mysql_root_credentials
406
- find_and_execute_task("mysql:write_root_credentials")
333
+ # Finally set it so it's available and write it to the server.
334
+ if mysql_credentials[:user].present? and mysql_credentials[:pass].present?
335
+ set "mysql_#{var}".to_sym, mysql_credentials
336
+ find_and_execute_task("mysql:write_#{var}")
337
+ end
407
338
  end
408
339
  end
409
340
  end
410
- # REFACTOR!!
411
-
412
341
  end
413
342
 
414
343
  before "mysql:backup_db", "mysql:credentials"
@@ -103,7 +103,7 @@ Capistrano::Configuration.instance(:must_exist).load do
103
103
 
104
104
  desc "print authentification file"
105
105
  task :print_http_auth do
106
- puts capture("cat #{fetch :deploy_to}/.http_basic_auth")
106
+ puts read("#{fetch :deploy_to}/.http_basic_auth")
107
107
  end
108
108
 
109
109
  desc "[internal] Write web configuration file"
@@ -2,7 +2,7 @@ module Capistrano
2
2
  module Extensions
3
3
  module Version #:nodoc:
4
4
  MAJOR = 1
5
- MINOR = 7
5
+ MINOR = 8
6
6
  TINY = 0
7
7
 
8
8
  ARRAY = [MAJOR, MINOR, TINY]
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.7.0
4
+ version: 1.8.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-07 00:00:00.000000000 Z
12
+ date: 2011-09-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capistrano
16
- requirement: &2152478500 !ruby/object:Gem::Requirement
16
+ requirement: &2156681780 !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: *2152478500
24
+ version_requirements: *2156681780
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: i18n
27
- requirement: &2152477960 !ruby/object:Gem::Requirement
27
+ requirement: &2156681280 !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: *2152477960
35
+ version_requirements: *2156681280
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: activesupport
38
- requirement: &2152477500 !ruby/object:Gem::Requirement
38
+ requirement: &2156680820 !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: *2152477500
46
+ version_requirements: *2156680820
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: guard
49
- requirement: &2152476860 !ruby/object:Gem::Requirement
49
+ requirement: &2156680360 !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: *2152476860
57
+ version_requirements: *2156680360
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: guard-bundler
60
- requirement: &2152476180 !ruby/object:Gem::Requirement
60
+ requirement: &2156679900 !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: *2152476180
68
+ version_requirements: *2156679900
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: guard-rspec
71
- requirement: &2152475460 !ruby/object:Gem::Requirement
71
+ requirement: &2156679440 !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: *2152475460
79
+ version_requirements: *2156679440
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: rspec
82
- requirement: &2152474740 !ruby/object:Gem::Requirement
82
+ requirement: &2156678980 !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: *2152474740
90
+ version_requirements: *2156678980
91
91
  description: Handy extensions for Capistrano
92
92
  email:
93
93
  - wael.nasreddine@gmail.com