piko-fast-tool 0.0.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 +7 -0
- data/capistrano-3.20.1/CHANGELOG.md +1 -0
- data/capistrano-3.20.1/CONTRIBUTING.md +63 -0
- data/capistrano-3.20.1/DEVELOPMENT.md +112 -0
- data/capistrano-3.20.1/Gemfile +9 -0
- data/capistrano-3.20.1/LICENSE.txt +21 -0
- data/capistrano-3.20.1/README.md +221 -0
- data/capistrano-3.20.1/RELEASING.md +17 -0
- data/capistrano-3.20.1/Rakefile +24 -0
- data/capistrano-3.20.1/UPGRADING-3.7.md +86 -0
- data/capistrano-3.20.1/bin/cap +3 -0
- data/capistrano-3.20.1/bin/capify +8 -0
- data/capistrano-3.20.1/capistrano.gemspec +34 -0
- data/capistrano-3.20.1/docker-compose.yml +8 -0
- data/capistrano-3.20.1/features/configuration.feature +28 -0
- data/capistrano-3.20.1/features/deploy.feature +92 -0
- data/capistrano-3.20.1/features/deploy_failure.feature +17 -0
- data/capistrano-3.20.1/features/doctor.feature +11 -0
- data/capistrano-3.20.1/features/installation.feature +21 -0
- data/capistrano-3.20.1/features/sshconnect.feature +11 -0
- data/capistrano-3.20.1/features/stage_failure.feature +9 -0
- data/capistrano-3.20.1/features/step_definitions/assertions.rb +162 -0
- data/capistrano-3.20.1/features/step_definitions/cap_commands.rb +21 -0
- data/capistrano-3.20.1/features/step_definitions/setup.rb +91 -0
- data/capistrano-3.20.1/features/subdirectory.feature +9 -0
- data/capistrano-3.20.1/features/support/docker_gateway.rb +53 -0
- data/capistrano-3.20.1/features/support/env.rb +1 -0
- data/capistrano-3.20.1/features/support/remote_command_helpers.rb +29 -0
- data/capistrano-3.20.1/features/support/remote_ssh_helpers.rb +33 -0
- data/capistrano-3.20.1/gemfiles/legacy.gemfile +7 -0
- data/capistrano-3.20.1/lib/Capfile +3 -0
- data/capistrano-3.20.1/lib/capistrano/all.rb +17 -0
- data/capistrano-3.20.1/lib/capistrano/application.rb +153 -0
- data/capistrano-3.20.1/lib/capistrano/configuration/empty_filter.rb +9 -0
- data/capistrano-3.20.1/lib/capistrano/configuration/filter.rb +26 -0
- data/capistrano-3.20.1/lib/capistrano/configuration/host_filter.rb +29 -0
- data/capistrano-3.20.1/lib/capistrano/configuration/null_filter.rb +9 -0
- data/capistrano-3.20.1/lib/capistrano/configuration/plugin_installer.rb +51 -0
- data/capistrano-3.20.1/lib/capistrano/configuration/question.rb +76 -0
- data/capistrano-3.20.1/lib/capistrano/configuration/role_filter.rb +29 -0
- data/capistrano-3.20.1/lib/capistrano/configuration/scm_resolver.rb +149 -0
- data/capistrano-3.20.1/lib/capistrano/configuration/server.rb +135 -0
- data/capistrano-3.20.1/lib/capistrano/configuration/servers.rb +76 -0
- data/capistrano-3.20.1/lib/capistrano/configuration/validated_variables.rb +110 -0
- data/capistrano-3.20.1/lib/capistrano/configuration/variables.rb +112 -0
- data/capistrano-3.20.1/lib/capistrano/configuration.rb +189 -0
- data/capistrano-3.20.1/lib/capistrano/console.rb +1 -0
- data/capistrano-3.20.1/lib/capistrano/defaults.rb +36 -0
- data/capistrano-3.20.1/lib/capistrano/deploy.rb +3 -0
- data/capistrano-3.20.1/lib/capistrano/doctor/environment_doctor.rb +19 -0
- data/capistrano-3.20.1/lib/capistrano/doctor/gems_doctor.rb +45 -0
- data/capistrano-3.20.1/lib/capistrano/doctor/output_helpers.rb +79 -0
- data/capistrano-3.20.1/lib/capistrano/doctor/servers_doctor.rb +105 -0
- data/capistrano-3.20.1/lib/capistrano/doctor/variables_doctor.rb +74 -0
- data/capistrano-3.20.1/lib/capistrano/doctor.rb +6 -0
- data/capistrano-3.20.1/lib/capistrano/dotfile.rb +2 -0
- data/capistrano-3.20.1/lib/capistrano/dsl/env.rb +43 -0
- data/capistrano-3.20.1/lib/capistrano/dsl/paths.rb +89 -0
- data/capistrano-3.20.1/lib/capistrano/dsl/stages.rb +31 -0
- data/capistrano-3.20.1/lib/capistrano/dsl/task_enhancements.rb +61 -0
- data/capistrano-3.20.1/lib/capistrano/dsl.rb +95 -0
- data/capistrano-3.20.1/lib/capistrano/framework.rb +2 -0
- data/capistrano-3.20.1/lib/capistrano/i18n.rb +46 -0
- data/capistrano-3.20.1/lib/capistrano/immutable_task.rb +30 -0
- data/capistrano-3.20.1/lib/capistrano/install.rb +1 -0
- data/capistrano-3.20.1/lib/capistrano/plugin.rb +95 -0
- data/capistrano-3.20.1/lib/capistrano/proc_helpers.rb +13 -0
- data/capistrano-3.20.1/lib/capistrano/scm/git.rb +106 -0
- data/capistrano-3.20.1/lib/capistrano/scm/hg.rb +55 -0
- data/capistrano-3.20.1/lib/capistrano/scm/plugin.rb +13 -0
- data/capistrano-3.20.1/lib/capistrano/scm/svn.rb +56 -0
- data/capistrano-3.20.1/lib/capistrano/scm/tasks/git.rake +84 -0
- data/capistrano-3.20.1/lib/capistrano/scm/tasks/hg.rake +53 -0
- data/capistrano-3.20.1/lib/capistrano/scm/tasks/svn.rake +53 -0
- data/capistrano-3.20.1/lib/capistrano/scm.rb +115 -0
- data/capistrano-3.20.1/lib/capistrano/setup.rb +36 -0
- data/capistrano-3.20.1/lib/capistrano/tasks/console.rake +25 -0
- data/capistrano-3.20.1/lib/capistrano/tasks/deploy.rake +280 -0
- data/capistrano-3.20.1/lib/capistrano/tasks/doctor.rake +24 -0
- data/capistrano-3.20.1/lib/capistrano/tasks/framework.rake +67 -0
- data/capistrano-3.20.1/lib/capistrano/tasks/install.rake +41 -0
- data/capistrano-3.20.1/lib/capistrano/templates/Capfile +38 -0
- data/capistrano-3.20.1/lib/capistrano/templates/deploy.rb.erb +39 -0
- data/capistrano-3.20.1/lib/capistrano/templates/stage.rb.erb +61 -0
- data/capistrano-3.20.1/lib/capistrano/upload_task.rb +9 -0
- data/capistrano-3.20.1/lib/capistrano/version.rb +3 -0
- data/capistrano-3.20.1/lib/capistrano/version_validator.rb +32 -0
- data/capistrano-3.20.1/lib/capistrano.rb +0 -0
- data/capistrano-3.20.1/spec/integration/dsl_spec.rb +632 -0
- data/capistrano-3.20.1/spec/integration_spec_helper.rb +5 -0
- data/capistrano-3.20.1/spec/lib/capistrano/application_spec.rb +60 -0
- data/capistrano-3.20.1/spec/lib/capistrano/configuration/empty_filter_spec.rb +17 -0
- data/capistrano-3.20.1/spec/lib/capistrano/configuration/filter_spec.rb +109 -0
- data/capistrano-3.20.1/spec/lib/capistrano/configuration/host_filter_spec.rb +71 -0
- data/capistrano-3.20.1/spec/lib/capistrano/configuration/null_filter_spec.rb +17 -0
- data/capistrano-3.20.1/spec/lib/capistrano/configuration/plugin_installer_spec.rb +98 -0
- data/capistrano-3.20.1/spec/lib/capistrano/configuration/question_spec.rb +92 -0
- data/capistrano-3.20.1/spec/lib/capistrano/configuration/role_filter_spec.rb +80 -0
- data/capistrano-3.20.1/spec/lib/capistrano/configuration/scm_resolver_spec.rb +56 -0
- data/capistrano-3.20.1/spec/lib/capistrano/configuration/server_spec.rb +309 -0
- data/capistrano-3.20.1/spec/lib/capistrano/configuration/servers_spec.rb +331 -0
- data/capistrano-3.20.1/spec/lib/capistrano/configuration_spec.rb +357 -0
- data/capistrano-3.20.1/spec/lib/capistrano/doctor/environment_doctor_spec.rb +44 -0
- data/capistrano-3.20.1/spec/lib/capistrano/doctor/gems_doctor_spec.rb +67 -0
- data/capistrano-3.20.1/spec/lib/capistrano/doctor/output_helpers_spec.rb +47 -0
- data/capistrano-3.20.1/spec/lib/capistrano/doctor/servers_doctor_spec.rb +86 -0
- data/capistrano-3.20.1/spec/lib/capistrano/doctor/variables_doctor_spec.rb +89 -0
- data/capistrano-3.20.1/spec/lib/capistrano/dsl/paths_spec.rb +228 -0
- data/capistrano-3.20.1/spec/lib/capistrano/dsl/task_enhancements_spec.rb +108 -0
- data/capistrano-3.20.1/spec/lib/capistrano/dsl_spec.rb +125 -0
- data/capistrano-3.20.1/spec/lib/capistrano/immutable_task_spec.rb +31 -0
- data/capistrano-3.20.1/spec/lib/capistrano/plugin_spec.rb +84 -0
- data/capistrano-3.20.1/spec/lib/capistrano/scm/git_spec.rb +194 -0
- data/capistrano-3.20.1/spec/lib/capistrano/scm/hg_spec.rb +109 -0
- data/capistrano-3.20.1/spec/lib/capistrano/scm/svn_spec.rb +137 -0
- data/capistrano-3.20.1/spec/lib/capistrano/scm_spec.rb +103 -0
- data/capistrano-3.20.1/spec/lib/capistrano/upload_task_spec.rb +19 -0
- data/capistrano-3.20.1/spec/lib/capistrano/version_validator_spec.rb +118 -0
- data/capistrano-3.20.1/spec/lib/capistrano_spec.rb +7 -0
- data/capistrano-3.20.1/spec/spec_helper.rb +29 -0
- data/capistrano-3.20.1/spec/support/matchers.rb +5 -0
- data/capistrano-3.20.1/spec/support/tasks/database.rake +11 -0
- data/capistrano-3.20.1/spec/support/tasks/fail.rake +8 -0
- data/capistrano-3.20.1/spec/support/tasks/failed.rake +5 -0
- data/capistrano-3.20.1/spec/support/tasks/plugin.rake +6 -0
- data/capistrano-3.20.1/spec/support/tasks/root.rake +11 -0
- data/capistrano-3.20.1/spec/support/test_app.rb +205 -0
- data/piko-fast-tool.gemspec +11 -0
- metadata +167 -0
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
module Capistrano
|
|
2
|
+
class Application < Rake::Application
|
|
3
|
+
def initialize
|
|
4
|
+
super
|
|
5
|
+
@rakefiles = %w{capfile Capfile capfile.rb Capfile.rb}
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def name
|
|
9
|
+
"cap"
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def run
|
|
13
|
+
Rake.application = self
|
|
14
|
+
super
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def sort_options(options)
|
|
18
|
+
not_applicable_to_capistrano = %w(quiet silent verbose)
|
|
19
|
+
options.reject! do |(switch, *)|
|
|
20
|
+
switch =~ /--#{Regexp.union(not_applicable_to_capistrano)}/
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
super.push(version, dry_run, roles, hostfilter, print_config_variables)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def handle_options
|
|
27
|
+
options.rakelib = ["rakelib"]
|
|
28
|
+
options.trace_output = $stderr
|
|
29
|
+
|
|
30
|
+
OptionParser.new do |opts|
|
|
31
|
+
opts.banner = "See full documentation at http://capistranorb.com/."
|
|
32
|
+
opts.separator ""
|
|
33
|
+
opts.separator "Install capistrano in a project:"
|
|
34
|
+
opts.separator " bundle exec cap install [STAGES=qa,staging,production,...]"
|
|
35
|
+
opts.separator ""
|
|
36
|
+
opts.separator "Show available tasks:"
|
|
37
|
+
opts.separator " bundle exec cap -T"
|
|
38
|
+
opts.separator ""
|
|
39
|
+
opts.separator "Invoke (or simulate invoking) a task:"
|
|
40
|
+
opts.separator " bundle exec cap [--dry-run] STAGE TASK"
|
|
41
|
+
opts.separator ""
|
|
42
|
+
opts.separator "Advanced options:"
|
|
43
|
+
|
|
44
|
+
opts.on_tail("-h", "--help", "-H", "Display this help message.") do
|
|
45
|
+
puts opts
|
|
46
|
+
exit
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
standard_rake_options.each { |args| opts.on(*args) }
|
|
50
|
+
opts.environment("RAKEOPT")
|
|
51
|
+
end.parse!
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def top_level_tasks
|
|
55
|
+
if tasks_without_stage_dependency.include?(@top_level_tasks.first)
|
|
56
|
+
@top_level_tasks
|
|
57
|
+
else
|
|
58
|
+
@top_level_tasks.unshift(ensure_stage.to_s)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def display_error_message(ex)
|
|
63
|
+
unless options.backtrace
|
|
64
|
+
Rake.application.options.suppress_backtrace_pattern = backtrace_pattern if backtrace_pattern
|
|
65
|
+
trace "(Backtrace restricted to imported tasks)"
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
super
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def exit_because_of_exception(ex)
|
|
72
|
+
if respond_to?(:deploying?) && deploying?
|
|
73
|
+
exit_deploy_because_of_exception(ex)
|
|
74
|
+
else
|
|
75
|
+
super
|
|
76
|
+
end
|
|
77
|
+
end
|
|
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
|
+
|
|
88
|
+
private
|
|
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
|
+
|
|
98
|
+
def load_imports
|
|
99
|
+
if options.show_tasks && Rake::Task.task_defined?("load:defaults")
|
|
100
|
+
invoke "load:defaults"
|
|
101
|
+
set(:stage, "")
|
|
102
|
+
Dir[deploy_config_path].each { |f| add_import f }
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
super
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def capfile
|
|
109
|
+
File.expand_path(File.join(File.dirname(__FILE__), "..", "Capfile"))
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def version
|
|
113
|
+
["--version", "-V",
|
|
114
|
+
"Display the program version.",
|
|
115
|
+
lambda do |_value|
|
|
116
|
+
puts "Capistrano Version: #{Capistrano::VERSION} (Rake Version: #{Rake::VERSION})"
|
|
117
|
+
exit
|
|
118
|
+
end]
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def dry_run
|
|
122
|
+
["--dry-run", "-n",
|
|
123
|
+
"Do a dry run without executing actions",
|
|
124
|
+
lambda do |_value|
|
|
125
|
+
Configuration.env.set(:sshkit_backend, SSHKit::Backend::Printer)
|
|
126
|
+
end]
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def roles
|
|
130
|
+
["--roles ROLES", "-r",
|
|
131
|
+
"Run SSH commands only on hosts matching these roles",
|
|
132
|
+
lambda do |value|
|
|
133
|
+
Configuration.env.add_cmdline_filter(:role, value)
|
|
134
|
+
end]
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def hostfilter
|
|
138
|
+
["--hosts HOSTS", "-z",
|
|
139
|
+
"Run SSH commands only on matching hosts",
|
|
140
|
+
lambda do |value|
|
|
141
|
+
Configuration.env.add_cmdline_filter(:host, value)
|
|
142
|
+
end]
|
|
143
|
+
end
|
|
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
|
|
152
|
+
end
|
|
153
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
require "capistrano/configuration"
|
|
2
|
+
require "capistrano/configuration/empty_filter"
|
|
3
|
+
require "capistrano/configuration/host_filter"
|
|
4
|
+
require "capistrano/configuration/null_filter"
|
|
5
|
+
require "capistrano/configuration/role_filter"
|
|
6
|
+
|
|
7
|
+
module Capistrano
|
|
8
|
+
class Configuration
|
|
9
|
+
class Filter
|
|
10
|
+
def initialize(type, values=nil)
|
|
11
|
+
raise "Invalid filter type #{type}" unless %i(host role).include? type
|
|
12
|
+
av = Array(values)
|
|
13
|
+
@strategy = if av.empty? then EmptyFilter.new
|
|
14
|
+
elsif av.include?(:all) || av.include?("all") then NullFilter.new
|
|
15
|
+
elsif type == :host then HostFilter.new(values)
|
|
16
|
+
elsif type == :role then RoleFilter.new(values)
|
|
17
|
+
else NullFilter.new
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def filter(servers)
|
|
22
|
+
@strategy.filter servers
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module Capistrano
|
|
2
|
+
class Configuration
|
|
3
|
+
class HostFilter
|
|
4
|
+
def initialize(values)
|
|
5
|
+
av = Array(values).dup
|
|
6
|
+
av = av.flat_map { |v| v.is_a?(String) && v =~ /^(?<name>[-A-Za-z0-9.]+)(,\g<name>)*$/ ? v.split(",") : v }
|
|
7
|
+
@rex = regex_matcher(av)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def filter(servers)
|
|
11
|
+
Array(servers).select { |s| @rex.match s.to_s }
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
private
|
|
15
|
+
|
|
16
|
+
def regex_matcher(values)
|
|
17
|
+
values.map! do |v|
|
|
18
|
+
case v
|
|
19
|
+
when Regexp then v
|
|
20
|
+
else
|
|
21
|
+
vs = v.to_s
|
|
22
|
+
vs =~ /^[-A-Za-z0-9.]+$/ ? /^#{Regexp.quote(vs)}$/ : Regexp.new(vs)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
Regexp.union values
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Encapsulates the logic for installing plugins into Capistrano. Plugins must
|
|
2
|
+
# simply conform to a basic API; the PluginInstaller takes care of invoking the
|
|
3
|
+
# API at appropriate times.
|
|
4
|
+
#
|
|
5
|
+
# This class is not used directly; instead it is typically accessed via the
|
|
6
|
+
# `install_plugin` method of the Capistrano DSL.
|
|
7
|
+
#
|
|
8
|
+
module Capistrano
|
|
9
|
+
class Configuration
|
|
10
|
+
class PluginInstaller
|
|
11
|
+
# "Installs" a Plugin into Capistrano by loading its tasks, hooks, and
|
|
12
|
+
# defaults at the appropriate time. The hooks in particular can be
|
|
13
|
+
# skipped, if you want full control over when and how the plugin's tasks
|
|
14
|
+
# are executed. Simply pass `load_hooks:false` to opt out.
|
|
15
|
+
#
|
|
16
|
+
# The plugin class or instance may be provided. These are equivalent:
|
|
17
|
+
#
|
|
18
|
+
# install(Capistrano::SCM::Git)
|
|
19
|
+
# install(Capistrano::SCM::Git.new)
|
|
20
|
+
#
|
|
21
|
+
# Note that the :load_immediately flag is for internal use only and will
|
|
22
|
+
# be removed in an upcoming release.
|
|
23
|
+
#
|
|
24
|
+
def install(plugin, load_hooks: true, load_immediately: false)
|
|
25
|
+
plugin = plugin.is_a?(Class) ? plugin.new : plugin
|
|
26
|
+
|
|
27
|
+
plugin.define_tasks
|
|
28
|
+
plugin.register_hooks if load_hooks
|
|
29
|
+
@scm_installed ||= provides_scm?(plugin)
|
|
30
|
+
|
|
31
|
+
if load_immediately
|
|
32
|
+
plugin.set_defaults
|
|
33
|
+
else
|
|
34
|
+
Rake::Task.define_task("load:defaults") do
|
|
35
|
+
plugin.set_defaults
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def scm_installed?
|
|
41
|
+
@scm_installed
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
private
|
|
45
|
+
|
|
46
|
+
def provides_scm?(plugin)
|
|
47
|
+
plugin.respond_to?(:scm?) && plugin.scm?
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
module Capistrano
|
|
2
|
+
class Configuration
|
|
3
|
+
class Question
|
|
4
|
+
def initialize(key, default, options={})
|
|
5
|
+
@key = key
|
|
6
|
+
@default = default
|
|
7
|
+
@options = options
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def call
|
|
11
|
+
ask_question
|
|
12
|
+
value_or_default
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
private
|
|
16
|
+
|
|
17
|
+
attr_reader :key, :default, :options
|
|
18
|
+
|
|
19
|
+
def ask_question
|
|
20
|
+
$stdout.print question
|
|
21
|
+
$stdout.flush
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def value_or_default
|
|
25
|
+
if response.empty?
|
|
26
|
+
default
|
|
27
|
+
else
|
|
28
|
+
response
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def response
|
|
33
|
+
return @response if defined? @response
|
|
34
|
+
|
|
35
|
+
@response = (gets || "").chomp
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def gets
|
|
39
|
+
return unless stdin.tty?
|
|
40
|
+
|
|
41
|
+
if echo?
|
|
42
|
+
stdin.gets
|
|
43
|
+
else
|
|
44
|
+
stdin.noecho(&:gets).tap { $stdout.print "\n" }
|
|
45
|
+
end
|
|
46
|
+
rescue Errno::EIO
|
|
47
|
+
# when stdio gets closed
|
|
48
|
+
return
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def question
|
|
52
|
+
if prompt && default.nil?
|
|
53
|
+
I18n.t(:question_prompt, key: prompt, scope: :capistrano)
|
|
54
|
+
elsif prompt
|
|
55
|
+
I18n.t(:question_prompt_default, key: prompt, default_value: default, scope: :capistrano)
|
|
56
|
+
elsif default.nil?
|
|
57
|
+
I18n.t(:question, key: key, scope: :capistrano)
|
|
58
|
+
else
|
|
59
|
+
I18n.t(:question_default, key: key, default_value: default, scope: :capistrano)
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def echo?
|
|
64
|
+
(options || {}).fetch(:echo, true)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def stdin
|
|
68
|
+
(options || {}).fetch(:stdin, $stdin)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def prompt
|
|
72
|
+
(options || {}).fetch(:prompt, nil)
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module Capistrano
|
|
2
|
+
class Configuration
|
|
3
|
+
class RoleFilter
|
|
4
|
+
def initialize(values)
|
|
5
|
+
av = Array(values).dup
|
|
6
|
+
av = av.flat_map { |v| v.is_a?(String) ? v.split(",") : v }
|
|
7
|
+
@rex = regex_matcher(av)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def filter(servers)
|
|
11
|
+
Array(servers).select { |s| s.is_a?(String) ? false : s.roles.any? { |r| @rex.match r } }
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
private
|
|
15
|
+
|
|
16
|
+
def regex_matcher(values)
|
|
17
|
+
values.map! do |v|
|
|
18
|
+
case v
|
|
19
|
+
when Regexp then v
|
|
20
|
+
else
|
|
21
|
+
vs = v.to_s
|
|
22
|
+
vs =~ %r{^/(.+)/$} ? Regexp.new($1) : /^#{Regexp.quote(vs)}$/
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
Regexp.union values
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
module Capistrano
|
|
2
|
+
class Configuration
|
|
3
|
+
# In earlier versions of Capistrano, users would specify the desired SCM
|
|
4
|
+
# implementation using `set :scm, :git`, for example. Capistrano would then
|
|
5
|
+
# load the matching .rb file based on this variable.
|
|
6
|
+
#
|
|
7
|
+
# Now we expect users to explicitly `require` and call `new` on the desired
|
|
8
|
+
# SCM implementation in their Capfile. The `set` technique is deprecated.
|
|
9
|
+
#
|
|
10
|
+
# This SCMResolver class takes care of managing the transition from the old
|
|
11
|
+
# to new system. It maintains the legacy behavior, but prints deprecation
|
|
12
|
+
# warnings when it is used.
|
|
13
|
+
#
|
|
14
|
+
# To maintain backwards compatibility, the resolver will load the Git SCM by
|
|
15
|
+
# if default it determines that no SCM has been explicitly specified or
|
|
16
|
+
# loaded. To force no SCM to be used at all, use `set :scm, nil`. This hack
|
|
17
|
+
# won't be necessary once backwards compatibility is removed in a future
|
|
18
|
+
# version.
|
|
19
|
+
#
|
|
20
|
+
# TODO: Remove this class entirely in Capistrano 4.0.
|
|
21
|
+
#
|
|
22
|
+
class SCMResolver
|
|
23
|
+
DEFAULT_GIT = :"default-git"
|
|
24
|
+
|
|
25
|
+
include Capistrano::DSL
|
|
26
|
+
|
|
27
|
+
def resolve
|
|
28
|
+
return if scm_name.nil?
|
|
29
|
+
set(:scm, :git) if using_default_scm?
|
|
30
|
+
|
|
31
|
+
print_deprecation_warnings_if_applicable
|
|
32
|
+
|
|
33
|
+
# Note that `scm_plugin_installed?` comes from Capistrano::DSL
|
|
34
|
+
if scm_plugin_installed?
|
|
35
|
+
delete(:scm)
|
|
36
|
+
return
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
if built_in_scm_name?
|
|
40
|
+
load_built_in_scm
|
|
41
|
+
else
|
|
42
|
+
# Compatibility with existing 3.x third-party SCMs
|
|
43
|
+
register_legacy_scm_hooks
|
|
44
|
+
load_legacy_scm_by_name
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
private
|
|
49
|
+
|
|
50
|
+
def using_default_scm?
|
|
51
|
+
return @using_default_scm if defined? @using_default_scm
|
|
52
|
+
@using_default_scm = (fetch(:scm) == DEFAULT_GIT)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def scm_name
|
|
56
|
+
fetch(:scm)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def load_built_in_scm
|
|
60
|
+
require "capistrano/scm/#{scm_name}"
|
|
61
|
+
scm_class = Object.const_get(built_in_scm_plugin_class_name)
|
|
62
|
+
# We use :load_immediately because we are initializing the SCM plugin
|
|
63
|
+
# late in the load process and therefore can't use the standard
|
|
64
|
+
# load:defaults technique.
|
|
65
|
+
install_plugin(scm_class, load_immediately: true)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def load_legacy_scm_by_name
|
|
69
|
+
load("capistrano/#{scm_name}.rb")
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def third_party_scm_name?
|
|
73
|
+
!built_in_scm_name?
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def built_in_scm_name?
|
|
77
|
+
%w(git hg svn).include?(scm_name.to_s.downcase)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def built_in_scm_plugin_class_name
|
|
81
|
+
"Capistrano::SCM::#{scm_name.to_s.capitalize}"
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# rubocop:disable Style/GuardClause
|
|
85
|
+
def register_legacy_scm_hooks
|
|
86
|
+
if Rake::Task.task_defined?("deploy:new_release_path")
|
|
87
|
+
after "deploy:new_release_path", "#{scm_name}:create_release"
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
if Rake::Task.task_defined?("deploy:check")
|
|
91
|
+
before "deploy:check", "#{scm_name}:check"
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
if Rake::Task.task_defined?("deploy:set_current_revision")
|
|
95
|
+
before "deploy:set_current_revision",
|
|
96
|
+
"#{scm_name}:set_current_revision"
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
# rubocop:enable Style/GuardClause
|
|
100
|
+
|
|
101
|
+
def print_deprecation_warnings_if_applicable
|
|
102
|
+
if using_default_scm?
|
|
103
|
+
warn_add_git_to_capfile unless scm_plugin_installed?
|
|
104
|
+
elsif built_in_scm_name?
|
|
105
|
+
warn_set_scm_is_deprecated
|
|
106
|
+
elsif third_party_scm_name?
|
|
107
|
+
warn_third_party_scm_must_be_upgraded
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def warn_set_scm_is_deprecated
|
|
112
|
+
$stderr.puts(<<-MESSAGE)
|
|
113
|
+
[Deprecation Notice] `set :scm, #{scm_name.inspect}` is deprecated.
|
|
114
|
+
To ensure your project is compatible with future versions of Capistrano,
|
|
115
|
+
remove the :scm setting and instead add these lines to your Capfile after
|
|
116
|
+
`require "capistrano/deploy"`:
|
|
117
|
+
|
|
118
|
+
require "capistrano/scm/#{scm_name}"
|
|
119
|
+
install_plugin #{built_in_scm_plugin_class_name}
|
|
120
|
+
|
|
121
|
+
MESSAGE
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def warn_add_git_to_capfile
|
|
125
|
+
$stderr.puts(<<-MESSAGE)
|
|
126
|
+
[Deprecation Notice] Future versions of Capistrano will not load the Git SCM
|
|
127
|
+
plugin by default. To silence this deprecation warning, add the following to
|
|
128
|
+
your Capfile after `require "capistrano/deploy"`:
|
|
129
|
+
|
|
130
|
+
require "capistrano/scm/git"
|
|
131
|
+
install_plugin Capistrano::SCM::Git
|
|
132
|
+
|
|
133
|
+
MESSAGE
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def warn_third_party_scm_must_be_upgraded
|
|
137
|
+
$stderr.puts(<<-MESSAGE)
|
|
138
|
+
[Deprecation Notice] `set :scm, #{scm_name.inspect}` is deprecated.
|
|
139
|
+
To ensure this custom SCM will work with future versions of Capistrano,
|
|
140
|
+
please upgrade it to a version that uses the new SCM plugin mechanism
|
|
141
|
+
documented here:
|
|
142
|
+
|
|
143
|
+
http://capistranorb.com/documentation/advanced-features/custom-scm
|
|
144
|
+
|
|
145
|
+
MESSAGE
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
end
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
require "set"
|
|
2
|
+
module Capistrano
|
|
3
|
+
class Configuration
|
|
4
|
+
class Server < SSHKit::Host
|
|
5
|
+
extend Forwardable
|
|
6
|
+
def_delegators :properties, :roles, :fetch, :set
|
|
7
|
+
|
|
8
|
+
def self.[](host)
|
|
9
|
+
host.is_a?(Server) ? host : new(host)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def add_roles(roles)
|
|
13
|
+
Array(roles).each { |role| add_role(role) }
|
|
14
|
+
self
|
|
15
|
+
end
|
|
16
|
+
alias roles= add_roles
|
|
17
|
+
|
|
18
|
+
def add_role(role)
|
|
19
|
+
roles.add role.to_sym
|
|
20
|
+
self
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def has_role?(role)
|
|
24
|
+
roles.include? role.to_sym
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def select?(options)
|
|
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
|
|
39
|
+
return false unless result
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
true
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def primary
|
|
46
|
+
self if fetch(:primary)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def with(properties)
|
|
50
|
+
properties.each { |key, value| add_property(key, value) }
|
|
51
|
+
self
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def properties
|
|
55
|
+
@properties ||= Properties.new
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def netssh_options
|
|
59
|
+
@netssh_options ||= super.merge(fetch(:ssh_options) || {})
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def roles_array
|
|
63
|
+
roles.to_a
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def matches?(other)
|
|
67
|
+
# This matching logic must stay in sync with `Servers#add_host`.
|
|
68
|
+
hostname == other.hostname && port == other.port
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
private
|
|
72
|
+
|
|
73
|
+
def add_property(key, value)
|
|
74
|
+
if respond_to?("#{key}=")
|
|
75
|
+
send("#{key}=", value)
|
|
76
|
+
else
|
|
77
|
+
set(key, value)
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
class Properties
|
|
82
|
+
def initialize
|
|
83
|
+
@properties = {}
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def set(key, value)
|
|
87
|
+
pval = @properties[key]
|
|
88
|
+
if pval.is_a?(Hash) && value.is_a?(Hash)
|
|
89
|
+
pval.merge!(value)
|
|
90
|
+
elsif pval.is_a?(Set) && value.is_a?(Set)
|
|
91
|
+
pval.merge(value)
|
|
92
|
+
elsif pval.is_a?(Array) && value.is_a?(Array)
|
|
93
|
+
pval.concat value
|
|
94
|
+
else
|
|
95
|
+
@properties[key] = value
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def fetch(key)
|
|
100
|
+
@properties[key]
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def respond_to_missing?(method, _include_all=false)
|
|
104
|
+
@properties.key?(method) || super
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def roles
|
|
108
|
+
@roles ||= Set.new
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def keys
|
|
112
|
+
@properties.keys
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def method_missing(key, value=nil)
|
|
116
|
+
if value
|
|
117
|
+
set(lvalue(key), value)
|
|
118
|
+
else
|
|
119
|
+
fetch(key)
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def to_h
|
|
124
|
+
@properties
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
private
|
|
128
|
+
|
|
129
|
+
def lvalue(key)
|
|
130
|
+
key.to_s.chomp("=").to_sym
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
end
|