capistrano 2.15.11 → 3.0.0.pre
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/.gitignore +17 -8
- data/Gemfile +1 -12
- data/LICENSE.txt +18 -0
- data/README.md +65 -68
- data/Rakefile +4 -10
- data/bin/cap +2 -3
- data/bin/capify +7 -91
- data/capistrano.gemspec +20 -34
- data/lib/Capfile +2 -0
- data/lib/capistrano/application.rb +28 -0
- data/lib/capistrano/bundler.rb +1 -0
- data/lib/capistrano/configuration/question.rb +42 -0
- data/lib/capistrano/configuration/server.rb +24 -0
- data/lib/capistrano/configuration/servers.rb +43 -95
- data/lib/capistrano/configuration.rb +81 -44
- data/lib/capistrano/console.rb +1 -0
- data/lib/capistrano/defaults.rb +11 -0
- data/lib/capistrano/deploy.rb +3 -0
- data/lib/capistrano/dotfile.rb +3 -0
- data/lib/capistrano/dsl/env.rb +57 -0
- data/lib/capistrano/dsl/paths.rb +74 -0
- data/lib/capistrano/dsl/stages.rb +15 -0
- data/lib/capistrano/dsl/task_enhancements.rb +15 -0
- data/lib/capistrano/dsl.rb +38 -0
- data/lib/capistrano/git.rb +1 -0
- data/lib/capistrano/i18n.rb +33 -0
- data/lib/capistrano/install.rb +1 -0
- data/lib/capistrano/setup.rb +17 -0
- data/lib/capistrano/tasks/bundler.rake +13 -0
- data/lib/capistrano/tasks/console.rake +21 -0
- data/lib/capistrano/tasks/deploy.rake +153 -0
- data/lib/capistrano/tasks/framework.rake +45 -0
- data/lib/capistrano/tasks/git.rake +65 -0
- data/lib/capistrano/tasks/install.rake +39 -0
- data/lib/capistrano/templates/Capfile +43 -0
- data/lib/capistrano/templates/deploy.rb.erb +17 -0
- data/lib/capistrano/templates/stage.rb.erb +20 -0
- data/lib/capistrano/version.rb +1 -11
- data/lib/capistrano.rb +9 -3
- data/spec/lib/capistrano/configuration/question_spec.rb +54 -0
- data/spec/lib/capistrano/configuration/server_spec.rb +48 -0
- data/spec/lib/capistrano/configuration/servers_spec.rb +79 -0
- data/spec/lib/capistrano/configuration_spec.rb +80 -0
- data/spec/lib/capistrano/dsl/env_spec.rb +83 -0
- data/spec/lib/capistrano/dsl/paths_spec.rb +69 -0
- data/spec/lib/capistrano/dsl_spec.rb +51 -0
- data/spec/lib/capistrano_spec.rb +8 -0
- data/spec/spec_helper.rb +14 -0
- metadata +89 -215
- data/.travis.yml +0 -9
- data/CHANGELOG +0 -1203
- data/lib/capistrano/callback.rb +0 -45
- data/lib/capistrano/cli/execute.rb +0 -85
- data/lib/capistrano/cli/help.rb +0 -125
- data/lib/capistrano/cli/help.txt +0 -81
- data/lib/capistrano/cli/options.rb +0 -243
- data/lib/capistrano/cli/ui.rb +0 -40
- data/lib/capistrano/cli.rb +0 -47
- data/lib/capistrano/command.rb +0 -303
- data/lib/capistrano/configuration/actions/file_transfer.rb +0 -50
- data/lib/capistrano/configuration/actions/inspect.rb +0 -46
- data/lib/capistrano/configuration/actions/invocation.rb +0 -329
- data/lib/capistrano/configuration/alias_task.rb +0 -26
- data/lib/capistrano/configuration/callbacks.rb +0 -147
- data/lib/capistrano/configuration/connections.rb +0 -237
- data/lib/capistrano/configuration/execution.rb +0 -142
- data/lib/capistrano/configuration/loading.rb +0 -205
- data/lib/capistrano/configuration/log_formatters.rb +0 -75
- data/lib/capistrano/configuration/namespaces.rb +0 -223
- data/lib/capistrano/configuration/roles.rb +0 -83
- data/lib/capistrano/configuration/variables.rb +0 -127
- data/lib/capistrano/errors.rb +0 -19
- data/lib/capistrano/ext/multistage.rb +0 -67
- data/lib/capistrano/ext/string.rb +0 -5
- data/lib/capistrano/extensions.rb +0 -57
- data/lib/capistrano/fix_rake_deprecated_dsl.rb +0 -8
- data/lib/capistrano/logger.rb +0 -166
- data/lib/capistrano/processable.rb +0 -55
- data/lib/capistrano/recipes/compat.rb +0 -32
- data/lib/capistrano/recipes/deploy/assets.rb +0 -202
- data/lib/capistrano/recipes/deploy/dependencies.rb +0 -44
- data/lib/capistrano/recipes/deploy/local_dependency.rb +0 -54
- data/lib/capistrano/recipes/deploy/remote_dependency.rb +0 -117
- data/lib/capistrano/recipes/deploy/scm/accurev.rb +0 -169
- data/lib/capistrano/recipes/deploy/scm/base.rb +0 -200
- data/lib/capistrano/recipes/deploy/scm/bzr.rb +0 -86
- data/lib/capistrano/recipes/deploy/scm/cvs.rb +0 -153
- data/lib/capistrano/recipes/deploy/scm/darcs.rb +0 -96
- data/lib/capistrano/recipes/deploy/scm/git.rb +0 -299
- data/lib/capistrano/recipes/deploy/scm/mercurial.rb +0 -137
- data/lib/capistrano/recipes/deploy/scm/none.rb +0 -55
- data/lib/capistrano/recipes/deploy/scm/perforce.rb +0 -152
- data/lib/capistrano/recipes/deploy/scm/subversion.rb +0 -121
- data/lib/capistrano/recipes/deploy/scm.rb +0 -19
- data/lib/capistrano/recipes/deploy/strategy/base.rb +0 -92
- data/lib/capistrano/recipes/deploy/strategy/checkout.rb +0 -20
- data/lib/capistrano/recipes/deploy/strategy/copy.rb +0 -338
- data/lib/capistrano/recipes/deploy/strategy/export.rb +0 -20
- data/lib/capistrano/recipes/deploy/strategy/remote.rb +0 -52
- data/lib/capistrano/recipes/deploy/strategy/remote_cache.rb +0 -57
- data/lib/capistrano/recipes/deploy/strategy/unshared_remote_cache.rb +0 -21
- data/lib/capistrano/recipes/deploy/strategy.rb +0 -20
- data/lib/capistrano/recipes/deploy.rb +0 -625
- data/lib/capistrano/recipes/standard.rb +0 -37
- data/lib/capistrano/recipes/templates/maintenance.rhtml +0 -53
- data/lib/capistrano/role.rb +0 -102
- data/lib/capistrano/server_definition.rb +0 -56
- data/lib/capistrano/shell.rb +0 -265
- data/lib/capistrano/ssh.rb +0 -95
- data/lib/capistrano/task_definition.rb +0 -77
- data/lib/capistrano/transfer.rb +0 -218
- data/test/cli/execute_test.rb +0 -132
- data/test/cli/help_test.rb +0 -165
- data/test/cli/options_test.rb +0 -329
- data/test/cli/ui_test.rb +0 -28
- data/test/cli_test.rb +0 -17
- data/test/command_test.rb +0 -322
- data/test/configuration/actions/file_transfer_test.rb +0 -61
- data/test/configuration/actions/inspect_test.rb +0 -76
- data/test/configuration/actions/invocation_test.rb +0 -306
- data/test/configuration/alias_task_test.rb +0 -118
- data/test/configuration/callbacks_test.rb +0 -201
- data/test/configuration/connections_test.rb +0 -439
- data/test/configuration/execution_test.rb +0 -175
- data/test/configuration/loading_test.rb +0 -148
- data/test/configuration/namespace_dsl_test.rb +0 -332
- data/test/configuration/roles_test.rb +0 -157
- data/test/configuration/servers_test.rb +0 -183
- data/test/configuration/variables_test.rb +0 -190
- data/test/configuration_test.rb +0 -77
- data/test/deploy/local_dependency_test.rb +0 -76
- data/test/deploy/remote_dependency_test.rb +0 -146
- data/test/deploy/scm/accurev_test.rb +0 -23
- data/test/deploy/scm/base_test.rb +0 -55
- data/test/deploy/scm/bzr_test.rb +0 -51
- data/test/deploy/scm/darcs_test.rb +0 -37
- data/test/deploy/scm/git_test.rb +0 -274
- data/test/deploy/scm/mercurial_test.rb +0 -134
- data/test/deploy/scm/none_test.rb +0 -35
- data/test/deploy/scm/perforce_test.rb +0 -23
- data/test/deploy/scm/subversion_test.rb +0 -68
- data/test/deploy/strategy/copy_test.rb +0 -360
- data/test/extensions_test.rb +0 -69
- data/test/fixtures/cli_integration.rb +0 -5
- data/test/fixtures/config.rb +0 -5
- data/test/fixtures/custom.rb +0 -3
- data/test/logger_formatting_test.rb +0 -149
- data/test/logger_test.rb +0 -134
- data/test/recipes_test.rb +0 -25
- data/test/role_test.rb +0 -11
- data/test/server_definition_test.rb +0 -121
- data/test/shell_test.rb +0 -96
- data/test/ssh_test.rb +0 -113
- data/test/task_definition_test.rb +0 -117
- data/test/transfer_test.rb +0 -168
- data/test/utils.rb +0 -37
- data/test/version_test.rb +0 -11
|
@@ -1,115 +1,63 @@
|
|
|
1
|
+
require 'set'
|
|
1
2
|
module Capistrano
|
|
2
3
|
class Configuration
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
# The options hash accepts the same arguments as #find_servers, and any
|
|
6
|
-
# preexisting options there will take precedence over the options in
|
|
7
|
-
# the task.
|
|
8
|
-
def find_servers_for_task(task, options={})
|
|
9
|
-
find_servers(task.options.merge(options))
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
# Attempts to find all defined servers that match the given criteria.
|
|
13
|
-
# The options hash may include a :hosts option (which should specify
|
|
14
|
-
# an array of host names or ServerDefinition instances), a :roles
|
|
15
|
-
# option (specifying an array of roles), an :only option (specifying
|
|
16
|
-
# a hash of key/value pairs that any matching server must match),
|
|
17
|
-
# an :except option (like :only, but the inverse), and a
|
|
18
|
-
# :skip_hostfilter option to ignore the HOSTFILTER environment variable
|
|
19
|
-
# described below.
|
|
20
|
-
#
|
|
21
|
-
# Additionally, if the HOSTS environment variable is set, it will take
|
|
22
|
-
# precedence over any other options. Similarly, the ROLES environment
|
|
23
|
-
# variable will take precedence over other options. If both HOSTS and
|
|
24
|
-
# ROLES are given, HOSTS wins.
|
|
25
|
-
#
|
|
26
|
-
# Yet additionally, if the HOSTFILTER environment variable is set, it
|
|
27
|
-
# will limit the result to hosts found in that (comma-separated) list.
|
|
28
|
-
#
|
|
29
|
-
# If the HOSTROLEFILTER environment variable is set, it will limit the
|
|
30
|
-
# result to hosts found in that (comma-separated) list of roles
|
|
31
|
-
#
|
|
32
|
-
# Usage:
|
|
33
|
-
#
|
|
34
|
-
# # return all known servers
|
|
35
|
-
# servers = find_servers
|
|
36
|
-
#
|
|
37
|
-
# # find all servers in the app role that are not exempted from
|
|
38
|
-
# # deployment
|
|
39
|
-
# servers = find_servers :roles => :app,
|
|
40
|
-
# :except => { :no_release => true }
|
|
41
|
-
#
|
|
42
|
-
# # returns the given hosts, translated to ServerDefinition objects
|
|
43
|
-
# servers = find_servers :hosts => "jamis@example.host.com"
|
|
44
|
-
def find_servers(options={})
|
|
45
|
-
return [] if options.key?(:hosts) && (options[:hosts].nil? || [] == options[:hosts])
|
|
46
|
-
return [] if options.key?(:roles) && (options[:roles].nil? || [] == options[:roles])
|
|
47
|
-
|
|
48
|
-
hosts = server_list_from(ENV['HOSTS'] || options[:hosts])
|
|
4
|
+
class Servers
|
|
5
|
+
include Enumerable
|
|
49
6
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
filter_server_list(hosts.uniq)
|
|
7
|
+
def add_host(host, properties = {})
|
|
8
|
+
find_or_create_server(host).tap do |host|
|
|
9
|
+
Array(properties.delete(:roles) || properties.delete("roles")).each do |role|
|
|
10
|
+
host.add_role(role)
|
|
55
11
|
end
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
12
|
+
properties.each do |key, value|
|
|
13
|
+
unless host.properties.respond_to?(key)
|
|
14
|
+
host.properties.send(:"#{key}=", value)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
servers.add host
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def add_role(role, hosts)
|
|
22
|
+
Array(hosts).each do |host|
|
|
23
|
+
server = find_or_create_server(host)
|
|
24
|
+
server.add_role(role)
|
|
25
|
+
servers.add server
|
|
26
|
+
end
|
|
27
|
+
end
|
|
59
28
|
|
|
60
|
-
|
|
61
|
-
|
|
29
|
+
def fetch_roles(names)
|
|
30
|
+
roles_for(names)
|
|
31
|
+
end
|
|
62
32
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
servers = servers.reject { |server| except.any? { |key,value| server.options[key] == value } }
|
|
33
|
+
def fetch_primary(role)
|
|
34
|
+
fetch(role).select { |h| h.properties.primary }.first || fetch(role).first
|
|
35
|
+
end
|
|
67
36
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
else
|
|
71
|
-
filter_server_list(servers.uniq)
|
|
72
|
-
end
|
|
73
|
-
end
|
|
37
|
+
def each
|
|
38
|
+
servers.each { |server| yield server }
|
|
74
39
|
end
|
|
75
40
|
|
|
76
|
-
|
|
41
|
+
private
|
|
77
42
|
|
|
78
|
-
def
|
|
79
|
-
|
|
80
|
-
if ENV['HOSTFILTER']
|
|
81
|
-
filters = ENV['HOSTFILTER'].split(/,/)
|
|
82
|
-
servers.select { |server| filters.include?(server.host) }
|
|
83
|
-
elsif ENV['HOSTROLEFILTER']
|
|
84
|
-
filters = ENV['HOSTROLEFILTER'].split(/,/).map do |role|
|
|
85
|
-
local_roles = roles[role.to_sym]
|
|
86
|
-
if local_roles.is_a? Array
|
|
87
|
-
roles[role.to_sym]
|
|
88
|
-
else
|
|
89
|
-
roles[role.to_sym].servers
|
|
90
|
-
end
|
|
91
|
-
end.flatten
|
|
92
|
-
servers.select { |server| filters.include?(server) }
|
|
93
|
-
end
|
|
43
|
+
def find_or_create_server(host)
|
|
44
|
+
servers.find { |server| server.matches?(host) } || Server.new(host)
|
|
94
45
|
end
|
|
95
46
|
|
|
96
|
-
def
|
|
97
|
-
|
|
98
|
-
hosts = build_list(hosts)
|
|
99
|
-
hosts.map { |s| String === s ? ServerDefinition.new(s.strip) : s }
|
|
47
|
+
def fetch(name)
|
|
48
|
+
servers.find_all { |server| server.has_role? name }
|
|
100
49
|
end
|
|
101
50
|
|
|
102
|
-
def
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
role
|
|
51
|
+
def roles_for(names)
|
|
52
|
+
if Array(names).map(&:to_sym).include?(:all)
|
|
53
|
+
servers
|
|
54
|
+
else
|
|
55
|
+
Array(names).flat_map { |name| fetch name }.uniq
|
|
108
56
|
end
|
|
109
57
|
end
|
|
110
58
|
|
|
111
|
-
def
|
|
112
|
-
|
|
59
|
+
def servers
|
|
60
|
+
@servers ||= Set.new
|
|
113
61
|
end
|
|
114
62
|
end
|
|
115
63
|
end
|
|
@@ -1,57 +1,94 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
require 'capistrano/configuration/callbacks'
|
|
5
|
-
require 'capistrano/configuration/connections'
|
|
6
|
-
require 'capistrano/configuration/execution'
|
|
7
|
-
require 'capistrano/configuration/loading'
|
|
8
|
-
require 'capistrano/configuration/log_formatters'
|
|
9
|
-
require 'capistrano/configuration/namespaces'
|
|
10
|
-
require 'capistrano/configuration/roles'
|
|
11
|
-
require 'capistrano/configuration/servers'
|
|
12
|
-
require 'capistrano/configuration/variables'
|
|
13
|
-
|
|
14
|
-
require 'capistrano/configuration/actions/file_transfer'
|
|
15
|
-
require 'capistrano/configuration/actions/inspect'
|
|
16
|
-
require 'capistrano/configuration/actions/invocation'
|
|
1
|
+
require_relative 'configuration/question'
|
|
2
|
+
require_relative 'configuration/servers'
|
|
3
|
+
require_relative 'configuration/server'
|
|
17
4
|
|
|
18
5
|
module Capistrano
|
|
19
|
-
# Represents a specific Capistrano configuration. A Configuration instance
|
|
20
|
-
# may be used to load multiple recipe files, define and describe tasks,
|
|
21
|
-
# define roles, and set configuration variables.
|
|
22
6
|
class Configuration
|
|
23
|
-
# The logger instance defined for this configuration.
|
|
24
|
-
attr_accessor :debug, :logger, :dry_run, :preserve_roles
|
|
25
7
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
@logger = Logger.new(options)
|
|
8
|
+
class << self
|
|
9
|
+
def env
|
|
10
|
+
@env ||= new
|
|
11
|
+
end
|
|
31
12
|
end
|
|
32
13
|
|
|
33
|
-
|
|
34
|
-
|
|
14
|
+
def ask(key, default=nil)
|
|
15
|
+
question = Question.new(self, key, default)
|
|
16
|
+
set(key, question)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def set(key, value)
|
|
20
|
+
config[key] = value
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def fetch(key, default=nil, &block)
|
|
24
|
+
value = fetch_for(key, default, &block)
|
|
25
|
+
if value.respond_to?(:call)
|
|
26
|
+
set(key, value.call)
|
|
27
|
+
else
|
|
28
|
+
value
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def role(name, hosts)
|
|
33
|
+
servers.add_role(name, hosts)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def server(name, properties = {})
|
|
37
|
+
servers.add_host(name, properties)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def roles_for(names, options = {})
|
|
41
|
+
servers.fetch_roles(names).tap do |list|
|
|
42
|
+
if filter = options.delete(:filter) || options.delete(:select)
|
|
43
|
+
if filter.respond_to?(:call)
|
|
44
|
+
list.select!(&filter)
|
|
45
|
+
else
|
|
46
|
+
list.select! { |s| s.properties.send(filter) }
|
|
47
|
+
end
|
|
48
|
+
if list.empty?
|
|
49
|
+
raise "Your filter #{filter} would remove all matching servers!"
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def primary(role)
|
|
56
|
+
servers.fetch_primary(role)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def configure_backend
|
|
60
|
+
SSHKit.configure do |sshkit|
|
|
61
|
+
sshkit.format = fetch(:format)
|
|
62
|
+
sshkit.output_verbosity = fetch(:log_level)
|
|
63
|
+
sshkit.default_env = fetch(:default_env)
|
|
64
|
+
sshkit.backend.configure do |backend|
|
|
65
|
+
backend.pty = fetch(:pty)
|
|
66
|
+
backend.connection_timeout = fetch(:connection_timeout)
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
35
70
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
71
|
+
def timestamp
|
|
72
|
+
@timestamp ||= Time.now.utc
|
|
73
|
+
end
|
|
39
74
|
|
|
40
|
-
|
|
41
|
-
include Actions::FileTransfer, Actions::Inspect, Actions::Invocation
|
|
75
|
+
private
|
|
42
76
|
|
|
43
|
-
|
|
44
|
-
|
|
77
|
+
def servers
|
|
78
|
+
@servers ||= Servers.new
|
|
79
|
+
end
|
|
45
80
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
self.instance_method(name).owner.to_s.start_with?("Capistrano::Configuration")
|
|
49
|
-
end.select do |name|
|
|
50
|
-
# Of those, select methods that are being shadowed by the Kernel module in the Namespace class.
|
|
51
|
-
Namespaces::Namespace.method_defined?(name) && Namespaces::Namespace.instance_method(name).owner == Kernel
|
|
52
|
-
end.each do |name|
|
|
53
|
-
# Undefine the shadowed methods, since we want Namespace objects to defer handling to the Configuration object.
|
|
54
|
-
Namespaces::Namespace.send(:undef_method, name)
|
|
81
|
+
def config
|
|
82
|
+
@config ||= Hash.new
|
|
55
83
|
end
|
|
84
|
+
|
|
85
|
+
def fetch_for(key, default, &block)
|
|
86
|
+
if block_given?
|
|
87
|
+
config.fetch(key, &block)
|
|
88
|
+
else
|
|
89
|
+
config.fetch(key, default)
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
56
93
|
end
|
|
57
94
|
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
load File.expand_path("../tasks/console.rake", __FILE__)
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
module Capistrano
|
|
2
|
+
module DSL
|
|
3
|
+
module Env
|
|
4
|
+
|
|
5
|
+
def configure_backend
|
|
6
|
+
env.configure_backend
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def fetch(key, default=nil)
|
|
10
|
+
env.fetch(key, default)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def any?(key)
|
|
14
|
+
value = fetch(key)
|
|
15
|
+
if value.respond_to?(:any)
|
|
16
|
+
value.any?
|
|
17
|
+
else
|
|
18
|
+
!fetch(key).nil?
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def set(key, value)
|
|
23
|
+
env.set(key, value)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def ask(key, value)
|
|
27
|
+
env.ask(key, value)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def role(name, servers)
|
|
31
|
+
env.role(name, servers)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def roles(*names)
|
|
35
|
+
env.roles_for(names)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def primary(role)
|
|
39
|
+
env.primary(role)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def env
|
|
43
|
+
Configuration.env
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def release_timestamp
|
|
47
|
+
env.timestamp.strftime("%Y%m%d%H%M%S")
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def asset_timestamp
|
|
51
|
+
env.timestamp.strftime("%Y%m%d%H%M.%S")
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
require 'pathname'
|
|
2
|
+
module Capistrano
|
|
3
|
+
module DSL
|
|
4
|
+
module Paths
|
|
5
|
+
|
|
6
|
+
def deploy_to
|
|
7
|
+
fetch(:deploy_to)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def deploy_path
|
|
11
|
+
Pathname.new(deploy_to)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def current_path
|
|
15
|
+
deploy_path.join('current')
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def releases_path
|
|
19
|
+
deploy_path.join('releases')
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def release_path
|
|
23
|
+
releases_path.join(release_timestamp)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def repo_path
|
|
27
|
+
deploy_path.join('repo')
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def shared_path
|
|
31
|
+
deploy_path.join('shared')
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def revision_log
|
|
35
|
+
deploy_path.join('revisions.log')
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def release_timestamp
|
|
39
|
+
fetch(:rollback_release_timestamp,
|
|
40
|
+
env.timestamp.strftime("%Y%m%d%H%M%S"))
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def asset_timestamp
|
|
44
|
+
env.timestamp.strftime("%Y%m%d%H%M.%S")
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def linked_dirs(parent)
|
|
48
|
+
paths = fetch(:linked_dirs)
|
|
49
|
+
join_paths(parent, paths)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def linked_files(parent)
|
|
53
|
+
paths = fetch(:linked_files)
|
|
54
|
+
join_paths(parent, paths)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def linked_file_dirs(parent)
|
|
58
|
+
map_dirnames(linked_files(parent))
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def linked_dir_parents(parent)
|
|
62
|
+
map_dirnames(linked_dirs(parent))
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def join_paths(parent, paths)
|
|
66
|
+
paths.map { |path| parent.join(path) }
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def map_dirnames(paths)
|
|
70
|
+
paths.map { |path| path.dirname }
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module Capistrano
|
|
2
|
+
module TaskEnhancements
|
|
3
|
+
def before(task, prerequisite, *args, &block)
|
|
4
|
+
prerequisite = Rake::Task.define_task(prerequisite, *args, &block) if block_given?
|
|
5
|
+
Rake::Task[task].enhance [prerequisite]
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def after(task, post_task, *args, &block)
|
|
9
|
+
post_task = Rake::Task.define_task(post_task, *args, &block) if block_given?
|
|
10
|
+
Rake::Task[task].enhance do
|
|
11
|
+
invoke(post_task)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
require 'capistrano/dsl/task_enhancements'
|
|
2
|
+
require 'capistrano/dsl/paths'
|
|
3
|
+
require 'capistrano/dsl/stages'
|
|
4
|
+
require 'capistrano/dsl/env'
|
|
5
|
+
|
|
6
|
+
module Capistrano
|
|
7
|
+
module DSL
|
|
8
|
+
include TaskEnhancements
|
|
9
|
+
include Env
|
|
10
|
+
include Paths
|
|
11
|
+
include Stages
|
|
12
|
+
|
|
13
|
+
def invoke(task, *args)
|
|
14
|
+
Rake::Task[task].invoke(*args)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def t(key, options={})
|
|
18
|
+
I18n.t(key, options.merge(scope: :capistrano))
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def scm
|
|
22
|
+
fetch(:scm)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def revision_log_message
|
|
26
|
+
fetch(:revision_log_message,
|
|
27
|
+
t(:revision_log_message, branch: fetch(:branch), user: local_user, release: release_timestamp))
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def rollback_log_message
|
|
31
|
+
t(:rollback_log_message, user: local_user, release: release_timestamp)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def local_user
|
|
35
|
+
`whoami`
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
load File.expand_path("../tasks/git.rake", __FILE__)
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require 'i18n'
|
|
2
|
+
|
|
3
|
+
en = {
|
|
4
|
+
starting: 'Starting',
|
|
5
|
+
capified: 'Capified',
|
|
6
|
+
starting: 'Starting',
|
|
7
|
+
start: 'Start',
|
|
8
|
+
update: 'Update',
|
|
9
|
+
finalize: 'Finalise',
|
|
10
|
+
restart: 'Restart',
|
|
11
|
+
finishing: 'Finishing',
|
|
12
|
+
finished: 'Finished',
|
|
13
|
+
stage_not_set: 'Stage not set, please call something such as `cap production deploy`, where production is a stage you have defined.',
|
|
14
|
+
written_file: 'create %{file}',
|
|
15
|
+
question: 'Please enter %{key}: |%{default_value}|',
|
|
16
|
+
keeping_releases: 'Keeping %{keep_releases} of %{releases} deployed releases',
|
|
17
|
+
linked_file_does_not_exist: 'linked file %{file} does not exist on %{host}',
|
|
18
|
+
mirror_exists: "The repository mirror is at %{at}",
|
|
19
|
+
revision_log_message: 'Branch %{branch} deployed as release %{release} by %{user}',
|
|
20
|
+
rollback_log_message: '%{user} rolled back to release %{release}',
|
|
21
|
+
console: {
|
|
22
|
+
welcome: 'capistrano console - enter command to execute on %{stage}',
|
|
23
|
+
bye: 'bye'
|
|
24
|
+
},
|
|
25
|
+
error: {
|
|
26
|
+
user: {
|
|
27
|
+
does_not_exist: 'User %{user} does not exists',
|
|
28
|
+
cannot_switch: 'Cannot switch to user %{user}'
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
I18n.backend.store_translations(:en, { capistrano: en })
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
load File.expand_path(File.join(File.dirname(__FILE__),'tasks/install.rake'))
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
include Capistrano::DSL
|
|
2
|
+
|
|
3
|
+
load 'capistrano/defaults.rb'
|
|
4
|
+
|
|
5
|
+
stages.each do |stage|
|
|
6
|
+
Rake::Task.define_task(stage) do
|
|
7
|
+
load "config/deploy.rb"
|
|
8
|
+
load "config/deploy/#{stage}.rb"
|
|
9
|
+
load "capistrano/#{fetch(:scm)}.rb"
|
|
10
|
+
set(:stage, stage.to_sym)
|
|
11
|
+
I18n.locale = fetch(:locale, :en)
|
|
12
|
+
configure_backend
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
require 'capistrano/dotfile'
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
namespace :deploy do
|
|
2
|
+
|
|
3
|
+
desc 'Bundle'
|
|
4
|
+
task :bundle do
|
|
5
|
+
on roles :web do
|
|
6
|
+
within release_path do
|
|
7
|
+
execute :bundle, "--gemfile #{release_path}/Gemfile --deployment --binstubs #{shared_path}/bin --path #{shared_path}/bundle --without development test cucumber"
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
before :finalize, :bundle
|
|
13
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
desc 'Execute remote commands'
|
|
2
|
+
task :console do
|
|
3
|
+
stage = fetch(:stage)
|
|
4
|
+
puts I18n.t('console.welcome', scope: :capistrano, stage: stage)
|
|
5
|
+
loop do
|
|
6
|
+
print "#{stage}> "
|
|
7
|
+
command = $stdin.gets.chomp
|
|
8
|
+
if %w{quit exit q}.include? command
|
|
9
|
+
puts t('console.bye')
|
|
10
|
+
break
|
|
11
|
+
else
|
|
12
|
+
begin
|
|
13
|
+
on roles :all do
|
|
14
|
+
execute command
|
|
15
|
+
end
|
|
16
|
+
rescue => e
|
|
17
|
+
puts e
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|