capistrano-exts 1.5.1 → 1.6.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.5.1'
20
+ gem 'capistrano-exts', '>=1.6.0'
21
21
  ```
22
22
 
23
23
  Setup
@@ -26,6 +26,7 @@ set :use_sudo, false
26
26
  set :deploy_to, -> { "/home/vhosts/#{fetch :stage}/#{fetch :application}" }
27
27
  set :logs_path, -> { "#{fetch :deploy_to}/logs" }
28
28
  set :public_path, -> { "#{fetch :current_path}/public" }
29
+ set :backup_path, -> { "#{fetch :deploy_to}/backups" }
29
30
 
30
31
  # How should we deploy?
31
32
  # Valid options:
@@ -26,6 +26,7 @@ set :use_sudo, false
26
26
  set :deploy_to, -> { "/home/vhosts/#{fetch :stage}/#{fetch :application}" }
27
27
  set :logs_path, -> { "#{fetch :deploy_to}/logs" }
28
28
  set :public_path, -> { "#{fetch :current_path}/public" }
29
+ set :backup_path, -> { "#{fetch :deploy_to}/backups" }
29
30
 
30
31
  # How should we deploy?
31
32
  # Valid options:
@@ -81,7 +82,6 @@ set :mysql_db_server, 'localhost'
81
82
  set :mysql_db_name, -> { "#{fetch :application}_#{fetch :stage}" }
82
83
 
83
84
  # What is the database user ?
84
- # NOTE: This is only used if you run deploy:server:setup which calls mysql:create_db_user
85
85
  set :mysql_db_user, -> { "#{fetch :application}" }
86
86
 
87
87
  # Where the database credentials are stored on the server ?
@@ -26,6 +26,7 @@ set :use_sudo, false
26
26
  set :deploy_to, -> { "/home/vhosts/#{fetch :stage}/#{fetch :application}" }
27
27
  set :logs_path, -> { "#{fetch :deploy_to}/logs" }
28
28
  set :public_path, -> { "#{fetch :current_path}/public" }
29
+ set :backup_path, -> { "#{fetch :deploy_to}/backups" }
29
30
 
30
31
  # How should we deploy?
31
32
  # Valid options:
@@ -81,7 +82,6 @@ set :mysql_db_server, 'localhost'
81
82
  set :mysql_db_name, -> { "#{fetch :application}_#{fetch :stage}" }
82
83
 
83
84
  # What is the database user ?
84
- # NOTE: This is only used if you run deploy:server:setup which calls mysql:create_db_user
85
85
  set :mysql_db_user, -> { "#{fetch :application}" }
86
86
 
87
87
  # Where the database credentials are stored on the server ?
@@ -26,6 +26,7 @@ set :use_sudo, false
26
26
  set :deploy_to, -> { "/home/vhosts/#{fetch :stage}/#{fetch :application}" }
27
27
  set :logs_path, -> { "#{fetch :deploy_to}/logs" }
28
28
  set :public_path, -> { "#{fetch :current_path}/public" }
29
+ set :backup_path, -> { "#{fetch :deploy_to}/backups" }
29
30
 
30
31
  # How should we deploy?
31
32
  # Valid options:
@@ -82,7 +83,6 @@ set :mysql_db_server, 'localhost'
82
83
  set :mysql_db_name, -> { "#{fetch :application}_#{fetch :stage}" }
83
84
 
84
85
  # What is the database user ?
85
- # NOTE: This is only used if you run deploy:server:setup which calls mysql:create_db_user
86
86
  set :mysql_db_user, -> { "#{fetch :application}" }
87
87
 
88
88
  # Where the database credentials are stored on the server ?
@@ -26,6 +26,7 @@ set :use_sudo, false
26
26
  set :deploy_to, -> { "/home/vhosts/#{fetch :stage}/#{fetch :application}" }
27
27
  set :logs_path, -> { "#{fetch :deploy_to}/logs" }
28
28
  set :public_path, -> { "#{fetch :current_path}/public" }
29
+ set :backup_path, -> { "#{fetch :deploy_to}/backups" }
29
30
 
30
31
  # How should we deploy?
31
32
  # Valid options:
@@ -82,7 +83,6 @@ set :mysql_db_server, 'localhost'
82
83
  set :mysql_db_name, -> { "#{fetch :application}_#{fetch :stage}" }
83
84
 
84
85
  # What is the database user ?
85
- # NOTE: This is only used if you run deploy:server:setup which calls mysql:create_db_user
86
86
  set :mysql_db_user, -> { "#{fetch :application}" }
87
87
 
88
88
  # Where the database credentials are stored on the server ?
@@ -26,6 +26,7 @@ set :use_sudo, false
26
26
  set :deploy_to, -> { "/home/vhosts/#{fetch :stage}/#{fetch :application}" }
27
27
  set :logs_path, -> { "#{fetch :deploy_to}/logs" }
28
28
  set :public_path, -> { "#{fetch :current_path}/public" }
29
+ set :backup_path, -> { "#{fetch :deploy_to}/backups" }
29
30
 
30
31
  # How should we deploy?
31
32
  # Valid options:
@@ -82,7 +83,6 @@ set :mysql_db_server, 'localhost'
82
83
  set :mysql_db_name, -> { "#{fetch :application}_#{fetch :stage}" }
83
84
 
84
85
  # What is the database user ?
85
- # NOTE: This is only used if you run deploy:server:setup which calls mysql:create_db_user
86
86
  set :mysql_db_user, -> { "#{fetch :application}" }
87
87
 
88
88
  # Where the database credentials are stored on the server ?
@@ -26,6 +26,7 @@ set :use_sudo, false
26
26
  set :deploy_to, -> { "/home/vhosts/#{fetch :stage}/#{fetch :application}" }
27
27
  set :logs_path, -> { "#{fetch :deploy_to}/logs" }
28
28
  set :public_path, -> { "#{fetch :current_path}/public" }
29
+ set :backup_path, -> { "#{fetch :deploy_to}/backups" }
29
30
 
30
31
  # How should we deploy?
31
32
  # Valid options:
@@ -82,7 +83,6 @@ set :mysql_db_server, 'localhost'
82
83
  set :mysql_db_name, -> { "#{fetch :application}_#{fetch :stage}" }
83
84
 
84
85
  # What is the database user ?
85
- # NOTE: This is only used if you run deploy:server:setup which calls mysql:create_db_user
86
86
  set :mysql_db_user, -> { "#{fetch :application}" }
87
87
 
88
88
  # Where the database credentials are stored on the server ?
@@ -26,6 +26,7 @@ set :use_sudo, false
26
26
  set :deploy_to, -> { "/home/vhosts/#{fetch :stage}/#{fetch :application}" }
27
27
  set :logs_path, -> { "#{fetch :deploy_to}/logs" }
28
28
  set :public_path, -> { "#{fetch :current_path}/public" }
29
+ set :backup_path, -> { "#{fetch :deploy_to}/backups" }
29
30
 
30
31
  # How should we deploy?
31
32
  # Valid options:
@@ -82,7 +83,6 @@ set :mysql_db_server, 'localhost'
82
83
  set :mysql_db_name, -> { "#{fetch :application}_#{fetch :stage}" }
83
84
 
84
85
  # What is the database user ?
85
- # NOTE: This is only used if you run deploy:server:setup which calls mysql:create_db_user
86
86
  set :mysql_db_user, -> { "#{fetch :application}" }
87
87
 
88
88
  # Where the database credentials are stored on the server ?
@@ -26,6 +26,7 @@ set :use_sudo, false
26
26
  set :deploy_to, -> { "/home/vhosts/#{fetch :stage}/#{fetch :application}" }
27
27
  set :logs_path, -> { "#{fetch :deploy_to}/logs" }
28
28
  set :public_path, -> { "#{fetch :current_path}/public" }
29
+ set :backup_path, -> { "#{fetch :deploy_to}/backups" }
29
30
 
30
31
  # How should we deploy?
31
32
  # Valid options:
@@ -82,7 +83,6 @@ set :mysql_db_server, 'localhost'
82
83
  set :mysql_db_name, -> { "#{fetch :application}_#{fetch :stage}" }
83
84
 
84
85
  # What is the database user ?
85
- # NOTE: This is only used if you run deploy:server:setup which calls mysql:create_db_user
86
86
  set :mysql_db_user, -> { "#{fetch :application}" }
87
87
 
88
88
  # Where the database credentials are stored on the server ?
@@ -50,6 +50,7 @@ Capistrano::Configuration.instance(:must_exist).load do
50
50
 
51
51
  # Add MySQL credentials
52
52
  unless localconfig.blank? or mysql_credentials.blank?
53
+ localconfig.gsub!(/#DB_HOST#/, mysql_credentials[:host])
53
54
  localconfig.gsub!(/#DB_USER#/, mysql_credentials[:user])
54
55
  localconfig.gsub!(/#DB_PASS#/, mysql_credentials[:pass])
55
56
  localconfig.gsub!(/#DB_NAME#/, mysql_db_name)
@@ -25,6 +25,22 @@ Capistrano::Configuration.instance(:must_exist).load do
25
25
  end
26
26
  end
27
27
 
28
+ desc "Backup the contents folder"
29
+ task :backup, :roles => :app, :except => { :no_release => true } do
30
+ backup_path = fetch :backup_path, "#{fetch :deploy_to}/backups"
31
+ set :latest_contents_backup, "#{backup_path}/#{application}_shared_contents_#{Time.now.strftime('%d-%m-%Y_%H-%M-%S')}.tar.gz"
32
+ latest_contents_backup = fetch :latest_contents_backup
33
+
34
+ # Setup a rollback hook
35
+ on_rollback { run "rm -f #{latest_contents_backup}" }
36
+
37
+ # Create a tarball of the contents folder
38
+ run <<-CMD
39
+ cd #{shared_path}/shared_contents &&
40
+ tar chzf #{latest_contents_backup} --exclude='*~' --exclude='*.tmp' --exclude='*.bak' *
41
+ CMD
42
+ end
43
+
28
44
  desc "[internal] Fix contao's symlinks to the shared path"
29
45
  task :fix_links, :roles => :app, :except => { :no_release => true } do
30
46
  contents_folder = fetch :contents_folder
@@ -58,6 +74,7 @@ Capistrano::Configuration.instance(:must_exist).load do
58
74
  desc "Export the contents folder"
59
75
  task :export, :roles => :app, :except => { :no_release => true } do
60
76
  shared_path = fetch :shared_path
77
+ latest_contents_backup = fetch :latest_contents_backup
61
78
 
62
79
  # Find out at which index the file is located ?
63
80
  argv_file_index = ARGV.index("contents:export") + 1
@@ -72,20 +89,63 @@ Capistrano::Configuration.instance(:must_exist).load do
72
89
  export_filename = random_tmp_file + ".tar.gz"
73
90
  end
74
91
 
75
- # Create a tarball of the contents folder
76
- run <<-CMD
77
- cd #{shared_path}/shared_contents &&
78
- tar chzf /tmp/#{File.basename export_filename} --exclude='*~' --exclude='*.tmp' --exclude='*.bak' *
79
- CMD
80
-
81
92
  # Tranfer the contents to the local system
82
- get "/tmp/#{File.basename export_filename}", export_filename
93
+ get latest_contents_backup, export_filename
83
94
 
84
95
  puts "Contents has been downloaded to #{export_filename}"
85
96
  exit 0
86
97
  end
98
+
99
+ desc "Import the contents folder"
100
+ task :import, :roles => :app, :except => { :no_release => true } do
101
+ # Find out at which index the file is located ?
102
+ argv_file_index = ARGV.index("contents:import") + 1
103
+
104
+ unless ARGV.size >= (argv_file_index + 1) and File.exists?(ARGV[argv_file_index])
105
+ puts "ERROR: please run 'cap import <gzipped tar>'"
106
+ exit 1
107
+ else
108
+ # The contents file name
109
+ import_filename_argv = ARGV[argv_file_index]
110
+ # Read the dump
111
+ contents_dump = File.read(import_filename_argv)
112
+ # Generate a random file
113
+ random_file = random_tmp_file contents_dump
114
+ # Add a rollback hook
115
+ on_rollback { run "rm -f #{random_file}" }
116
+
117
+ # Ask for a confirmation
118
+ response = ask("I am going to add/replace all the files in the contents folder of #{fetch :application} with the contents of #{import_filename_argv}, are you sure you would like to continue (Yes, [No], Abort)", default:'N')
119
+ if response =~ /(no?)|(a(bort)?|\n)/i
120
+ abort "Canceled by the user."
121
+ end
122
+
123
+ # Transfer the SQL file to the server
124
+ # TODO: Try upload(filename, remote_file_name) function instead
125
+ put contents_dump, random_file
126
+
127
+ run <<-CMD
128
+ cd #{shared_path}/shared_contents &&
129
+ tar xzf #{random_file}
130
+ CMD
131
+
132
+ # Remove the uploaded file
133
+ run <<-CMD
134
+ rm -f '#{random_file}'
135
+ CMD
136
+
137
+ # Fix permissions
138
+ find_and_execute_task("deploy:fix_permissions")
139
+
140
+ # Exit because capistrano will rollback, the next argument is a file name and not a task
141
+ # TODO: Find a better solution!
142
+ exit 0
143
+ end
144
+ end
87
145
  end
88
146
 
89
147
  after "deploy:setup", "contents:setup"
90
148
  after "deploy:finalize_update", "contents:fix_links"
149
+ before "contents:export", "contents:backup"
150
+ before "contents:import", "contents:backup"
91
151
  end
@@ -32,6 +32,22 @@ Capistrano::Configuration.instance(:must_exist).load do
32
32
  run "chmod -R g+w #{fetch :latest_release}" if fetch(:group_writable, true)
33
33
  end
34
34
 
35
+ desc "[internal] create the required folders."
36
+ task :folders, :roles => :app do
37
+ backup_path = fetch :backup_path, "#{fetch :deploy_to}/backups"
38
+
39
+ run <<-CMD
40
+ mkdir -p #{fetch :deploy_to} &&
41
+ mkdir -p #{backup_path}
42
+ CMD
43
+
44
+ if exists? :logs_path
45
+ run <<-CMD
46
+ mkdir -p #{fetch :logs_path}
47
+ CMD
48
+ end
49
+ end
50
+
35
51
  desc "[internal] Symlink public folder"
36
52
  task :symlink_public_folders, :roles => :web, :except => { :no_release => true } do
37
53
  deploy_to = fetch :deploy_to
@@ -61,5 +77,6 @@ Capistrano::Configuration.instance(:must_exist).load do
61
77
  # Dependencies
62
78
  before "deploy", "deploy:check_if_remote_ready"
63
79
  after "deploy:restart", "deploy:fix_permissions"
80
+ after "deploy:setup", "deploy:folders"
64
81
  after "deploy:setup", "deploy:symlink_public_folders"
65
82
  end
@@ -55,7 +55,7 @@ Capistrano::Configuration.instance(:must_exist).load do
55
55
  end
56
56
 
57
57
  def generate_random_file_name(data = nil)
58
- if data.present?
58
+ if data
59
59
  "#{fetch :application}_#{Time.now.strftime('%d-%m-%Y_%H-%M-%S-%L')}_#{Digest::SHA1.hexdigest data}"
60
60
  else
61
61
  "#{fetch :application}_#{Time.now.strftime('%d-%m-%Y_%H-%M-%S-%L')}"
@@ -15,7 +15,9 @@ Capistrano::Configuration.instance(:must_exist).load do
15
15
  mysql_credentials = fetch :mysql_credentials
16
16
  mysql_db_name = fetch :mysql_db_name
17
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"
18
+ backup_path = fetch :backup_path, "#{fetch :deploy_to}/backups"
19
+
20
+ set :latest_db_dump, "#{backup_path}/#{mysql_db_name}_#{Time.now.strftime('%d-%m-%Y_%H-%M-%S')}.sql"
19
21
  latest_db_dump = fetch :latest_db_dump
20
22
 
21
23
  on_rollback { run "rm -f #{latest_db_dump}" }
@@ -99,6 +101,7 @@ Capistrano::Configuration.instance(:must_exist).load do
99
101
  EOS
100
102
  end
101
103
 
104
+ # Upload the script
102
105
  put mysql_create, random_file
103
106
 
104
107
  begin
@@ -164,16 +167,28 @@ Capistrano::Configuration.instance(:must_exist).load do
164
167
  # The database dump name
165
168
  import_filename_argv = ARGV[argv_file_index]
166
169
  # Read the dump
167
- mysql_dump = File.read(import_filename_argv)
170
+ contents_dump = File.read(import_filename_argv)
168
171
  # Generate a random file
169
- random_file = random_tmp_file mysql_dump
172
+ random_file = random_tmp_file contents_dump
170
173
  # Add a rollback hook
171
174
  on_rollback { run "rm -f #{random_file}" }
172
175
 
173
176
  if mysql_credentials.present?
174
- drop_db
175
- create_db
176
- put File.read(import_filename_argv), random_file
177
+ # Ask for a confirmation
178
+ response = ask("I am going to replace the database of #{fetch :application} with the contents of #{import_filename_argv}, are you sure you would like to continue (Yes, [No], Abort)", default:'N')
179
+ if response =~ /(no?)|(a(bort)?|\n)/i
180
+ abort "Canceled by the user."
181
+ end
182
+
183
+ # Transfer the SQL file to the server
184
+ # TODO: Try upload(filename, remote_file_name) function instead
185
+ put contents_dump, random_file
186
+
187
+ # Drop the database
188
+ find_and_execute_task("mysql:drop_db")
189
+
190
+ # Create the database
191
+ find_and_execute_task("mysql:create_db")
177
192
 
178
193
  run <<-CMD
179
194
  mysql \
@@ -185,10 +200,13 @@ Capistrano::Configuration.instance(:must_exist).load do
185
200
  #{random_file}
186
201
  CMD
187
202
 
203
+ # Remove the uploaded file
188
204
  run <<-CMD
189
205
  rm -f '#{random_file}'
190
206
  CMD
191
207
 
208
+ # Exit because capistrano will rollback, the next argument is a file name and not a task
209
+ # TODO: Find a better solution!
192
210
  exit 0
193
211
  end
194
212
  end
@@ -54,16 +54,8 @@ Capistrano::Configuration.instance(:must_exist).load do
54
54
  end
55
55
 
56
56
  task :folders, :roles => :app do
57
- run <<-CMD
58
- mkdir -p #{fetch :deploy_to} &&
59
- mkdir -p #{fetch :deploy_to}/backups
60
- CMD
61
-
62
- if exists? :logs_path
63
- run <<-CMD
64
- mkdir -p #{fetch :logs_path}
65
- CMD
66
- end
57
+ # Use setup:folders
58
+ find_and_execute_task("setup:folders")
67
59
  end
68
60
 
69
61
  task :finish do
@@ -23,6 +23,7 @@ set :use_sudo, false
23
23
  set :deploy_to, -> { "/home/vhosts/#{fetch :stage}/#{fetch :application}" }
24
24
  set :logs_path, -> { "#{fetch :deploy_to}/logs" }
25
25
  set :public_path, -> { "#{fetch :current_path}/public" }
26
+ set :backup_path, -> { "#{fetch :deploy_to}/backups" }
26
27
 
27
28
  # How should we deploy?
28
29
  # Valid options:
@@ -79,7 +80,6 @@ set :mysql_db_server, 'localhost'
79
80
  set :mysql_db_name, -> { "#{fetch :application}_#{fetch :stage}" }
80
81
 
81
82
  # What is the database user ?
82
- # NOTE: This is only used if you run deploy:server:setup which calls mysql:create_db_user
83
83
  set :mysql_db_user, -> { "#{fetch :application}" }
84
84
 
85
85
  # Where the database credentials are stored on the server ?
@@ -2,8 +2,8 @@ module Capistrano
2
2
  module Extensions
3
3
  module Version #:nodoc:
4
4
  MAJOR = 1
5
- MINOR = 5
6
- TINY = 1
5
+ MINOR = 6
6
+ TINY = 0
7
7
 
8
8
  ARRAY = [MAJOR, MINOR, TINY]
9
9
  STRING = ARRAY.join(".")
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.5.1
4
+ version: 1.6.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-09-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capistrano
16
- requirement: &2156458100 !ruby/object:Gem::Requirement
16
+ requirement: &2156442460 !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: *2156458100
24
+ version_requirements: *2156442460
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: i18n
27
- requirement: &2156456100 !ruby/object:Gem::Requirement
27
+ requirement: &2156453940 !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: *2156456100
35
+ version_requirements: *2156453940
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: activesupport
38
- requirement: &2156454120 !ruby/object:Gem::Requirement
38
+ requirement: &2156453160 !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: *2156454120
46
+ version_requirements: *2156453160
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: guard
49
- requirement: &2156452240 !ruby/object:Gem::Requirement
49
+ requirement: &2156451240 !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: *2156452240
57
+ version_requirements: *2156451240
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: guard-bundler
60
- requirement: &2156451180 !ruby/object:Gem::Requirement
60
+ requirement: &2156479320 !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: *2156451180
68
+ version_requirements: *2156479320
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: guard-rspec
71
- requirement: &2156469200 !ruby/object:Gem::Requirement
71
+ requirement: &2156475160 !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: *2156469200
79
+ version_requirements: *2156475160
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: rspec
82
- requirement: &2156467860 !ruby/object:Gem::Requirement
82
+ requirement: &2156486700 !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: *2156467860
90
+ version_requirements: *2156486700
91
91
  description: Handy extensions for Capistrano
92
92
  email:
93
93
  - wael.nasreddine@gmail.com