capistrano 3.3.5 → 3.16.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/issue_template.md +19 -0
- data/.github/pull_request_template.md +22 -0
- data/.github/release-drafter.yml +17 -0
- data/.github/workflows/push.yml +12 -0
- data/.gitignore +8 -5
- data/.rubocop.yml +62 -0
- data/.travis.yml +25 -7
- data/CHANGELOG.md +1 -273
- data/CONTRIBUTING.md +63 -93
- data/DEVELOPMENT.md +127 -0
- data/Dangerfile +1 -0
- data/Gemfile +36 -3
- data/LICENSE.txt +1 -1
- data/README.md +118 -292
- data/RELEASING.md +17 -0
- data/Rakefile +9 -1
- data/UPGRADING-3.7.md +86 -0
- data/bin/cap +1 -1
- data/capistrano.gemspec +24 -24
- data/features/deploy.feature +35 -1
- data/features/doctor.feature +11 -0
- data/features/installation.feature +8 -3
- data/features/sshconnect.feature +11 -0
- data/features/stage_failure.feature +9 -0
- data/features/step_definitions/assertions.rb +57 -20
- data/features/step_definitions/cap_commands.rb +9 -0
- data/features/step_definitions/setup.rb +56 -8
- data/features/subdirectory.feature +9 -0
- data/features/support/env.rb +5 -5
- data/features/support/remote_command_helpers.rb +12 -6
- data/features/support/vagrant_helpers.rb +17 -11
- data/lib/Capfile +1 -1
- data/lib/capistrano/all.rb +10 -10
- data/lib/capistrano/application.rb +47 -34
- data/lib/capistrano/configuration.rb +95 -44
- data/lib/capistrano/configuration/empty_filter.rb +9 -0
- data/lib/capistrano/configuration/filter.rb +16 -46
- data/lib/capistrano/configuration/host_filter.rb +29 -0
- data/lib/capistrano/configuration/null_filter.rb +9 -0
- data/lib/capistrano/configuration/plugin_installer.rb +51 -0
- data/lib/capistrano/configuration/question.rb +31 -9
- data/lib/capistrano/configuration/role_filter.rb +29 -0
- data/lib/capistrano/configuration/scm_resolver.rb +149 -0
- data/lib/capistrano/configuration/server.rb +30 -62
- data/lib/capistrano/configuration/servers.rb +38 -12
- data/lib/capistrano/configuration/validated_variables.rb +110 -0
- data/lib/capistrano/configuration/variables.rb +112 -0
- data/lib/capistrano/defaults.rb +26 -4
- data/lib/capistrano/deploy.rb +1 -2
- data/lib/capistrano/doctor.rb +6 -0
- data/lib/capistrano/doctor/environment_doctor.rb +19 -0
- data/lib/capistrano/doctor/gems_doctor.rb +45 -0
- data/lib/capistrano/doctor/output_helpers.rb +79 -0
- data/lib/capistrano/doctor/servers_doctor.rb +105 -0
- data/lib/capistrano/doctor/variables_doctor.rb +72 -0
- data/lib/capistrano/dotfile.rb +1 -2
- data/lib/capistrano/dsl.rb +49 -18
- data/lib/capistrano/dsl/env.rb +16 -46
- data/lib/capistrano/dsl/paths.rb +11 -25
- data/lib/capistrano/dsl/stages.rb +14 -2
- data/lib/capistrano/dsl/task_enhancements.rb +7 -12
- data/lib/capistrano/framework.rb +1 -1
- data/lib/capistrano/i18n.rb +32 -24
- data/lib/capistrano/immutable_task.rb +30 -0
- data/lib/capistrano/install.rb +1 -1
- data/lib/capistrano/plugin.rb +95 -0
- data/lib/capistrano/proc_helpers.rb +13 -0
- data/lib/capistrano/scm.rb +7 -20
- data/lib/capistrano/scm/git.rb +100 -0
- data/lib/capistrano/scm/hg.rb +55 -0
- data/lib/capistrano/scm/plugin.rb +13 -0
- data/lib/capistrano/scm/svn.rb +56 -0
- data/lib/capistrano/scm/tasks/git.rake +73 -0
- data/lib/capistrano/scm/tasks/hg.rake +53 -0
- data/lib/capistrano/scm/tasks/svn.rake +53 -0
- data/lib/capistrano/setup.rb +20 -6
- data/lib/capistrano/tasks/console.rake +4 -8
- data/lib/capistrano/tasks/deploy.rake +105 -74
- data/lib/capistrano/tasks/doctor.rake +24 -0
- data/lib/capistrano/tasks/framework.rake +13 -14
- data/lib/capistrano/tasks/install.rake +14 -15
- data/lib/capistrano/templates/Capfile +22 -11
- data/lib/capistrano/templates/deploy.rb.erb +18 -27
- data/lib/capistrano/templates/stage.rb.erb +36 -20
- data/lib/capistrano/upload_task.rb +1 -1
- data/lib/capistrano/version.rb +1 -1
- data/lib/capistrano/version_validator.rb +5 -10
- data/spec/integration/dsl_spec.rb +311 -289
- data/spec/integration_spec_helper.rb +3 -5
- data/spec/lib/capistrano/application_spec.rb +23 -39
- data/spec/lib/capistrano/configuration/empty_filter_spec.rb +17 -0
- data/spec/lib/capistrano/configuration/filter_spec.rb +83 -79
- data/spec/lib/capistrano/configuration/host_filter_spec.rb +71 -0
- data/spec/lib/capistrano/configuration/null_filter_spec.rb +17 -0
- data/spec/lib/capistrano/configuration/plugin_installer_spec.rb +98 -0
- data/spec/lib/capistrano/configuration/question_spec.rb +58 -26
- data/spec/lib/capistrano/configuration/role_filter_spec.rb +80 -0
- data/spec/lib/capistrano/configuration/scm_resolver_spec.rb +55 -0
- data/spec/lib/capistrano/configuration/server_spec.rb +124 -100
- data/spec/lib/capistrano/configuration/servers_spec.rb +143 -123
- data/spec/lib/capistrano/configuration_spec.rb +231 -59
- data/spec/lib/capistrano/doctor/environment_doctor_spec.rb +44 -0
- data/spec/lib/capistrano/doctor/gems_doctor_spec.rb +67 -0
- data/spec/lib/capistrano/doctor/output_helpers_spec.rb +47 -0
- data/spec/lib/capistrano/doctor/servers_doctor_spec.rb +86 -0
- data/spec/lib/capistrano/doctor/variables_doctor_spec.rb +89 -0
- data/spec/lib/capistrano/dsl/paths_spec.rb +201 -42
- data/spec/lib/capistrano/dsl/task_enhancements_spec.rb +57 -37
- data/spec/lib/capistrano/dsl_spec.rb +84 -11
- data/spec/lib/capistrano/immutable_task_spec.rb +31 -0
- data/spec/lib/capistrano/plugin_spec.rb +84 -0
- data/spec/lib/capistrano/scm/git_spec.rb +184 -0
- data/spec/lib/capistrano/scm/hg_spec.rb +109 -0
- data/spec/lib/capistrano/scm/svn_spec.rb +137 -0
- data/spec/lib/capistrano/scm_spec.rb +7 -8
- data/spec/lib/capistrano/upload_task_spec.rb +7 -7
- data/spec/lib/capistrano/version_validator_spec.rb +61 -46
- data/spec/lib/capistrano_spec.rb +2 -3
- data/spec/spec_helper.rb +21 -8
- data/spec/support/Vagrantfile +18 -8
- data/spec/support/tasks/database.rake +3 -3
- data/spec/support/tasks/fail.rake +4 -3
- data/spec/support/tasks/failed.rake +2 -2
- data/spec/support/tasks/plugin.rake +6 -0
- data/spec/support/tasks/root.rake +11 -0
- data/spec/support/test_app.rb +63 -39
- metadata +121 -44
- data/features/remote_file_task.feature +0 -14
- data/lib/capistrano/git.rb +0 -46
- data/lib/capistrano/hg.rb +0 -43
- data/lib/capistrano/svn.rb +0 -38
- data/lib/capistrano/tasks/git.rake +0 -81
- data/lib/capistrano/tasks/hg.rake +0 -52
- data/lib/capistrano/tasks/svn.rake +0 -52
- data/spec/lib/capistrano/git_spec.rb +0 -81
- data/spec/lib/capistrano/hg_spec.rb +0 -81
- data/spec/lib/capistrano/svn_spec.rb +0 -79
@@ -2,8 +2,16 @@ Given(/^a test app with the default configuration$/) do
|
|
2
2
|
TestApp.install
|
3
3
|
end
|
4
4
|
|
5
|
+
Given(/^a test app without any configuration$/) do
|
6
|
+
TestApp.create_test_app
|
7
|
+
end
|
8
|
+
|
5
9
|
Given(/^servers with the roles app and web$/) do
|
6
|
-
|
10
|
+
begin
|
11
|
+
vagrant_cli_command("up")
|
12
|
+
rescue
|
13
|
+
nil
|
14
|
+
end
|
7
15
|
end
|
8
16
|
|
9
17
|
Given(/^a linked file "(.*?)"$/) do |file|
|
@@ -13,10 +21,16 @@ end
|
|
13
21
|
|
14
22
|
Given(/^file "(.*?)" exists in shared path$/) do |file|
|
15
23
|
file_shared_path = TestApp.shared_path.join(file)
|
16
|
-
run_vagrant_command("mkdir -p #{
|
24
|
+
run_vagrant_command("mkdir -p #{file_shared_path.dirname}")
|
17
25
|
run_vagrant_command("touch #{file_shared_path}")
|
18
26
|
end
|
19
27
|
|
28
|
+
Given(/^all linked files exists in shared path$/) do
|
29
|
+
TestApp.linked_files.each do |linked_file|
|
30
|
+
step %Q{file "#{linked_file}" exists in shared path}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
20
34
|
Given(/^file "(.*?)" does not exist in shared path$/) do |file|
|
21
35
|
file_shared_path = TestApp.shared_path.join(file)
|
22
36
|
run_vagrant_command("mkdir -p #{TestApp.shared_path}")
|
@@ -24,7 +38,11 @@ Given(/^file "(.*?)" does not exist in shared path$/) do |file|
|
|
24
38
|
end
|
25
39
|
|
26
40
|
Given(/^a custom task to generate a file$/) do
|
27
|
-
TestApp.copy_task_to_test_app(
|
41
|
+
TestApp.copy_task_to_test_app("spec/support/tasks/database.rake")
|
42
|
+
end
|
43
|
+
|
44
|
+
Given(/^a task which executes as root$/) do
|
45
|
+
TestApp.copy_task_to_test_app("spec/support/tasks/root.rake")
|
28
46
|
end
|
29
47
|
|
30
48
|
Given(/config stage file has line "(.*?)"/) do |line|
|
@@ -32,15 +50,45 @@ Given(/config stage file has line "(.*?)"/) do |line|
|
|
32
50
|
end
|
33
51
|
|
34
52
|
Given(/^the configuration is in a custom location$/) do
|
35
|
-
TestApp.move_configuration_to_custom_location(
|
53
|
+
TestApp.move_configuration_to_custom_location("app")
|
36
54
|
end
|
37
55
|
|
38
56
|
Given(/^a custom task that will simulate a failure$/) do
|
39
|
-
safely_remove_file(TestApp.shared_path.join(
|
40
|
-
TestApp.copy_task_to_test_app(
|
57
|
+
safely_remove_file(TestApp.shared_path.join("failed"))
|
58
|
+
TestApp.copy_task_to_test_app("spec/support/tasks/fail.rake")
|
41
59
|
end
|
42
60
|
|
43
61
|
Given(/^a custom task to run in the event of a failure$/) do
|
44
|
-
safely_remove_file(TestApp.shared_path.join(
|
45
|
-
TestApp.copy_task_to_test_app(
|
62
|
+
safely_remove_file(TestApp.shared_path.join("failed"))
|
63
|
+
TestApp.copy_task_to_test_app("spec/support/tasks/failed.rake")
|
64
|
+
end
|
65
|
+
|
66
|
+
Given(/^a stage file named (.+)$/) do |filename|
|
67
|
+
TestApp.write_local_stage_file(filename)
|
68
|
+
end
|
69
|
+
|
70
|
+
Given(/^I make (\d+) deployments$/) do |count|
|
71
|
+
step "all linked files exists in shared path"
|
72
|
+
|
73
|
+
@release_paths = (1..count.to_i).map do
|
74
|
+
TestApp.cap("deploy")
|
75
|
+
stdout, _stderr = run_vagrant_command("readlink #{TestApp.current_path}")
|
76
|
+
|
77
|
+
stdout.strip
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
Given(/^(\d+) valid existing releases$/) do |num|
|
82
|
+
a_day = 86_400 # in seconds
|
83
|
+
(1...num).each_slice(100) do |num_batch|
|
84
|
+
dirs = num_batch.map do |i|
|
85
|
+
offset = -(a_day * i)
|
86
|
+
TestApp.release_path(TestApp.timestamp(offset))
|
87
|
+
end
|
88
|
+
run_vagrant_command("mkdir -p #{dirs.join(' ')}")
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
Given(/^an invalid release named "(.+)"$/) do |filename|
|
93
|
+
run_vagrant_command("mkdir -p #{TestApp.release_path(filename)}")
|
46
94
|
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
Feature: cap can be run from a subdirectory, and will still find the Capfile
|
2
|
+
|
3
|
+
Background:
|
4
|
+
Given a test app with the default configuration
|
5
|
+
And servers with the roles app and web
|
6
|
+
|
7
|
+
Scenario: Running cap from a subdirectory
|
8
|
+
When I run cap "git:check" within the "config" directory
|
9
|
+
Then the task is successful
|
data/features/support/env.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
PROJECT_ROOT = File.expand_path(
|
2
|
-
VAGRANT_ROOT = File.join(PROJECT_ROOT,
|
3
|
-
VAGRANT_BIN = ENV[
|
1
|
+
PROJECT_ROOT = File.expand_path("../../../", __FILE__)
|
2
|
+
VAGRANT_ROOT = File.join(PROJECT_ROOT, "spec/support")
|
3
|
+
VAGRANT_BIN = ENV["VAGRANT_BIN"] || "vagrant"
|
4
4
|
|
5
5
|
at_exit do
|
6
|
-
if ENV[
|
6
|
+
if ENV["KEEP_RUNNING"]
|
7
7
|
VagrantHelpers.run_vagrant_command("rm -rf /home/vagrant/var")
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
require_relative
|
11
|
+
require_relative "../../spec/support/test_app"
|
@@ -1,22 +1,28 @@
|
|
1
1
|
module RemoteCommandHelpers
|
2
2
|
def test_dir_exists(path)
|
3
|
-
exists?(
|
3
|
+
exists?("d", path)
|
4
4
|
end
|
5
5
|
|
6
6
|
def test_symlink_exists(path)
|
7
|
-
exists?(
|
7
|
+
exists?("L", path)
|
8
8
|
end
|
9
9
|
|
10
10
|
def test_file_exists(path)
|
11
|
-
exists?(
|
11
|
+
exists?("f", path)
|
12
12
|
end
|
13
13
|
|
14
14
|
def exists?(type, path)
|
15
|
-
%{[ -#{type} "#{path}" ]}
|
15
|
+
%Q{[ -#{type} "#{path}" ]}
|
16
16
|
end
|
17
17
|
|
18
|
-
def
|
19
|
-
|
18
|
+
def symlinked?(symlink_path, target_path)
|
19
|
+
"[ #{symlink_path} -ef #{target_path} ]"
|
20
|
+
end
|
21
|
+
|
22
|
+
def safely_remove_file(_path)
|
23
|
+
run_vagrant_command("rm #{test_file}")
|
24
|
+
rescue
|
25
|
+
VagrantHelpers::VagrantSSHCommandError
|
20
26
|
end
|
21
27
|
end
|
22
28
|
|
@@ -1,10 +1,12 @@
|
|
1
|
+
require "open3"
|
2
|
+
|
1
3
|
module VagrantHelpers
|
2
4
|
extend self
|
3
5
|
|
4
6
|
class VagrantSSHCommandError < RuntimeError; end
|
5
7
|
|
6
8
|
at_exit do
|
7
|
-
if ENV[
|
9
|
+
if ENV["KEEP_RUNNING"]
|
8
10
|
puts "Vagrant vm will be left up because KEEP_RUNNING is set."
|
9
11
|
puts "Rerun without KEEP_RUNNING set to cleanup the vm."
|
10
12
|
else
|
@@ -14,22 +16,26 @@ module VagrantHelpers
|
|
14
16
|
|
15
17
|
def vagrant_cli_command(command)
|
16
18
|
puts "[vagrant] #{command}"
|
17
|
-
Dir.chdir(VAGRANT_ROOT) do
|
18
|
-
|
19
|
-
puts "[vagrant] #{line}"
|
20
|
-
end
|
19
|
+
stdout, stderr, status = Dir.chdir(VAGRANT_ROOT) do
|
20
|
+
Open3.capture3("#{VAGRANT_BIN} #{command}")
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
|
+
(stdout + stderr).each_line { |line| puts "[vagrant] #{line}" }
|
24
|
+
|
25
|
+
[stdout, stderr, status]
|
23
26
|
end
|
24
27
|
|
25
28
|
def run_vagrant_command(command)
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
fail VagrantSSHCommandError, status
|
30
|
-
end
|
29
|
+
stdout, stderr, status = vagrant_cli_command("ssh -c #{command.inspect}")
|
30
|
+
return [stdout, stderr] if status.success?
|
31
|
+
raise VagrantSSHCommandError, status
|
31
32
|
end
|
32
33
|
|
34
|
+
def puts(message)
|
35
|
+
# Attach log messages to the current cucumber feature (`log`),
|
36
|
+
# or simply puts to the console (`super`) if we are outside of cucumber.
|
37
|
+
respond_to?(:log) ? log(message) : super(message)
|
38
|
+
end
|
33
39
|
end
|
34
40
|
|
35
41
|
World(VagrantHelpers)
|
data/lib/Capfile
CHANGED
data/lib/capistrano/all.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "rake"
|
2
|
+
require "sshkit"
|
3
3
|
|
4
|
-
require
|
4
|
+
require "io/console"
|
5
5
|
|
6
6
|
Rake.application.options.trace = true
|
7
7
|
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require
|
13
|
-
require
|
8
|
+
require "capistrano/version"
|
9
|
+
require "capistrano/version_validator"
|
10
|
+
require "capistrano/i18n"
|
11
|
+
require "capistrano/dsl"
|
12
|
+
require "capistrano/application"
|
13
|
+
require "capistrano/configuration"
|
14
|
+
require "capistrano/configuration/scm_resolver"
|
14
15
|
|
15
16
|
module Capistrano
|
16
|
-
|
17
17
|
end
|
@@ -1,9 +1,8 @@
|
|
1
1
|
module Capistrano
|
2
2
|
class Application < Rake::Application
|
3
|
-
|
4
3
|
def initialize
|
5
4
|
super
|
6
|
-
@rakefiles = %w{capfile Capfile capfile.rb Capfile.rb}
|
5
|
+
@rakefiles = %w{capfile Capfile capfile.rb Capfile.rb}
|
7
6
|
end
|
8
7
|
|
9
8
|
def name
|
@@ -21,11 +20,11 @@ module Capistrano
|
|
21
20
|
switch =~ /--#{Regexp.union(not_applicable_to_capistrano)}/
|
22
21
|
end
|
23
22
|
|
24
|
-
super.push(version, dry_run, roles, hostfilter)
|
23
|
+
super.push(version, dry_run, roles, hostfilter, print_config_variables)
|
25
24
|
end
|
26
25
|
|
27
26
|
def handle_options
|
28
|
-
options.rakelib = [
|
27
|
+
options.rakelib = ["rakelib"]
|
29
28
|
options.trace_output = $stderr
|
30
29
|
|
31
30
|
OptionParser.new do |opts|
|
@@ -48,11 +47,10 @@ module Capistrano
|
|
48
47
|
end
|
49
48
|
|
50
49
|
standard_rake_options.each { |args| opts.on(*args) }
|
51
|
-
opts.environment(
|
50
|
+
opts.environment("RAKEOPT")
|
52
51
|
end.parse!
|
53
52
|
end
|
54
53
|
|
55
|
-
|
56
54
|
def top_level_tasks
|
57
55
|
if tasks_without_stage_dependency.include?(@top_level_tasks.first)
|
58
56
|
@top_level_tasks
|
@@ -63,13 +61,10 @@ module Capistrano
|
|
63
61
|
|
64
62
|
def display_error_message(ex)
|
65
63
|
unless options.backtrace
|
66
|
-
|
67
|
-
whitelist = (@imported.dup << loc[0]).map{|f| File.absolute_path(f, loc[1])}
|
68
|
-
pattern = %r@^(?!#{whitelist.map{|p| Regexp.quote(p)}.join('|')})@
|
69
|
-
Rake.application.options.suppress_backtrace_pattern = pattern
|
70
|
-
end
|
64
|
+
Rake.application.options.suppress_backtrace_pattern = backtrace_pattern if backtrace_pattern
|
71
65
|
trace "(Backtrace restricted to imported tasks)"
|
72
66
|
end
|
67
|
+
|
73
68
|
super
|
74
69
|
end
|
75
70
|
|
@@ -81,60 +76,78 @@ module Capistrano
|
|
81
76
|
end
|
82
77
|
end
|
83
78
|
|
79
|
+
# allows the `cap install` task to load without a capfile
|
80
|
+
def find_rakefile_location
|
81
|
+
if (location = super).nil?
|
82
|
+
[capfile, Dir.pwd]
|
83
|
+
else
|
84
|
+
location
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
84
88
|
private
|
85
89
|
|
90
|
+
def backtrace_pattern
|
91
|
+
loc = Rake.application.find_rakefile_location
|
92
|
+
return unless loc
|
93
|
+
|
94
|
+
whitelist = (@imported.dup << loc[0]).map { |f| File.absolute_path(f, loc[1]) }
|
95
|
+
/^(?!#{whitelist.map { |p| Regexp.quote(p) }.join('|')})/
|
96
|
+
end
|
97
|
+
|
86
98
|
def load_imports
|
87
|
-
if options.show_tasks
|
88
|
-
invoke
|
89
|
-
set(:stage,
|
99
|
+
if options.show_tasks && Rake::Task.task_defined?("load:defaults")
|
100
|
+
invoke "load:defaults"
|
101
|
+
set(:stage, "")
|
90
102
|
Dir[deploy_config_path].each { |f| add_import f }
|
91
103
|
end
|
92
104
|
|
93
105
|
super
|
94
106
|
end
|
95
107
|
|
96
|
-
# allows the `cap install` task to load without a capfile
|
97
108
|
def capfile
|
98
|
-
File.expand_path(File.join(File.dirname(__FILE__),
|
109
|
+
File.expand_path(File.join(File.dirname(__FILE__), "..", "Capfile"))
|
99
110
|
end
|
100
111
|
|
101
112
|
def version
|
102
|
-
[
|
113
|
+
["--version", "-V",
|
103
114
|
"Display the program version.",
|
104
|
-
lambda
|
105
|
-
puts "Capistrano Version: #{Capistrano::VERSION} (Rake Version: #{
|
115
|
+
lambda do |_value|
|
116
|
+
puts "Capistrano Version: #{Capistrano::VERSION} (Rake Version: #{Rake::VERSION})"
|
106
117
|
exit
|
107
|
-
|
108
|
-
]
|
118
|
+
end]
|
109
119
|
end
|
110
120
|
|
111
121
|
def dry_run
|
112
|
-
[
|
122
|
+
["--dry-run", "-n",
|
113
123
|
"Do a dry run without executing actions",
|
114
|
-
lambda
|
124
|
+
lambda do |_value|
|
115
125
|
Configuration.env.set(:sshkit_backend, SSHKit::Backend::Printer)
|
116
|
-
|
117
|
-
]
|
126
|
+
end]
|
118
127
|
end
|
119
128
|
|
120
129
|
def roles
|
121
|
-
[
|
130
|
+
["--roles ROLES", "-r",
|
122
131
|
"Run SSH commands only on hosts matching these roles",
|
123
|
-
lambda
|
132
|
+
lambda do |value|
|
124
133
|
Configuration.env.add_cmdline_filter(:role, value)
|
125
|
-
|
126
|
-
]
|
134
|
+
end]
|
127
135
|
end
|
128
136
|
|
129
137
|
def hostfilter
|
130
|
-
[
|
138
|
+
["--hosts HOSTS", "-z",
|
131
139
|
"Run SSH commands only on matching hosts",
|
132
|
-
lambda
|
140
|
+
lambda do |value|
|
133
141
|
Configuration.env.add_cmdline_filter(:host, value)
|
134
|
-
|
135
|
-
]
|
142
|
+
end]
|
136
143
|
end
|
137
144
|
|
145
|
+
def print_config_variables
|
146
|
+
["--print-config-variables", "-p",
|
147
|
+
"Display the defined config variables before starting the deployment tasks.",
|
148
|
+
lambda do |_value|
|
149
|
+
Configuration.env.set(:print_config_variables, true)
|
150
|
+
end]
|
151
|
+
end
|
138
152
|
end
|
139
|
-
|
140
153
|
end
|
@@ -1,15 +1,15 @@
|
|
1
|
-
require_relative
|
2
|
-
require_relative
|
3
|
-
require_relative
|
4
|
-
require_relative
|
1
|
+
require_relative "configuration/filter"
|
2
|
+
require_relative "configuration/question"
|
3
|
+
require_relative "configuration/plugin_installer"
|
4
|
+
require_relative "configuration/server"
|
5
|
+
require_relative "configuration/servers"
|
6
|
+
require_relative "configuration/validated_variables"
|
7
|
+
require_relative "configuration/variables"
|
5
8
|
|
6
9
|
module Capistrano
|
7
|
-
class
|
8
|
-
|
9
|
-
def initialize(config = nil)
|
10
|
-
@config ||= config
|
11
|
-
end
|
10
|
+
class ValidationError < RuntimeError; end
|
12
11
|
|
12
|
+
class Configuration
|
13
13
|
def self.env
|
14
14
|
@env ||= new
|
15
15
|
end
|
@@ -18,38 +18,53 @@ module Capistrano
|
|
18
18
|
@env = new
|
19
19
|
end
|
20
20
|
|
21
|
+
extend Forwardable
|
22
|
+
attr_reader :variables
|
23
|
+
def_delegators :variables,
|
24
|
+
:set, :fetch, :fetch_for, :delete, :keys, :validate
|
25
|
+
|
26
|
+
def initialize(values={})
|
27
|
+
@variables = ValidatedVariables.new(Variables.new(values))
|
28
|
+
end
|
29
|
+
|
21
30
|
def ask(key, default=nil, options={})
|
22
31
|
question = Question.new(key, default, options)
|
23
32
|
set(key, question)
|
24
33
|
end
|
25
34
|
|
26
|
-
def
|
27
|
-
|
35
|
+
def set_if_empty(key, value=nil, &block)
|
36
|
+
set(key, value, &block) unless keys.include?(key)
|
28
37
|
end
|
29
38
|
|
30
|
-
def
|
31
|
-
|
39
|
+
def append(key, *values)
|
40
|
+
set(key, Array(fetch(key)).concat(values))
|
32
41
|
end
|
33
42
|
|
34
|
-
def
|
35
|
-
|
43
|
+
def remove(key, *values)
|
44
|
+
set(key, Array(fetch(key)) - values)
|
36
45
|
end
|
37
46
|
|
38
|
-
def
|
39
|
-
value =
|
40
|
-
|
41
|
-
|
47
|
+
def any?(key)
|
48
|
+
value = fetch(key)
|
49
|
+
if value && value.respond_to?(:any?)
|
50
|
+
begin
|
51
|
+
return value.any?
|
52
|
+
rescue ArgumentError # rubocop:disable Lint/HandleExceptions
|
53
|
+
# Gracefully ignore values whose `any?` method doesn't accept 0 args
|
54
|
+
end
|
42
55
|
end
|
43
|
-
|
56
|
+
|
57
|
+
!value.nil?
|
44
58
|
end
|
45
59
|
|
46
|
-
def
|
47
|
-
|
60
|
+
def is_question?(key)
|
61
|
+
value = fetch_for(key, nil)
|
62
|
+
!value.nil? && value.is_a?(Question)
|
48
63
|
end
|
49
64
|
|
50
65
|
def role(name, hosts, options={})
|
51
66
|
if name == :all
|
52
|
-
raise ArgumentError
|
67
|
+
raise ArgumentError, "#{name} reserved name for role. Please choose another name"
|
53
68
|
end
|
54
69
|
|
55
70
|
servers.add_role(name, hosts, options)
|
@@ -63,6 +78,10 @@ module Capistrano
|
|
63
78
|
servers.roles_for(names)
|
64
79
|
end
|
65
80
|
|
81
|
+
def role_properties_for(names, &block)
|
82
|
+
servers.role_properties_for(names, &block)
|
83
|
+
end
|
84
|
+
|
66
85
|
def primary(role)
|
67
86
|
servers.fetch_primary(role)
|
68
87
|
end
|
@@ -75,27 +94,50 @@ module Capistrano
|
|
75
94
|
|
76
95
|
def configure_backend
|
77
96
|
backend.configure do |sshkit|
|
78
|
-
sshkit
|
97
|
+
configure_sshkit_output(sshkit)
|
79
98
|
sshkit.output_verbosity = fetch(:log_level)
|
80
99
|
sshkit.default_env = fetch(:default_env)
|
81
100
|
sshkit.backend = fetch(:sshkit_backend, SSHKit::Backend::Netssh)
|
82
101
|
sshkit.backend.configure do |backend|
|
83
102
|
backend.pty = fetch(:pty)
|
84
103
|
backend.connection_timeout = fetch(:connection_timeout)
|
85
|
-
backend.ssh_options =
|
104
|
+
backend.ssh_options = (backend.ssh_options || {}).merge(fetch(:ssh_options, {}))
|
86
105
|
end
|
87
106
|
end
|
88
107
|
end
|
89
108
|
|
109
|
+
def configure_scm
|
110
|
+
Capistrano::Configuration::SCMResolver.new.resolve
|
111
|
+
end
|
112
|
+
|
90
113
|
def timestamp
|
91
114
|
@timestamp ||= Time.now.utc
|
92
115
|
end
|
93
116
|
|
117
|
+
def add_filter(filter=nil, &block)
|
118
|
+
if block
|
119
|
+
raise ArgumentError, "Both a block and an object were given" if filter
|
120
|
+
|
121
|
+
filter = Object.new
|
122
|
+
def filter.filter(servers)
|
123
|
+
block.call(servers)
|
124
|
+
end
|
125
|
+
elsif !filter.respond_to? :filter
|
126
|
+
raise TypeError, "Provided custom filter <#{filter.inspect}> does " \
|
127
|
+
"not have a public 'filter' method"
|
128
|
+
end
|
129
|
+
@custom_filters ||= []
|
130
|
+
@custom_filters << filter
|
131
|
+
end
|
132
|
+
|
94
133
|
def setup_filters
|
95
|
-
@filters = cmdline_filters
|
96
|
-
@filters
|
97
|
-
@filters << Filter.new(:
|
98
|
-
|
134
|
+
@filters = cmdline_filters
|
135
|
+
@filters += @custom_filters if @custom_filters
|
136
|
+
@filters << Filter.new(:role, ENV["ROLES"]) if ENV["ROLES"]
|
137
|
+
@filters << Filter.new(:host, ENV["HOSTS"]) if ENV["HOSTS"]
|
138
|
+
fh = fetch_for(:filter, {}) || {}
|
139
|
+
@filters << Filter.new(:host, fh[:hosts]) if fh[:hosts]
|
140
|
+
@filters << Filter.new(:role, fh[:roles]) if fh[:roles]
|
99
141
|
@filters << Filter.new(:host, fh[:host]) if fh[:host]
|
100
142
|
@filters << Filter.new(:role, fh[:role]) if fh[:role]
|
101
143
|
end
|
@@ -104,35 +146,44 @@ module Capistrano
|
|
104
146
|
cmdline_filters << Filter.new(type, values)
|
105
147
|
end
|
106
148
|
|
107
|
-
def filter
|
149
|
+
def filter(list)
|
108
150
|
setup_filters if @filters.nil?
|
109
|
-
@filters.reduce(list) { |l,f| f.filter l }
|
151
|
+
@filters.reduce(list) { |l, f| f.filter l }
|
110
152
|
end
|
111
153
|
|
112
|
-
|
154
|
+
def dry_run?
|
155
|
+
fetch(:sshkit_backend) == SSHKit::Backend::Printer
|
156
|
+
end
|
113
157
|
|
114
|
-
def
|
115
|
-
|
158
|
+
def install_plugin(plugin, load_hooks: true, load_immediately: false)
|
159
|
+
installer.install(plugin,
|
160
|
+
load_hooks: load_hooks,
|
161
|
+
load_immediately: load_immediately)
|
162
|
+
end
|
163
|
+
|
164
|
+
def scm_plugin_installed?
|
165
|
+
installer.scm_installed?
|
116
166
|
end
|
117
167
|
|
118
168
|
def servers
|
119
169
|
@servers ||= Servers.new
|
120
170
|
end
|
121
171
|
|
122
|
-
|
123
|
-
|
172
|
+
private
|
173
|
+
|
174
|
+
def cmdline_filters
|
175
|
+
@cmdline_filters ||= []
|
124
176
|
end
|
125
177
|
|
126
|
-
def
|
127
|
-
|
128
|
-
config.fetch(key, &block)
|
129
|
-
else
|
130
|
-
config.fetch(key, default)
|
131
|
-
end
|
178
|
+
def installer
|
179
|
+
@installer ||= PluginInstaller.new
|
132
180
|
end
|
133
181
|
|
134
|
-
def
|
135
|
-
|
182
|
+
def configure_sshkit_output(sshkit)
|
183
|
+
format_args = [fetch(:format)]
|
184
|
+
format_args.push(fetch(:format_options)) if any?(:format_options)
|
185
|
+
|
186
|
+
sshkit.use_format(*format_args)
|
136
187
|
end
|
137
188
|
end
|
138
189
|
end
|