capistrano 3.4.0 → 3.17.1
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.
- checksums.yaml +5 -5
- data/.circleci/config.yml +129 -0
- 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/CHANGELOG.md +1 -307
- data/CONTRIBUTING.md +63 -93
- data/DEVELOPMENT.md +127 -0
- data/Dangerfile +1 -0
- data/Gemfile +40 -3
- data/LICENSE.txt +1 -1
- data/README.md +127 -44
- data/RELEASING.md +17 -0
- data/Rakefile +13 -2
- data/UPGRADING-3.7.md +86 -0
- data/bin/cap +1 -1
- data/capistrano.gemspec +21 -24
- data/features/deploy.feature +35 -1
- data/features/doctor.feature +11 -0
- data/features/installation.feature +8 -3
- data/features/stage_failure.feature +9 -0
- data/features/step_definitions/assertions.rb +51 -18
- data/features/step_definitions/cap_commands.rb +9 -0
- data/features/step_definitions/setup.rb +53 -9
- 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/empty_filter.rb +9 -0
- data/lib/capistrano/configuration/filter.rb +17 -47
- 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 +29 -23
- data/lib/capistrano/configuration/servers.rb +21 -14
- data/lib/capistrano/configuration/validated_variables.rb +110 -0
- data/lib/capistrano/configuration/variables.rb +112 -0
- data/lib/capistrano/configuration.rb +91 -44
- data/lib/capistrano/defaults.rb +26 -4
- data/lib/capistrano/deploy.rb +1 -1
- 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 +74 -0
- data/lib/capistrano/doctor.rb +6 -0
- data/lib/capistrano/dotfile.rb +1 -2
- data/lib/capistrano/dsl/env.rb +9 -47
- 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/dsl.rb +47 -16
- 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/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/scm.rb +7 -20
- data/lib/capistrano/setup.rb +20 -6
- data/lib/capistrano/tasks/console.rake +4 -8
- data/lib/capistrano/tasks/deploy.rake +105 -73
- 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 +21 -10
- data/lib/capistrano/templates/deploy.rb.erb +17 -26
- data/lib/capistrano/templates/stage.rb.erb +9 -9
- 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 +289 -240
- 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 -85
- 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 +106 -113
- data/spec/lib/capistrano/configuration/servers_spec.rb +129 -145
- data/spec/lib/capistrano/configuration_spec.rb +224 -63
- 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 +97 -59
- 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 +9 -10
- 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 +4 -4
- data/spec/support/test_app.rb +64 -39
- metadata +100 -55
- data/.travis.yml +0 -13
- 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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require
|
|
1
|
+
require "set"
|
|
2
2
|
module Capistrano
|
|
3
3
|
class Configuration
|
|
4
4
|
class Server < SSHKit::Host
|
|
@@ -25,19 +25,21 @@ module Capistrano
|
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
def select?(options)
|
|
28
|
-
options.each do |k,v|
|
|
29
|
-
callable = v.respond_to?(:call) ? v: ->(server){server.fetch(v)}
|
|
30
|
-
result =
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
28
|
+
options.each do |k, v|
|
|
29
|
+
callable = v.respond_to?(:call) ? v : ->(server) { server.fetch(v) }
|
|
30
|
+
result = \
|
|
31
|
+
case k
|
|
32
|
+
when :filter, :select
|
|
33
|
+
callable.call(self)
|
|
34
|
+
when :exclude
|
|
35
|
+
!callable.call(self)
|
|
36
|
+
else
|
|
37
|
+
fetch(k) == v
|
|
38
|
+
end
|
|
38
39
|
return false unless result
|
|
39
40
|
end
|
|
40
|
-
|
|
41
|
+
|
|
42
|
+
true
|
|
41
43
|
end
|
|
42
44
|
|
|
43
45
|
def primary
|
|
@@ -54,7 +56,7 @@ module Capistrano
|
|
|
54
56
|
end
|
|
55
57
|
|
|
56
58
|
def netssh_options
|
|
57
|
-
@netssh_options ||= super.merge(
|
|
59
|
+
@netssh_options ||= super.merge(fetch(:ssh_options) || {})
|
|
58
60
|
end
|
|
59
61
|
|
|
60
62
|
def roles_array
|
|
@@ -62,7 +64,8 @@ module Capistrano
|
|
|
62
64
|
end
|
|
63
65
|
|
|
64
66
|
def matches?(other)
|
|
65
|
-
|
|
67
|
+
# This matching logic must stay in sync with `Servers#add_host`.
|
|
68
|
+
hostname == other.hostname && port == other.port
|
|
66
69
|
end
|
|
67
70
|
|
|
68
71
|
private
|
|
@@ -76,18 +79,17 @@ module Capistrano
|
|
|
76
79
|
end
|
|
77
80
|
|
|
78
81
|
class Properties
|
|
79
|
-
|
|
80
82
|
def initialize
|
|
81
83
|
@properties = {}
|
|
82
84
|
end
|
|
83
85
|
|
|
84
86
|
def set(key, value)
|
|
85
87
|
pval = @properties[key]
|
|
86
|
-
if pval.is_a?
|
|
88
|
+
if pval.is_a?(Hash) && value.is_a?(Hash)
|
|
87
89
|
pval.merge!(value)
|
|
88
|
-
elsif pval.is_a?
|
|
90
|
+
elsif pval.is_a?(Set) && value.is_a?(Set)
|
|
89
91
|
pval.merge(value)
|
|
90
|
-
elsif pval.is_a?
|
|
92
|
+
elsif pval.is_a?(Array) && value.is_a?(Array)
|
|
91
93
|
pval.concat value
|
|
92
94
|
else
|
|
93
95
|
@properties[key] = value
|
|
@@ -98,8 +100,8 @@ module Capistrano
|
|
|
98
100
|
@properties[key]
|
|
99
101
|
end
|
|
100
102
|
|
|
101
|
-
def
|
|
102
|
-
@properties.
|
|
103
|
+
def respond_to_missing?(method, _include_all=false)
|
|
104
|
+
@properties.key?(method) || super
|
|
103
105
|
end
|
|
104
106
|
|
|
105
107
|
def roles
|
|
@@ -110,6 +112,7 @@ module Capistrano
|
|
|
110
112
|
@properties.keys
|
|
111
113
|
end
|
|
112
114
|
|
|
115
|
+
# rubocop:disable Style/MethodMissing
|
|
113
116
|
def method_missing(key, value=nil)
|
|
114
117
|
if value
|
|
115
118
|
set(lvalue(key), value)
|
|
@@ -117,15 +120,18 @@ module Capistrano
|
|
|
117
120
|
fetch(key)
|
|
118
121
|
end
|
|
119
122
|
end
|
|
123
|
+
# rubocop:enable Style/MethodMissing
|
|
124
|
+
|
|
125
|
+
def to_h
|
|
126
|
+
@properties
|
|
127
|
+
end
|
|
120
128
|
|
|
121
129
|
private
|
|
122
130
|
|
|
123
131
|
def lvalue(key)
|
|
124
|
-
key.to_s.chomp(
|
|
132
|
+
key.to_s.chomp("=").to_sym
|
|
125
133
|
end
|
|
126
|
-
|
|
127
134
|
end
|
|
128
|
-
|
|
129
135
|
end
|
|
130
136
|
end
|
|
131
137
|
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
require
|
|
2
|
-
require
|
|
3
|
-
require
|
|
1
|
+
require "set"
|
|
2
|
+
require "capistrano/configuration"
|
|
3
|
+
require "capistrano/configuration/filter"
|
|
4
4
|
|
|
5
5
|
module Capistrano
|
|
6
6
|
class Configuration
|
|
@@ -9,23 +9,28 @@ module Capistrano
|
|
|
9
9
|
|
|
10
10
|
def add_host(host, properties={})
|
|
11
11
|
new_host = Server[host]
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
new_host.port = properties[:port] if properties.key?(:port)
|
|
13
|
+
# This matching logic must stay in sync with `Server#matches?`.
|
|
14
|
+
key = ServerKey.new(new_host.hostname, new_host.port)
|
|
15
|
+
existing = servers_by_key[key]
|
|
16
|
+
if existing
|
|
17
|
+
existing.user = new_host.user if new_host.user
|
|
18
|
+
existing.with(properties)
|
|
16
19
|
else
|
|
17
|
-
|
|
20
|
+
servers_by_key[key] = new_host.with(properties)
|
|
18
21
|
end
|
|
19
22
|
end
|
|
20
23
|
|
|
24
|
+
# rubocop:disable Security/MarshalLoad
|
|
21
25
|
def add_role(role, hosts, options={})
|
|
22
26
|
options_deepcopy = Marshal.dump(options.merge(roles: role))
|
|
23
27
|
Array(hosts).each { |host| add_host(host, Marshal.load(options_deepcopy)) }
|
|
24
28
|
end
|
|
29
|
+
# rubocop:enable Security/MarshalLoad
|
|
25
30
|
|
|
26
31
|
def roles_for(names)
|
|
27
32
|
options = extract_options(names)
|
|
28
|
-
s = Filter.new(:role, names).filter(
|
|
33
|
+
s = Filter.new(:role, names).filter(servers_by_key.values)
|
|
29
34
|
s.select { |server| server.select?(options) }
|
|
30
35
|
end
|
|
31
36
|
|
|
@@ -38,12 +43,12 @@ module Capistrano
|
|
|
38
43
|
if block_given?
|
|
39
44
|
yield host, role, props
|
|
40
45
|
else
|
|
41
|
-
rps << (props || {}).merge(
|
|
46
|
+
rps << (props || {}).merge(role: role, hostname: host.hostname)
|
|
42
47
|
end
|
|
43
48
|
end
|
|
44
49
|
end
|
|
45
50
|
end
|
|
46
|
-
block_given? ? nil: rps
|
|
51
|
+
block_given? ? nil : rps
|
|
47
52
|
end
|
|
48
53
|
|
|
49
54
|
def fetch_primary(role)
|
|
@@ -52,13 +57,15 @@ module Capistrano
|
|
|
52
57
|
end
|
|
53
58
|
|
|
54
59
|
def each
|
|
55
|
-
|
|
60
|
+
servers_by_key.values.each { |server| yield server }
|
|
56
61
|
end
|
|
57
62
|
|
|
58
63
|
private
|
|
59
64
|
|
|
60
|
-
|
|
61
|
-
|
|
65
|
+
ServerKey = Struct.new(:hostname, :port)
|
|
66
|
+
|
|
67
|
+
def servers_by_key
|
|
68
|
+
@servers_by_key ||= {}
|
|
62
69
|
end
|
|
63
70
|
|
|
64
71
|
def extract_options(array)
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
require "capistrano/proc_helpers"
|
|
2
|
+
require "delegate"
|
|
3
|
+
|
|
4
|
+
module Capistrano
|
|
5
|
+
class Configuration
|
|
6
|
+
# Decorates a Variables object to additionally perform an optional set of
|
|
7
|
+
# user-supplied validation rules. Each rule for a given key is invoked
|
|
8
|
+
# immediately whenever `set` is called with a value for that key.
|
|
9
|
+
#
|
|
10
|
+
# If `set` is called with a callable value or a block, validation is not
|
|
11
|
+
# performed immediately. Instead, the validation rules are invoked the first
|
|
12
|
+
# time `fetch` is used to access the value.
|
|
13
|
+
#
|
|
14
|
+
# A rule is simply a block that accepts two arguments: key and value. It is
|
|
15
|
+
# up to the rule to raise an exception when it deems the value is invalid
|
|
16
|
+
# (or just print a warning).
|
|
17
|
+
#
|
|
18
|
+
# Rules can be registered using the DSL like this:
|
|
19
|
+
#
|
|
20
|
+
# validate(:my_key) do |key, value|
|
|
21
|
+
# # rule goes here
|
|
22
|
+
# end
|
|
23
|
+
#
|
|
24
|
+
class ValidatedVariables < SimpleDelegator
|
|
25
|
+
include Capistrano::ProcHelpers
|
|
26
|
+
|
|
27
|
+
def initialize(variables)
|
|
28
|
+
super(variables)
|
|
29
|
+
@validators = {}
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Decorate Variables#set to add validation behavior.
|
|
33
|
+
def set(key, value=nil, &block)
|
|
34
|
+
assert_value_or_block_not_both(value, block)
|
|
35
|
+
|
|
36
|
+
# Skip validation behavior if no validators are registered for this key
|
|
37
|
+
return super unless validators.key?(key)
|
|
38
|
+
|
|
39
|
+
value_to_evaluate = block || value
|
|
40
|
+
|
|
41
|
+
if callable_without_parameters?(value_to_evaluate)
|
|
42
|
+
super(key, assert_valid_later(key, value_to_evaluate), &nil)
|
|
43
|
+
else
|
|
44
|
+
assert_valid_now(key, value_to_evaluate)
|
|
45
|
+
super
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# Register a validation rule for the given key.
|
|
50
|
+
def validate(key, &validator)
|
|
51
|
+
vs = (validators[key] || [])
|
|
52
|
+
vs << validator
|
|
53
|
+
validators[key] = vs
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
private
|
|
57
|
+
|
|
58
|
+
attr_reader :validators
|
|
59
|
+
|
|
60
|
+
# Given a callable that provides a value, wrap the callable with another
|
|
61
|
+
# object that responds to `call`. This new object will perform validation
|
|
62
|
+
# and then return the original callable's value.
|
|
63
|
+
#
|
|
64
|
+
# If the callable is a `Question`, the object returned by this method will
|
|
65
|
+
# also be a `Question` (a `ValidatedQuestion`, to be precise). This
|
|
66
|
+
# ensures that `is_a?(Question)` remains true even after the validation
|
|
67
|
+
# wrapper is applied. This is needed so that `Configuration#is_question?`
|
|
68
|
+
# works as expected.
|
|
69
|
+
#
|
|
70
|
+
def assert_valid_later(key, callable)
|
|
71
|
+
validation_callback = lambda do
|
|
72
|
+
value = callable.call
|
|
73
|
+
assert_valid_now(key, value)
|
|
74
|
+
value
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
if callable.is_a?(Question)
|
|
78
|
+
ValidatedQuestion.new(validation_callback)
|
|
79
|
+
else
|
|
80
|
+
validation_callback
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# Runs all validation rules registered for the given key against the
|
|
85
|
+
# user-supplied value for that variable. If no validator raises an
|
|
86
|
+
# exception, the value is assumed to be valid.
|
|
87
|
+
def assert_valid_now(key, value)
|
|
88
|
+
validators[key].each do |validator|
|
|
89
|
+
validator.call(key, value)
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def assert_value_or_block_not_both(value, block)
|
|
94
|
+
return if value.nil? || block.nil?
|
|
95
|
+
raise Capistrano::ValidationError,
|
|
96
|
+
"Value and block both passed to Configuration#set"
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
class ValidatedQuestion < Question
|
|
100
|
+
def initialize(validator)
|
|
101
|
+
@validator = validator
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def call
|
|
105
|
+
@validator.call
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
require "capistrano/proc_helpers"
|
|
2
|
+
|
|
3
|
+
module Capistrano
|
|
4
|
+
class Configuration
|
|
5
|
+
# Holds the variables assigned at Capistrano runtime via `set` and retrieved
|
|
6
|
+
# with `fetch`. Does internal bookkeeping to help identify user mistakes
|
|
7
|
+
# like spelling errors or unused variables that may lead to unexpected
|
|
8
|
+
# behavior.
|
|
9
|
+
class Variables
|
|
10
|
+
CAPISTRANO_LOCATION = File.expand_path("../..", __FILE__).freeze
|
|
11
|
+
IGNORED_LOCATIONS = [
|
|
12
|
+
"#{CAPISTRANO_LOCATION}/configuration/variables.rb:",
|
|
13
|
+
"#{CAPISTRANO_LOCATION}/configuration.rb:",
|
|
14
|
+
"#{CAPISTRANO_LOCATION}/dsl/env.rb:",
|
|
15
|
+
"/dsl.rb:",
|
|
16
|
+
"/forwardable.rb:"
|
|
17
|
+
].freeze
|
|
18
|
+
private_constant :CAPISTRANO_LOCATION, :IGNORED_LOCATIONS
|
|
19
|
+
|
|
20
|
+
include Capistrano::ProcHelpers
|
|
21
|
+
|
|
22
|
+
def initialize(values={})
|
|
23
|
+
@trusted_keys = []
|
|
24
|
+
@fetched_keys = []
|
|
25
|
+
@locations = {}
|
|
26
|
+
@values = values
|
|
27
|
+
@trusted = true
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def untrusted!
|
|
31
|
+
@trusted = false
|
|
32
|
+
yield
|
|
33
|
+
ensure
|
|
34
|
+
@trusted = true
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def set(key, value=nil, &block)
|
|
38
|
+
@trusted_keys << key if trusted? && !@trusted_keys.include?(key)
|
|
39
|
+
remember_location(key)
|
|
40
|
+
values[key] = block || value
|
|
41
|
+
trace_set(key)
|
|
42
|
+
values[key]
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def fetch(key, default=nil, &block)
|
|
46
|
+
fetched_keys << key unless fetched_keys.include?(key)
|
|
47
|
+
peek(key, default, &block)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Internal use only.
|
|
51
|
+
def peek(key, default=nil, &block)
|
|
52
|
+
value = fetch_for(key, default, &block)
|
|
53
|
+
while callable_without_parameters?(value)
|
|
54
|
+
value = (values[key] = value.call)
|
|
55
|
+
end
|
|
56
|
+
value
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def fetch_for(key, default, &block)
|
|
60
|
+
block ? values.fetch(key, &block) : values.fetch(key, default)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def delete(key)
|
|
64
|
+
values.delete(key)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def trusted_keys
|
|
68
|
+
@trusted_keys.dup
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def untrusted_keys
|
|
72
|
+
keys - @trusted_keys
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def keys
|
|
76
|
+
values.keys
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# Keys that have been set, but which have never been fetched.
|
|
80
|
+
def unused_keys
|
|
81
|
+
keys - fetched_keys
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# Returns an array of source file location(s) where the given key was
|
|
85
|
+
# assigned (i.e. where `set` was called). If the key was never assigned,
|
|
86
|
+
# returns `nil`.
|
|
87
|
+
def source_locations(key)
|
|
88
|
+
locations[key]
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
private
|
|
92
|
+
|
|
93
|
+
attr_reader :locations, :values, :fetched_keys
|
|
94
|
+
|
|
95
|
+
def trusted?
|
|
96
|
+
@trusted
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def remember_location(key)
|
|
100
|
+
location = caller.find do |line|
|
|
101
|
+
IGNORED_LOCATIONS.none? { |i| line.include?(i) }
|
|
102
|
+
end
|
|
103
|
+
(locations[key] ||= []) << location
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def trace_set(key)
|
|
107
|
+
return unless fetch(:print_config_variables, false)
|
|
108
|
+
puts "Config variable set: #{key.inspect} => #{values[key].inspect}"
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
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)
|
|
@@ -79,27 +94,50 @@ module Capistrano
|
|
|
79
94
|
|
|
80
95
|
def configure_backend
|
|
81
96
|
backend.configure do |sshkit|
|
|
82
|
-
sshkit
|
|
97
|
+
configure_sshkit_output(sshkit)
|
|
83
98
|
sshkit.output_verbosity = fetch(:log_level)
|
|
84
99
|
sshkit.default_env = fetch(:default_env)
|
|
85
100
|
sshkit.backend = fetch(:sshkit_backend, SSHKit::Backend::Netssh)
|
|
86
101
|
sshkit.backend.configure do |backend|
|
|
87
102
|
backend.pty = fetch(:pty)
|
|
88
103
|
backend.connection_timeout = fetch(:connection_timeout)
|
|
89
|
-
backend.ssh_options = (backend.ssh_options || {}).merge(fetch(:ssh_options,{}))
|
|
104
|
+
backend.ssh_options = (backend.ssh_options || {}).merge(fetch(:ssh_options, {}))
|
|
90
105
|
end
|
|
91
106
|
end
|
|
92
107
|
end
|
|
93
108
|
|
|
109
|
+
def configure_scm
|
|
110
|
+
Capistrano::Configuration::SCMResolver.new.resolve
|
|
111
|
+
end
|
|
112
|
+
|
|
94
113
|
def timestamp
|
|
95
114
|
@timestamp ||= Time.now.utc
|
|
96
115
|
end
|
|
97
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
|
+
|
|
98
133
|
def setup_filters
|
|
99
|
-
@filters = cmdline_filters
|
|
100
|
-
@filters
|
|
101
|
-
@filters << Filter.new(:
|
|
102
|
-
|
|
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]
|
|
103
141
|
@filters << Filter.new(:host, fh[:host]) if fh[:host]
|
|
104
142
|
@filters << Filter.new(:role, fh[:role]) if fh[:role]
|
|
105
143
|
end
|
|
@@ -108,35 +146,44 @@ module Capistrano
|
|
|
108
146
|
cmdline_filters << Filter.new(type, values)
|
|
109
147
|
end
|
|
110
148
|
|
|
111
|
-
def filter
|
|
149
|
+
def filter(list)
|
|
112
150
|
setup_filters if @filters.nil?
|
|
113
|
-
@filters.reduce(list) { |l,f| f.filter l }
|
|
151
|
+
@filters.reduce(list) { |l, f| f.filter l }
|
|
114
152
|
end
|
|
115
153
|
|
|
116
|
-
|
|
154
|
+
def dry_run?
|
|
155
|
+
fetch(:sshkit_backend) == SSHKit::Backend::Printer
|
|
156
|
+
end
|
|
117
157
|
|
|
118
|
-
def
|
|
119
|
-
|
|
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?
|
|
120
166
|
end
|
|
121
167
|
|
|
122
168
|
def servers
|
|
123
169
|
@servers ||= Servers.new
|
|
124
170
|
end
|
|
125
171
|
|
|
126
|
-
|
|
127
|
-
|
|
172
|
+
private
|
|
173
|
+
|
|
174
|
+
def cmdline_filters
|
|
175
|
+
@cmdline_filters ||= []
|
|
128
176
|
end
|
|
129
177
|
|
|
130
|
-
def
|
|
131
|
-
|
|
132
|
-
config.fetch(key, &block)
|
|
133
|
-
else
|
|
134
|
-
config.fetch(key, default)
|
|
135
|
-
end
|
|
178
|
+
def installer
|
|
179
|
+
@installer ||= PluginInstaller.new
|
|
136
180
|
end
|
|
137
181
|
|
|
138
|
-
def
|
|
139
|
-
|
|
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)
|
|
140
187
|
end
|
|
141
188
|
end
|
|
142
189
|
end
|
data/lib/capistrano/defaults.rb
CHANGED
|
@@ -1,14 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
validate :application do |_key, value|
|
|
2
|
+
changed_value = value.gsub(/[^A-Z0-9\.\-]/i, "_")
|
|
3
|
+
if value != changed_value
|
|
4
|
+
warn %Q(The :application value "#{value}" is invalid!)
|
|
5
|
+
warn "Use only letters, numbers, hyphens, dots, and underscores. For example:"
|
|
6
|
+
warn " set :application, '#{changed_value}'"
|
|
7
|
+
raise Capistrano::ValidationError
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
%i(git_strategy hg_strategy svn_strategy).each do |strategy|
|
|
12
|
+
validate(strategy) do |key, _value|
|
|
13
|
+
warn(
|
|
14
|
+
"[Deprecation Warning] #{key} is deprecated and will be removed in "\
|
|
15
|
+
"Capistrano 3.7.0.\n"\
|
|
16
|
+
"https://github.com/capistrano/capistrano/blob/master/UPGRADING-3.7.md"
|
|
17
|
+
)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# We use a special :_default_git value so that SCMResolver can tell whether the
|
|
22
|
+
# default has been replaced by the user via `set`.
|
|
23
|
+
set_if_empty :scm, Capistrano::Configuration::SCMResolver::DEFAULT_GIT
|
|
24
|
+
set_if_empty :branch, "master"
|
|
3
25
|
set_if_empty :deploy_to, -> { "/var/www/#{fetch(:application)}" }
|
|
4
26
|
set_if_empty :tmp_dir, "/tmp"
|
|
5
27
|
|
|
6
28
|
set_if_empty :default_env, {}
|
|
7
29
|
set_if_empty :keep_releases, 5
|
|
8
30
|
|
|
9
|
-
set_if_empty :format, :
|
|
31
|
+
set_if_empty :format, :airbrussh
|
|
10
32
|
set_if_empty :log_level, :debug
|
|
11
33
|
|
|
12
34
|
set_if_empty :pty, false
|
|
13
35
|
|
|
14
|
-
set_if_empty :local_user, -> {
|
|
36
|
+
set_if_empty :local_user, -> { ENV["USER"] || ENV["LOGNAME"] || ENV["USERNAME"] }
|
data/lib/capistrano/deploy.rb
CHANGED