capistrano-exts 1.4.0 → 1.5.0

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.
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.4.0'
20
+ gem 'capistrano-exts', '>=1.5.0'
21
21
  ```
22
22
 
23
23
  Setup
@@ -59,19 +59,30 @@ Capistrano::Configuration.instance(:must_exist).load do
59
59
  task :export, :roles => :app, :except => { :no_release => true } do
60
60
  shared_path = fetch :shared_path
61
61
 
62
- # Create random file name
63
- random_file = random_tmp_file + ".tar.gz"
62
+ # Find out at which index the file is located ?
63
+ argv_file_index = ARGV.index("contents:export") + 1
64
+
65
+ # The database dump name
66
+ export_filename_argv = ARGV.try(:[], argv_file_index)
67
+
68
+ # Generate the file name
69
+ if export_filename_argv and not export_filename_argv =~ /.+:.+/ and not File.exists?(export_filename_argv)
70
+ export_filename = export_filename_argv
71
+ else
72
+ export_filename = random_tmp_file + ".tar.gz"
73
+ end
64
74
 
65
75
  # Create a tarball of the contents folder
66
76
  run <<-CMD
67
- cd #{shared_path} &&
68
- tar czf #{random_file} --exclude='*~' --exclude='*.tmp' --exclude='*.bak' shared_contents
77
+ cd #{shared_path}/shared_contents &&
78
+ tar czf /tmp/#{File.basename export_filename} --exclude='*~' --exclude='*.tmp' --exclude='*.bak' *
69
79
  CMD
70
80
 
71
81
  # Tranfer the contents to the local system
72
- get random_file, random_file
82
+ get "/tmp/#{File.basename export_filename}", export_filename
73
83
 
74
- puts "Contents has been downloaded to #{random_file}"
84
+ puts "Contents has been downloaded to #{export_filename}"
85
+ exit 0
75
86
  end
76
87
  end
77
88
 
@@ -1,4 +1,6 @@
1
1
  require 'capistrano'
2
+ require 'capistrano/errors'
3
+ require 'capistrano-exts/receipts/functions'
2
4
 
3
5
  # Verify that Capistrano is version 2
4
6
  unless Capistrano::Configuration.respond_to?(:instance)
@@ -29,9 +31,27 @@ Capistrano::Configuration.instance(:must_exist).load do
29
31
 
30
32
  run "chmod -R g+w #{fetch :latest_release}" if fetch(:group_writable, true)
31
33
  end
34
+
35
+ desc "[internal] Symlink htdocs"
36
+ task :symlink_htdocs do
37
+ deploy_to = fetch :deploy_to
38
+ if remote_file_exists?("#{deploy_to}/htdocs")
39
+ begin
40
+ run <<-CMD
41
+ #{try_sudo} mv #{deploy_to}/htdocs #{deploy_to}/old_htdocs &&
42
+ #{try_sudo} ln -nsf #{fetch :public_path} #{deploy_to}/htdocs
43
+ CMD
44
+ rescue Capistrano::CommandError
45
+ puts "WARNING: I couldn't replace the old htdocs please do so manually"
46
+ end
47
+ end
48
+
49
+ puts "The htdocs folder has been moved to old_htdocs"
50
+ end
32
51
  end
33
52
 
34
53
  # Dependencies
35
54
  before "deploy", "deploy:check_if_remote_ready"
36
55
  after "deploy:restart", "deploy:fix_permissions"
56
+ after "deploy:setup", "deploy:symlink_htdocs"
37
57
  end
@@ -1,5 +1,6 @@
1
1
  require 'capistrano'
2
2
  require 'capistrano/errors'
3
+ require 'capistrano-exts/receipts/functions'
3
4
  require 'capistrano-exts/receipts/deploy'
4
5
 
5
6
  # Verify that Capistrano is version 2
@@ -13,9 +14,11 @@ Capistrano::Configuration.instance(:must_exist).load do
13
14
  task :backup_db, :roles => :db, :except => { :no_release => true } do
14
15
  mysql_credentials = fetch :mysql_credentials
15
16
  mysql_db_name = fetch :mysql_db_name
16
- MYSQL_DB_BACKUP_PATH = "#{deploy_to}/backups/#{mysql_db_name}_#{Time.now.strftime('%d-%m-%Y_%H-%M-%S')}.sql"
17
+ deploy_to = fetch :deploy_to
18
+ set :latest_db_dump, "#{deploy_to}/backups/#{mysql_db_name}_#{Time.now.strftime('%d-%m-%Y_%H-%M-%S')}.sql"
19
+ latest_db_dump = fetch :latest_db_dump
17
20
 
18
- on_rollback { run "rm -f #{MYSQL_DB_BACKUP_PATH}" }
21
+ on_rollback { run "rm -f #{latest_db_dump}" }
19
22
 
20
23
  if exists?(:mysql_credentials)
21
24
  begin
@@ -26,11 +29,11 @@ Capistrano::Configuration.instance(:must_exist).load do
26
29
  --password='#{mysql_credentials[:pass]}' \
27
30
  --default-character-set=utf8 \
28
31
  '#{mysql_db_name}' > \
29
- '#{MYSQL_DB_BACKUP_PATH}'
32
+ '#{latest_db_dump}'
30
33
  CMD
31
34
 
32
35
  run <<-CMD
33
- #{try_sudo} bzip2 -9 '#{MYSQL_DB_BACKUP_PATH}'
36
+ #{try_sudo} bzip2 -9 '#{latest_db_dump}'
34
37
  CMD
35
38
  rescue Capistrano::CommandError
36
39
  puts "WARNING: The database doesn't exist."
@@ -159,9 +162,9 @@ Capistrano::Configuration.instance(:must_exist).load do
159
162
  exit 1
160
163
  else
161
164
  # The database dump name
162
- dump_sql_file = ARGV[argv_file_index]
165
+ import_filename_argv = ARGV[argv_file_index]
163
166
  # Read the dump
164
- mysql_dump = File.read(dump_sql_file)
167
+ mysql_dump = File.read(import_filename_argv)
165
168
  # Generate a random file
166
169
  random_file = random_tmp_file mysql_dump
167
170
  # Add a rollback hook
@@ -170,7 +173,7 @@ Capistrano::Configuration.instance(:must_exist).load do
170
173
  if mysql_credentials.present?
171
174
  drop_db
172
175
  create_db
173
- put File.read(dump_sql_file), random_file
176
+ put File.read(import_filename_argv), random_file
174
177
 
175
178
  run <<-CMD
176
179
  mysql \
@@ -193,35 +196,39 @@ Capistrano::Configuration.instance(:must_exist).load do
193
196
 
194
197
  desc "Export a database dump"
195
198
  task :export_db_dump, :roles => :db, :except => { :no_release => true } do
196
- on_rollback { run "rm -f /tmp/#{File.basename MYSQL_DB_BACKUP_PATH}{,.bz2" }
199
+ latest_db_dump = fetch :latest_db_dump
200
+ on_rollback { run "rm -f /tmp/#{File.basename latest_db_dump}{,.bz2" }
197
201
 
198
202
  mysql_credentials = fetch :mysql_credentials
199
203
 
200
204
  # Find out at which index the file is located ?
201
205
  argv_file_index = ARGV.index("mysql:export_db_dump") + 1
202
206
 
203
- if ARGV.size < (argv_file_index + 1) or File.exists?(ARGV[argv_file_index])
204
- puts "ERROR: please run 'cap mysql:export_db_dump <sql dump>'"
205
- puts " <sql dump> should not exist"
206
- exit 1
207
+ # The database dump name
208
+ export_filename_argv = ARGV.try(:[], argv_file_index)
209
+
210
+ # Generate the file name
211
+ if export_filename_argv and not export_filename_argv =~ /.+:.+/ and not File.exists?(export_filename_argv)
212
+ export_filename = export_filename_argv
207
213
  else
208
- # The database dump name
209
- dump_sql_file = ARGV.delete_at(argv_file_index)
214
+ export_filename = random_tmp_file + ".sql"
215
+ end
210
216
 
211
- if mysql_credentials.present?
212
- run <<-CMD
213
- cp #{MYSQL_DB_BACKUP_PATH}.bz2 /tmp &&
214
- bunzip2 /tmp/#{File.basename MYSQL_DB_BACKUP_PATH}.bz2
215
- CMD
217
+ # Get the dump
218
+ if mysql_credentials.present?
219
+ run <<-CMD
220
+ cp #{latest_db_dump}.bz2 /tmp &&
221
+ bunzip2 /tmp/#{File.basename latest_db_dump}.bz2
222
+ CMD
216
223
 
217
- get "/tmp/#{File.basename MYSQL_DB_BACKUP_PATH}", dump_sql_file
224
+ get "/tmp/#{File.basename latest_db_dump}", export_filename
218
225
 
219
- run <<-CMD
220
- rm -f /tmp/#{File.basename MYSQL_DB_BACKUP_PATH}
221
- CMD
226
+ run <<-CMD
227
+ rm -f /tmp/#{File.basename latest_db_dump}
228
+ CMD
222
229
 
223
- exit 0
224
- end
230
+ puts "Mysql dump has been downloaded to #{export_filename}"
231
+ exit 0
225
232
  end
226
233
  end
227
234
 
@@ -15,6 +15,38 @@ end
15
15
  Capistrano::Configuration.instance(:must_exist).load do
16
16
  namespace :deploy do
17
17
  namespace :server do
18
+
19
+ desc "Send SSH key"
20
+ task :send_ssh_key do
21
+ # Find out at which index the file is located ?
22
+ argv_file_index = ARGV.index("deploy:server:send_ssh_key") + 1
23
+
24
+ # The database dump name
25
+ idrsa_filename_argv = ARGV.try(:[], argv_file_index)
26
+
27
+ # Generate the file name
28
+ if idrsa_filename_argv and not idrsa_filename_argv =~ /.+:.+/ and not File.exists?(idrsa_filename_argv)
29
+ idrsa_filename = idrsa_filename_argv
30
+ else
31
+ idrsa_filename = "#{ENV['HOME']}/.ssh/id_rsa.pub"
32
+ end
33
+
34
+ if File.exists?(idrsa_filename)
35
+ idrsa_filename_contents = File.read(idrsa_filename).chomp
36
+ random_file = random_tmp_file idrsa_filename_contents
37
+
38
+ run <<-CMD
39
+ mkdir -p ~/.ssh &&
40
+ touch ~/.ssh/authorized_keys &&
41
+ echo '#{idrsa_filename_contents}' > #{random_file} &&
42
+ cat #{random_file} >> ~/.ssh/authorized_keys &&
43
+ rm -f #{random_file}
44
+ CMD
45
+ else
46
+ abort "The id_rsa or id_dsa file '#{idrsa_filename}' does not exists."
47
+ end
48
+ end
49
+
18
50
  namespace :setup do
19
51
  desc "Prepare the server (database server, web server and folders)"
20
52
  task :default do
@@ -2,7 +2,7 @@ module Capistrano
2
2
  module Extensions
3
3
  module Version #:nodoc:
4
4
  MAJOR = 1
5
- MINOR = 4
5
+ MINOR = 5
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.4.0
4
+ version: 1.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-09-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capistrano
16
- requirement: &2155898800 !ruby/object:Gem::Requirement
16
+ requirement: &2152402160 !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: *2155898800
24
+ version_requirements: *2152402160
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: i18n
27
- requirement: &2152141240 !ruby/object:Gem::Requirement
27
+ requirement: &2152612760 !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: *2152141240
35
+ version_requirements: *2152612760
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: activesupport
38
- requirement: &2152140380 !ruby/object:Gem::Requirement
38
+ requirement: &2152626900 !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: *2152140380
46
+ version_requirements: *2152626900
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: guard
49
- requirement: &2152139700 !ruby/object:Gem::Requirement
49
+ requirement: &2152622900 !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: *2152139700
57
+ version_requirements: *2152622900
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: guard-bundler
60
- requirement: &2152139040 !ruby/object:Gem::Requirement
60
+ requirement: &2152619820 !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: *2152139040
68
+ version_requirements: *2152619820
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: guard-rspec
71
- requirement: &2152138360 !ruby/object:Gem::Requirement
71
+ requirement: &2152670800 !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: *2152138360
79
+ version_requirements: *2152670800
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: rspec
82
- requirement: &2152137740 !ruby/object:Gem::Requirement
82
+ requirement: &2152665220 !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: *2152137740
90
+ version_requirements: *2152665220
91
91
  description: Handy extensions for Capistrano
92
92
  email:
93
93
  - wael.nasreddine@gmail.com