diff --git a/CHANGELOG.md b/CHANGELOG.md index a9878f1..b4d3a71 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## [9.1.0] +### Summary + +- Use correct capistrano context at copy scm +- Update capistrano 3.10.1 +- Always execute tasks for each server or at rollback + ## [9.0.0] ### Summary @@ -33,6 +40,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - first public release [Unreleased]: https://github.com/dkdeploy/dkdeploy-core/compare/master...develop +[9.1.0]: https://github.com/dkdeploy/dkdeploy-core/releases/tag/v9.1.0 [9.0.0]: https://github.com/dkdeploy/dkdeploy-core/releases/tag/v9.0.0 [8.0.1]: https://github.com/dkdeploy/dkdeploy-core/releases/tag/v8.0.1 [8.0.0]: https://github.com/dkdeploy/dkdeploy-core/releases/tag/v8.0.0 diff --git a/README.md b/README.md index 17728b0..27d9c3f 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ This Rubygem `dkdeploy-core` represents the extension of [Capistrano](http://cap Add this line to your application's `Gemfile` - gem 'dkdeploy-core', '~> 9.0' + gem 'dkdeploy-core', '~> 9.1' and then execute diff --git a/dkdeploy-core.gemspec b/dkdeploy-core.gemspec index 471795f..5a0f339 100644 --- a/dkdeploy-core.gemspec +++ b/dkdeploy-core.gemspec @@ -28,6 +28,6 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'pry', '~> 0.10' spec.add_development_dependency 'dkdeploy-test_environment', '~> 2.0' - spec.add_dependency 'capistrano', '~> 3.9.0' + spec.add_dependency 'capistrano', '~> 3.10.1' spec.add_dependency 'highline', '~> 1.7.1' end diff --git a/lib/capistrano/copy.rb b/lib/capistrano/copy.rb deleted file mode 100644 index 162837b..0000000 --- a/lib/capistrano/copy.rb +++ /dev/null @@ -1,2 +0,0 @@ -# if capistrano scm is set to copy, the current file will be loaded -load File.expand_path('../../dkdeploy/tasks/copy.rake', __FILE__) diff --git a/lib/dkdeploy/core/version.rb b/lib/dkdeploy/core/version.rb index 1624796..e48b48b 100644 --- a/lib/dkdeploy/core/version.rb +++ b/lib/dkdeploy/core/version.rb @@ -4,7 +4,7 @@ module Core # class Version MAJOR = 9 - MINOR = 0 + MINOR = 1 PATCH = 0 def self.to_s diff --git a/lib/dkdeploy/dsl.rb b/lib/dkdeploy/dsl.rb index 8ae32b9..e47a2cb 100644 --- a/lib/dkdeploy/dsl.rb +++ b/lib/dkdeploy/dsl.rb @@ -6,15 +6,14 @@ module DSL # @param server [Capistrano::Configuration::Server] Server to execute task # @param task [String] Name of rake/capistrano task # @param args [Array] Arguments of rake/capistrano task - def invoke_for_server(server, task, *args) # rubocop:disable Metrics/AbcSize + def invoke_for_server(server, task, *args) backup_filter = fetch :filter, {} new_server_filter = Marshal.load(Marshal.dump(backup_filter)) new_server_filter[:host] = server.hostname set :filter, new_server_filter env.setup_filters info I18n.t('dsl.invoke_for_server.set_filter', task: task, host: server.hostname, scope: :dkdeploy) - invoke task, *args - Rake::Task[task].reenable + invoke! task, *args ensure set :filter, backup_filter env.setup_filters diff --git a/lib/dkdeploy/scm/copy.rake b/lib/dkdeploy/scm/copy.rake index 07aff12..aef56d9 100644 --- a/lib/dkdeploy/scm/copy.rake +++ b/lib/dkdeploy/scm/copy.rake @@ -1,6 +1,3 @@ -# This trick lets us access the copy plugin within `on` blocks. -copy_plugin = self - namespace :copy do desc 'Check if all configuration variables and copy sources exist' task :check do @@ -24,11 +21,11 @@ namespace :copy do # generate an exclude.txt file with the patterns to be excluded exclude_content = copy_exclude.join("\n") - File.write(copy_plugin.local_exclude_path, exclude_content) + File.write(local_exclude_path, exclude_content) # build the tar archive excluding the patterns from exclude.txt within copy_source do - execute :tar, '-X ' + copy_plugin.local_exclude_path, '-cpzf', copy_plugin.local_archive_path, '.' + execute :tar, '-X ' + local_exclude_path, '-cpzf', local_archive_path, '.' end end end @@ -38,17 +35,17 @@ namespace :copy do # task :copy_archive_to_server do on release_roles :all do - info I18n.t('file.upload', file: 'archive', target: copy_plugin.remote_tmp_dir, scope: :dkdeploy) - execute :mkdir, '-p', copy_plugin.remote_tmp_dir + info I18n.t('file.upload', file: 'archive', target: remote_tmp_dir, scope: :dkdeploy) + execute :mkdir, '-p', remote_tmp_dir - upload! copy_plugin.local_archive_path, copy_plugin.remote_tmp_dir + upload! local_archive_path, remote_tmp_dir info I18n.t('directory.create', directory: release_path, scope: :dkdeploy) execute :mkdir, '-p', release_path within release_path do info I18n.t('tasks.copy.archive.extract', target: release_path, scope: :dkdeploy) - execute :tar, '-xpzf', copy_plugin.remote_archive_path + execute :tar, '-xpzf', remote_archive_path end end end @@ -58,14 +55,14 @@ namespace :copy do task :clean_up_temporary_sources do # remove the local temporary directory run_locally do - info I18n.t('file.remove', path: copy_plugin.local_tmp_dir, scope: :dkdeploy) - execute :rm, '-rf', copy_plugin.local_tmp_dir + info I18n.t('file.remove', path: fetch(:copy_local_tmp_dir), scope: :dkdeploy) + execute :rm, '-rf', fetch(:copy_local_tmp_dir) end # removes the remote temp path including the uploaded archive on release_roles :all do - info I18n.t('file.remove', path: copy_plugin.remote_archive_path, scope: :dkdeploy) - execute :rm, '-rf', copy_plugin.remote_tmp_dir + info I18n.t('file.remove', path: remote_archive_path, scope: :dkdeploy) + execute :rm, '-rf', remote_tmp_dir end end @@ -73,4 +70,32 @@ namespace :copy do task :set_current_revision do set :current_revision, I18n.t('log.revision_log_message', copy_source: fetch(:copy_source), time: Time.now, scope: :dkdeploy) end + + # Archive path in a local temporary directory + # + # @return [String] + def local_exclude_path + File.join fetch(:copy_local_tmp_dir), 'exclude.txt' + end + + # Archive path in a local temporary directory + # + # @return [String] + def local_archive_path + File.join fetch(:copy_local_tmp_dir), fetch(:copy_archive_filename) + end + + # Remote temporary directory path + # + # @return [String] + def remote_tmp_dir + File.join fetch(:tmp_dir), application + end + + # Archive path in a remote temporary directory + # + # @return [String] + def remote_archive_path + File.join remote_tmp_dir, fetch(:copy_archive_filename) + end end diff --git a/lib/dkdeploy/scm/copy.rb b/lib/dkdeploy/scm/copy.rb index e874b64..758d611 100644 --- a/lib/dkdeploy/scm/copy.rb +++ b/lib/dkdeploy/scm/copy.rb @@ -25,6 +25,8 @@ def set_defaults 'Thumbs.db', 'composer.lock' ] + set_if_empty :copy_archive_filename, -> { Dir::Tmpname.make_tmpname([fetch(:application) + '_', '.tar.gz'], nil) } + set_if_empty :copy_local_tmp_dir, Dir.mktmpdir end def register_hooks @@ -34,51 +36,9 @@ def register_hooks end def define_tasks - eval_rakefile File.expand_path('../copy.rake', __FILE__) - end - - # Archive filename as singleton - # Note: if the archive filename doesn't already exist it will be generated - # - # @return [String] - def archive_filename - @archive_filename ||= Dir::Tmpname.make_tmpname [application + '_', '.tar.gz'], nil - end - - # Local temporary directory path as singleton - # Note: if the directory doesn't already exist it will be created - # - # @return [String] - def local_tmp_dir - @local_tmp_dir ||= Dir.mktmpdir - end - - # Archive path in a local temporary directory - # - # @return [String] - def local_exclude_path - File.join local_tmp_dir, 'exclude.txt' - end - - # Archive path in a local temporary directory - # - # @return [String] - def local_archive_path - File.join local_tmp_dir, archive_filename - end - - # Remote temporary directory path - # - # @return [String] - def remote_tmp_dir - File.join fetch(:tmp_dir), application - end - - # Archive path in a remote temporary directory - # - # @return [String] - def remote_archive_path - File.join remote_tmp_dir, archive_filename + # Don not use method "eval_rakefile" to load rake tasks. + # "eval_rakefile" defined wrong context and use sskit dsl api instead of capistrano dsl. + load File.expand_path('../copy.rake', __FILE__) end end end diff --git a/lib/dkdeploy/tasks/deploy.rake b/lib/dkdeploy/tasks/deploy.rake index 7967b4d..28d592e 100644 --- a/lib/dkdeploy/tasks/deploy.rake +++ b/lib/dkdeploy/tasks/deploy.rake @@ -22,7 +22,7 @@ namespace :deploy do end end # Backup and remove last release - invoke 'deploy:cleanup_rollback' + invoke! 'deploy:cleanup_rollback' run_locally do error I18n.t('rollback_tasks', tasks_for_rollback: tasks_for_rollback.join(', '), scope: :dkdeploy) unless tasks_for_rollback.empty? @@ -33,8 +33,7 @@ namespace :deploy do next unless Rake::Task.task_defined? task_name # call rollback task - Rake::Task[task_name].reenable - invoke task_name + invoke! task_name end run_locally do diff --git a/lib/dkdeploy/tasks/maintenance.rake b/lib/dkdeploy/tasks/maintenance.rake index 3df20f5..672095b 100644 --- a/lib/dkdeploy/tasks/maintenance.rake +++ b/lib/dkdeploy/tasks/maintenance.rake @@ -1,7 +1,6 @@ require 'json' require 'i18n' require 'dkdeploy/i18n' -require 'sshkit/dsl' require 'capistrano/dsl' include Capistrano::DSL