dkdeploy-core 9.0.0 → 9.3.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.
Files changed (61) hide show
  1. checksums.yaml +5 -5
  2. data/.rubocop.yml +36 -8
  3. data/.travis.yml +7 -5
  4. data/Berksfile +2 -0
  5. data/Berksfile.lock +36 -35
  6. data/CHANGELOG.md +48 -1
  7. data/CONTRIBUTORS.md +3 -0
  8. data/Gemfile +2 -0
  9. data/LICENSE +1 -1
  10. data/README.md +11 -12
  11. data/Rakefile +2 -0
  12. data/Vagrantfile +14 -14
  13. data/config/vm/cookbooks/dkdeploy-core/metadata.rb +4 -4
  14. data/config/vm/cookbooks/dkdeploy-core/recipes/default.rb +11 -13
  15. data/dkdeploy-core.gemspec +13 -11
  16. data/features/assets.feature +0 -1
  17. data/features/file_access.feature +2 -2
  18. data/features/mysql.feature +2 -2
  19. data/features/support/env.rb +4 -2
  20. data/features/utils.feature +3 -3
  21. data/lib/capistrano/dkdeploy/core.rb +14 -17
  22. data/lib/dkdeploy.rb +2 -0
  23. data/lib/dkdeploy/constants.rb +2 -0
  24. data/lib/dkdeploy/core/version.rb +3 -1
  25. data/lib/dkdeploy/dsl.rb +4 -3
  26. data/lib/dkdeploy/helpers/assets.rb +2 -0
  27. data/lib/dkdeploy/helpers/common.rb +2 -0
  28. data/lib/dkdeploy/helpers/db.rb +7 -5
  29. data/lib/dkdeploy/helpers/file_system.rb +7 -12
  30. data/lib/dkdeploy/helpers/mysql.rb +3 -0
  31. data/lib/dkdeploy/i18n.rb +3 -12
  32. data/lib/dkdeploy/interaction_handler/mysql.rb +4 -1
  33. data/lib/dkdeploy/interaction_handler/password.rb +3 -1
  34. data/lib/dkdeploy/rollback_manager.rb +2 -0
  35. data/lib/dkdeploy/scm/copy.rake +39 -12
  36. data/lib/dkdeploy/scm/copy.rb +7 -45
  37. data/lib/dkdeploy/tasks/apache.rake +2 -0
  38. data/lib/dkdeploy/tasks/assets.rake +3 -1
  39. data/lib/dkdeploy/tasks/current_folder.rake +3 -1
  40. data/lib/dkdeploy/tasks/db.rake +138 -154
  41. data/lib/dkdeploy/tasks/deploy.rake +5 -3
  42. data/lib/dkdeploy/tasks/enhanced_symlinks.rake +7 -0
  43. data/lib/dkdeploy/tasks/fail.rake +2 -0
  44. data/lib/dkdeploy/tasks/file_access.rake +2 -0
  45. data/lib/dkdeploy/tasks/maintenance.rake +4 -3
  46. data/lib/dkdeploy/tasks/mysql.rake +5 -0
  47. data/lib/dkdeploy/tasks/project_version.rake +3 -3
  48. data/lib/dkdeploy/tasks/utils.rake +2 -0
  49. data/spec/fixtures/application/Capfile +2 -0
  50. data/spec/fixtures/application/Gemfile +3 -1
  51. data/spec/fixtures/application/config/deploy.rb +25 -23
  52. data/spec/fixtures/application/config/deploy/dev.rb +3 -1
  53. data/spec/fixtures/capistrano/configuration/add_output_after_create_symlink.rb +1 -0
  54. data/spec/fixtures/capistrano/configuration/custom_compass_sources.rb +2 -0
  55. data/spec/fixtures/capistrano/configuration/custom_file_access.rb +2 -0
  56. data/spec/fixtures/capistrano/configuration/default_deployment_behaviour.rb +2 -0
  57. metadata +40 -47
  58. data/features/bower.feature +0 -52
  59. data/lib/capistrano/copy.rb +0 -2
  60. data/lib/dkdeploy/tasks/bower.rake +0 -53
  61. data/spec/fixtures/application/htdocs/bower.json +0 -15
@@ -1,4 +1,6 @@
1
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
2
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
5
  require 'dkdeploy/core/version'
4
6
 
@@ -11,23 +13,23 @@ Gem::Specification.new do |spec|
11
13
  spec.description = 'dkd basic deployment tasks and strategies'
12
14
  spec.summary = 'dkd basic deployment tasks and strategies'
13
15
  spec.homepage = 'https://github.com/dkdeploy/dkdeploy-core'
14
- spec.required_ruby_version = '~> 2.2'
16
+ spec.required_ruby_version = '~> 2.5'
15
17
 
16
18
  spec.files = `git ls-files`.split($/)
17
- spec.executables = spec.files.grep(%r{^bin\/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)\/})
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
21
  spec.require_paths = ['lib']
20
22
 
23
+ spec.add_development_dependency 'aruba', '~> 1.0'
21
24
  spec.add_development_dependency 'bundler'
22
- spec.add_development_dependency 'rake'
23
- spec.add_development_dependency 'rspec', '~> 3.5'
24
25
  spec.add_development_dependency 'cucumber', '~> 2.4'
25
- spec.add_development_dependency 'rubocop', '~> 0.50.0'
26
- spec.add_development_dependency 'aruba', '~> 0.14.1'
26
+ spec.add_development_dependency 'dkdeploy-test_environment', '~> 2.0'
27
27
  spec.add_development_dependency 'mysql2', '~> 0.3'
28
28
  spec.add_development_dependency 'pry', '~> 0.10'
29
- spec.add_development_dependency 'dkdeploy-test_environment', '~> 2.0'
29
+ spec.add_development_dependency 'rake'
30
+ spec.add_development_dependency 'rspec', '~> 3.5'
31
+ spec.add_development_dependency 'rubocop', '~> 0.86.0'
30
32
 
31
- spec.add_dependency 'capistrano', '~> 3.9.0'
32
- spec.add_dependency 'highline', '~> 1.7.1'
33
+ spec.add_dependency 'capistrano', '~> 3.14.1'
34
+ spec.add_dependency 'highline', '~> 2.0.3'
33
35
  end
@@ -37,7 +37,6 @@ Feature: Test tasks for namespace 'assets'
37
37
  And I run `cap dev assets:add_htpasswd` interactively
38
38
  And I type "dkd_test_user"
39
39
  And I type "dkd_test_password"
40
- And I close the stdin stream
41
40
  Then the exit status should be 0
42
41
  And a remote file named "shared_path/.htpasswd" should exist
43
42
 
@@ -87,7 +87,7 @@ Feature: Test tasks for namespace 'file_permissions'
87
87
  Given I extend the development capistrano configuration variable custom_file_access with value {app: {release_path: {catalog: {mode: 'u+rwx,g+rwx,o-wx'}, not_existing: {mode: 'u+rwx,g+rwx,o-wx'}}}}
88
88
  And a remote directory named "releases_path/not_existing" should not exist
89
89
  When I successfully run `cap dev file_access:set_custom_access`
90
- Then the output should contain "The resource /var/www/dkdeploy/current/not_existing does not exist on host dkdeploy-core.dev"
90
+ Then the output should contain "The resource /var/www/dkdeploy/current/not_existing does not exist on host dkdeploy-core.test"
91
91
  And the output should not contain "sudo chmod u+rwx,g+rwx,o-wx /var/www/dkdeploy/current/not_existing"
92
92
  And the output should contain "sudo chmod u+rwx,g+rwx,o-wx /var/www/dkdeploy/current/catalog"
93
93
 
@@ -115,6 +115,6 @@ Feature: Test tasks for namespace 'file_permissions'
115
115
  And I extend the development capistrano configuration variable selected_custom_file_access with value [:not_existing, :catalog]
116
116
  And a remote directory named "releases_path/not_existing" should not exist
117
117
  When I successfully run `cap dev file_access:set_selected_custom_access`
118
- Then the output should contain "The resource /var/www/dkdeploy/current/not_existing does not exist on host dkdeploy-core.dev"
118
+ Then the output should contain "The resource /var/www/dkdeploy/current/not_existing does not exist on host dkdeploy-core.test"
119
119
  And the output should not contain "sudo chmod -R u+rwx,g+rwx,o-wx /var/www/dkdeploy/current/not_existing"
120
120
  And the output should contain "sudo chmod -R u+rwx,g+rwx,o-wx /var/www/dkdeploy/current/catalog"
@@ -10,14 +10,14 @@ Feature: Test tasks for namespace 'mysql'
10
10
  And I successfully run `cap dev "db:update[temp,dkdeploy_core.sql.gz]"`
11
11
  And I successfully run `cap dev db:download_content`
12
12
  And I successfully run `cap dev mysql:download_slow_log`
13
- Then a file named "temp/slow-queries.dev.dkdeploy-core.dev.log" should exist
13
+ Then a file named "temp/slow-queries.dev.dkdeploy-core.test.log" should exist
14
14
 
15
15
  Scenario: Downloading the MYSQL slow log analyze file
16
16
  When I successfully run `cap dev "db:upload_settings[127.0.0.1,3306,dkdeploy_core,root,ilikerandompasswords,utf8]"`
17
17
  And I successfully run `cap dev "db:update[temp,dkdeploy_core.sql.gz]"`
18
18
  And I successfully run `cap dev db:download_content`
19
19
  And I successfully run `cap dev mysql:analyze_download_slow_log`
20
- Then a file named "temp/mysql_slow_log_analyze.dev.dkdeploy-core.dev.log" should exist
20
+ Then a file named "temp/mysql_slow_log_analyze.dev.dkdeploy-core.test.log" should exist
21
21
 
22
22
  Scenario: Clearing the MySQL slow log file
23
23
  When I successfully run `cap dev "db:upload_settings[127.0.0.1,3306,dkdeploy_core,root,ilikerandompasswords,utf8]"`
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dkdeploy/test_environment/application'
2
4
 
3
5
  ssh_config = {}
@@ -11,8 +13,8 @@ unless ssh_key_files.empty?
11
13
  }
12
14
  end
13
15
 
14
- TEST_APPLICATION = Dkdeploy::TestEnvironment::Application.new(File.expand_path('../../../', __FILE__), 'dkdeploy-core.dev', ssh_config)
15
- TEST_APPLICATION.mysql_connection_settings = { host: 'dkdeploy-core.dev', username: 'root', password: 'ilikerandompasswords' }
16
+ TEST_APPLICATION = Dkdeploy::TestEnvironment::Application.new(File.expand_path('../..', __dir__), 'dkdeploy-core.test', ssh_config)
17
+ TEST_APPLICATION.mysql_connection_settings = { host: 'dkdeploy-core.test', username: 'root', password: 'ilikerandompasswords' }
16
18
 
17
19
  # this configuration tricks Bundler into executing another Bundler project with clean enviroment
18
20
  # The official way via Bundler.with_clean_env did not work properly here
@@ -28,10 +28,10 @@ Feature: Test tasks for namespace 'utils'
28
28
  Remote file content
29
29
  """
30
30
  When I successfully run `cap dev utils:download_file['download_file.txt']`
31
- Then a file named "temp/download_file.dkdeploy-core.dev.txt" should exist
31
+ Then a file named "temp/download_file.dkdeploy-core.test.txt" should exist
32
32
 
33
33
  Scenario: Download a file from server which does exist locally
34
- Given a file named "temp/download_file.dkdeploy-core.dev.txt" with:
34
+ Given a file named "temp/download_file.dkdeploy-core.test.txt" with:
35
35
  """
36
36
  Local file content
37
37
  """
@@ -41,7 +41,7 @@ Local file content
41
41
  Remote file content
42
42
  """
43
43
  When I successfully run `cap dev utils:download_file['download_file.txt']`
44
- Then the file "temp/download_file.dkdeploy-core.dev.txt" should contain exactly:
44
+ Then the file "temp/download_file.dkdeploy-core.test.txt" should contain exactly:
45
45
  """
46
46
  Remote file content
47
47
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  include Capistrano::DSL
2
4
 
3
5
  require 'dkdeploy/rollback_manager'
@@ -7,19 +9,18 @@ require 'dkdeploy/scm/copy'
7
9
  install_plugin Dkdeploy::SCM::Copy
8
10
 
9
11
  # Load dkdeploy tasks
10
- load File.expand_path('../../../dkdeploy/tasks/deploy.rake', __FILE__)
11
- load File.expand_path('../../../dkdeploy/tasks/fail.rake', __FILE__)
12
- load File.expand_path('../../../dkdeploy/tasks/maintenance.rake', __FILE__)
13
- load File.expand_path('../../../dkdeploy/tasks/utils.rake', __FILE__)
14
- load File.expand_path('../../../dkdeploy/tasks/file_access.rake', __FILE__)
15
- load File.expand_path('../../../dkdeploy/tasks/assets.rake', __FILE__)
16
- load File.expand_path('../../../dkdeploy/tasks/apache.rake', __FILE__)
17
- load File.expand_path('../../../dkdeploy/tasks/project_version.rake', __FILE__)
18
- load File.expand_path('../../../dkdeploy/tasks/db.rake', __FILE__)
19
- load File.expand_path('../../../dkdeploy/tasks/enhanced_symlinks.rake', __FILE__)
20
- load File.expand_path('../../../dkdeploy/tasks/current_folder.rake', __FILE__)
21
- load File.expand_path('../../../dkdeploy/tasks/bower.rake', __FILE__)
22
- load File.expand_path('../../../dkdeploy/tasks/mysql.rake', __FILE__)
12
+ load File.expand_path('../../dkdeploy/tasks/deploy.rake', __dir__)
13
+ load File.expand_path('../../dkdeploy/tasks/fail.rake', __dir__)
14
+ load File.expand_path('../../dkdeploy/tasks/maintenance.rake', __dir__)
15
+ load File.expand_path('../../dkdeploy/tasks/utils.rake', __dir__)
16
+ load File.expand_path('../../dkdeploy/tasks/file_access.rake', __dir__)
17
+ load File.expand_path('../../dkdeploy/tasks/assets.rake', __dir__)
18
+ load File.expand_path('../../dkdeploy/tasks/apache.rake', __dir__)
19
+ load File.expand_path('../../dkdeploy/tasks/project_version.rake', __dir__)
20
+ load File.expand_path('../../dkdeploy/tasks/db.rake', __dir__)
21
+ load File.expand_path('../../dkdeploy/tasks/enhanced_symlinks.rake', __dir__)
22
+ load File.expand_path('../../dkdeploy/tasks/current_folder.rake', __dir__)
23
+ load File.expand_path('../../dkdeploy/tasks/mysql.rake', __dir__)
23
24
 
24
25
  # Hook into symlink related tasks
25
26
  after 'deploy:check:linked_dirs', 'deploy:enhanced_symlinks:check:linked_dirs'
@@ -56,10 +57,6 @@ namespace :load do
56
57
  # Number of archives to keep around
57
58
  set :keep_rollback_archives, 5
58
59
 
59
- # List of bower.json files
60
- set(:bower_path, -> { fetch(:copy_source) })
61
- set(:bower_paths, -> { Array(fetch(:copy_source)) })
62
-
63
60
  # List of filters for file_access:set_selected_custom_access
64
61
  set :selected_custom_file_access, []
65
62
 
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dkdeploy/core/version'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Dkdeploy
2
4
  # Global static methods
3
5
  #
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Dkdeploy
2
4
  module Core
3
5
  # Class for version number
4
6
  #
5
7
  class Version
6
8
  MAJOR = 9
7
- MINOR = 0
9
+ MINOR = 3
8
10
  PATCH = 0
9
11
 
10
12
  def self.to_s
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Dkdeploy
2
4
  # dsl api
3
5
  module DSL
@@ -6,15 +8,14 @@ module Dkdeploy
6
8
  # @param server [Capistrano::Configuration::Server] Server to execute task
7
9
  # @param task [String] Name of rake/capistrano task
8
10
  # @param args [Array] Arguments of rake/capistrano task
9
- def invoke_for_server(server, task, *args) # rubocop:disable Metrics/AbcSize
11
+ def invoke_for_server(server, task, *args)
10
12
  backup_filter = fetch :filter, {}
11
13
  new_server_filter = Marshal.load(Marshal.dump(backup_filter))
12
14
  new_server_filter[:host] = server.hostname
13
15
  set :filter, new_server_filter
14
16
  env.setup_filters
15
17
  info I18n.t('dsl.invoke_for_server.set_filter', task: task, host: server.hostname, scope: :dkdeploy)
16
- invoke task, *args
17
- Rake::Task[task].reenable
18
+ invoke! task, *args
18
19
  ensure
19
20
  set :filter, backup_filter
20
21
  env.setup_filters
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  include Capistrano::DSL
2
4
 
3
5
  module Dkdeploy
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'highline'
2
4
 
3
5
  module Dkdeploy
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'yaml'
2
4
 
3
5
  include Capistrano::DSL
@@ -7,7 +9,7 @@ module Dkdeploy
7
9
  # DB related helpers
8
10
  module DB
9
11
  def db_dump_file(infix = '')
10
- date = DateTime.now.strftime(datetime_format)
12
+ date = Time.now.strftime(datetime_format)
11
13
  ['database', fetch(:stage), infix, date].join('-') << '.sql'
12
14
  end
13
15
 
@@ -22,12 +24,12 @@ module Dkdeploy
22
24
  def db_settings_hash
23
25
  {
24
26
  'database' => {
25
- 'host' => fetch(:db_host),
26
- 'port' => fetch(:db_port),
27
- 'name' => fetch(:db_name),
27
+ 'host' => fetch(:db_host),
28
+ 'port' => fetch(:db_port),
29
+ 'name' => fetch(:db_name),
28
30
  'username' => fetch(:db_username),
29
31
  'password' => fetch(:db_password),
30
- 'charset' => fetch(:db_charset)
32
+ 'charset' => fetch(:db_charset)
31
33
  }
32
34
  }
33
35
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  include Capistrano::DSL
2
4
 
3
5
  module Dkdeploy
@@ -22,9 +24,8 @@ module Dkdeploy
22
24
  # @param path [String] path to resolve
23
25
  # @return [String]
24
26
  def resolve_path_if_symlink(context, path)
25
- if context.test " [ -L #{path} ] "
26
- return context.capture :readlink, '-f', path
27
- end
27
+ return context.capture :readlink, '-f', path if context.test " [ -L #{path} ] "
28
+
28
29
  path
29
30
  end
30
31
 
@@ -57,19 +58,13 @@ module Dkdeploy
57
58
  resolved_path = resolve_path_if_symlink(context, path)
58
59
 
59
60
  # change owner if set
60
- if access_properties.key?(:owner)
61
- context.execute :chown, recursive, access_properties.fetch(:owner), resolved_path
62
- end
61
+ context.execute :chown, recursive, access_properties.fetch(:owner), resolved_path if access_properties.key?(:owner)
63
62
 
64
63
  # change group if set
65
- if access_properties.key?(:group)
66
- context.execute :chgrp, recursive, access_properties.fetch(:group), resolved_path
67
- end
64
+ context.execute :chgrp, recursive, access_properties.fetch(:group), resolved_path if access_properties.key?(:group)
68
65
 
69
66
  # change mode if set
70
- if access_properties.key?(:mode) # rubocop:disable Style/GuardClause
71
- context.execute :chmod, recursive, access_properties.fetch(:mode), resolved_path
72
- end
67
+ context.execute :chmod, recursive, access_properties.fetch(:mode), resolved_path if access_properties.key?(:mode)
73
68
  end
74
69
  end
75
70
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  include Capistrano::DSL
2
4
 
3
5
  module Dkdeploy
@@ -9,6 +11,7 @@ module Dkdeploy
9
11
  # @return [Boolean]
10
12
  def slow_log_exists?(file_path)
11
13
  return true if !file_path.empty? && test("[ -f #{file_path} ]")
14
+
12
15
  error I18n.t('file.not_exists_or_not_accessible_on_host', file: file_path, host: server, scope: :dkdeploy)
13
16
  false
14
17
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'i18n'
2
4
 
3
5
  en = {
@@ -42,11 +44,6 @@ en = {
42
44
  charset: 'Please enter the database character set',
43
45
  zipped_db_file: 'Please enter the name of the zipped SQL script file'
44
46
  },
45
- bower: {
46
- command: 'Please enter the command you want to run',
47
- path: 'Please enter the path to the bower.json file',
48
- paths: 'Please enter the paths bower.json files (separated by spaces)'
49
- },
50
47
  selected_custom_file_access: {
51
48
  paths: 'Please enter a list of paths (entries separated by spaces)'
52
49
  },
@@ -94,10 +91,6 @@ en = {
94
91
  upload_extract: 'Extracting %{file}',
95
92
  exclude_file_not_found: "No exclude file found. To use set variable 'assets_exclude_file'"
96
93
  },
97
- bower: {
98
- skipping_missing_directory: 'Skipping directory %{bower_path} because it does not exist.',
99
- skipping_directory_with_missing_bower_file: 'Skipping directory %{bower_path} because it does not contain a bower.json file.'
100
- },
101
94
  copy: {
102
95
  archive: {
103
96
  generate: 'Generating the tar archive.',
@@ -144,6 +137,4 @@ capistrano_i18n_overwritten = {
144
137
  I18n.backend.store_translations(:en, dkdeploy: en)
145
138
  I18n.backend.store_translations(:en, capistrano: capistrano_i18n_overwritten)
146
139
 
147
- if I18n.respond_to?(:enforce_available_locales=)
148
- I18n.enforce_available_locales = true
149
- end
140
+ I18n.enforce_available_locales = true if I18n.respond_to?(:enforce_available_locales=)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Dkdeploy
2
4
  module InteractionHandler
3
5
  # Interaction handler for mysql
@@ -26,8 +28,9 @@ module Dkdeploy
26
28
  else
27
29
  @mysql_error_seen = true if data =~ /.*ERROR.*/i
28
30
  return raise 'Unexpected data from stream. Can not send password to undefined stream' unless @mysql_error_seen
31
+
29
32
  # combine the multiple lines from error message. The fact that the error message will be shown multiple times is simply ignored
30
- @return_message << data
33
+ @return_message += data
31
34
  message = 'Error on executing MySQL command! Response (error code) is: '
32
35
  SSHKit.config.output.send(:error, "#{message}\n #{@return_message}")
33
36
  raise 'InteractionHandler caught a MySQL error'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Dkdeploy
2
4
  module InteractionHandler
3
5
  # Interaction handler for password
@@ -20,7 +22,7 @@ module Dkdeploy
20
22
  channel.send_data("#{@password}\n")
21
23
  else
22
24
  channel.close
23
- raise 'Unexpected data from stream. Can not send password to undefined stream'
25
+ raise 'Unexpected data from stream. Can not send password to undefined stream.'
24
26
  end
25
27
  end
26
28
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Dkdeploy
2
4
  # The RollbackManager module is a mixin for managing rollback tasks.
3
5
  module RollbackManager
@@ -1,5 +1,4 @@
1
- # This trick lets us access the copy plugin within `on` blocks.
2
- copy_plugin = self
1
+ # frozen_string_literal: true
3
2
 
4
3
  namespace :copy do
5
4
  desc 'Check if all configuration variables and copy sources exist'
@@ -24,11 +23,11 @@ namespace :copy do
24
23
 
25
24
  # generate an exclude.txt file with the patterns to be excluded
26
25
  exclude_content = copy_exclude.join("\n")
27
- File.write(copy_plugin.local_exclude_path, exclude_content)
26
+ File.write(local_exclude_path, exclude_content)
28
27
 
29
28
  # build the tar archive excluding the patterns from exclude.txt
30
29
  within copy_source do
31
- execute :tar, '-X ' + copy_plugin.local_exclude_path, '-cpzf', copy_plugin.local_archive_path, '.'
30
+ execute :tar, '-X ' + local_exclude_path, '-cpzf', local_archive_path, '.'
32
31
  end
33
32
  end
34
33
  end
@@ -38,17 +37,17 @@ namespace :copy do
38
37
  #
39
38
  task :copy_archive_to_server do
40
39
  on release_roles :all do
41
- info I18n.t('file.upload', file: 'archive', target: copy_plugin.remote_tmp_dir, scope: :dkdeploy)
42
- execute :mkdir, '-p', copy_plugin.remote_tmp_dir
40
+ info I18n.t('file.upload', file: 'archive', target: remote_tmp_dir, scope: :dkdeploy)
41
+ execute :mkdir, '-p', remote_tmp_dir
43
42
 
44
- upload! copy_plugin.local_archive_path, copy_plugin.remote_tmp_dir
43
+ upload! local_archive_path, remote_tmp_dir
45
44
 
46
45
  info I18n.t('directory.create', directory: release_path, scope: :dkdeploy)
47
46
  execute :mkdir, '-p', release_path
48
47
 
49
48
  within release_path do
50
49
  info I18n.t('tasks.copy.archive.extract', target: release_path, scope: :dkdeploy)
51
- execute :tar, '-xpzf', copy_plugin.remote_archive_path
50
+ execute :tar, '-xpzf', remote_archive_path
52
51
  end
53
52
  end
54
53
  end
@@ -58,14 +57,14 @@ namespace :copy do
58
57
  task :clean_up_temporary_sources do
59
58
  # remove the local temporary directory
60
59
  run_locally do
61
- info I18n.t('file.remove', path: copy_plugin.local_tmp_dir, scope: :dkdeploy)
62
- execute :rm, '-rf', copy_plugin.local_tmp_dir
60
+ info I18n.t('file.remove', path: fetch(:copy_local_tmp_dir), scope: :dkdeploy)
61
+ execute :rm, '-rf', fetch(:copy_local_tmp_dir)
63
62
  end
64
63
 
65
64
  # removes the remote temp path including the uploaded archive
66
65
  on release_roles :all do
67
- info I18n.t('file.remove', path: copy_plugin.remote_archive_path, scope: :dkdeploy)
68
- execute :rm, '-rf', copy_plugin.remote_tmp_dir
66
+ info I18n.t('file.remove', path: remote_archive_path, scope: :dkdeploy)
67
+ execute :rm, '-rf', remote_archive_path
69
68
  end
70
69
  end
71
70
 
@@ -73,4 +72,32 @@ namespace :copy do
73
72
  task :set_current_revision do
74
73
  set :current_revision, I18n.t('log.revision_log_message', copy_source: fetch(:copy_source), time: Time.now, scope: :dkdeploy)
75
74
  end
75
+
76
+ # Archive path in a local temporary directory
77
+ #
78
+ # @return [String]
79
+ def local_exclude_path
80
+ File.join fetch(:copy_local_tmp_dir), 'exclude.txt'
81
+ end
82
+
83
+ # Archive path in a local temporary directory
84
+ #
85
+ # @return [String]
86
+ def local_archive_path
87
+ File.join fetch(:copy_local_tmp_dir), fetch(:copy_archive_filename)
88
+ end
89
+
90
+ # Remote temporary directory path
91
+ #
92
+ # @return [String]
93
+ def remote_tmp_dir
94
+ File.join fetch(:tmp_dir), application
95
+ end
96
+
97
+ # Archive path in a remote temporary directory
98
+ #
99
+ # @return [String]
100
+ def remote_archive_path
101
+ File.join remote_tmp_dir, fetch(:copy_archive_filename)
102
+ end
76
103
  end