Skip to content
This repository has been archived by the owner on Jan 30, 2024. It is now read-only.

Commit

Permalink
Merge branch 'release/9.1.0'
Browse files Browse the repository at this point in the history
* release/9.1.0:
  prepare release v9.1.0
  Always execute tasks for each server or at rollback
  Update capistrano 3.10.1
  Do not load sshkit dsl
  Delete not needed copy strategy loading file.
  Use correct capistrano context at copy scm
  • Loading branch information
ncreuschling committed Feb 9, 2018
2 parents 64bb2e2 + 51741a5 commit b1e21a2
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 70 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion dkdeploy-core.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 0 additions & 2 deletions lib/capistrano/copy.rb

This file was deleted.

2 changes: 1 addition & 1 deletion lib/dkdeploy/core/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Core
#
class Version
MAJOR = 9
MINOR = 0
MINOR = 1
PATCH = 0

def self.to_s
Expand Down
5 changes: 2 additions & 3 deletions lib/dkdeploy/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
51 changes: 38 additions & 13 deletions lib/dkdeploy/scm/copy.rake
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -58,19 +55,47 @@ 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

desc 'Determine the revision that will be deployed'
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
50 changes: 5 additions & 45 deletions lib/dkdeploy/scm/copy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 2 additions & 3 deletions lib/dkdeploy/tasks/deploy.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion lib/dkdeploy/tasks/maintenance.rake
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require 'json'
require 'i18n'
require 'dkdeploy/i18n'
require 'sshkit/dsl'
require 'capistrano/dsl'

include Capistrano::DSL
Expand Down

0 comments on commit b1e21a2

Please sign in to comment.