capistrano 2.15.11 → 3.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (158) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +17 -8
  3. data/Gemfile +1 -12
  4. data/LICENSE.txt +18 -0
  5. data/README.md +65 -68
  6. data/Rakefile +4 -10
  7. data/bin/cap +2 -3
  8. data/bin/capify +7 -91
  9. data/capistrano.gemspec +20 -34
  10. data/lib/Capfile +2 -0
  11. data/lib/capistrano/application.rb +28 -0
  12. data/lib/capistrano/bundler.rb +1 -0
  13. data/lib/capistrano/configuration/question.rb +42 -0
  14. data/lib/capistrano/configuration/server.rb +24 -0
  15. data/lib/capistrano/configuration/servers.rb +43 -95
  16. data/lib/capistrano/configuration.rb +81 -44
  17. data/lib/capistrano/console.rb +1 -0
  18. data/lib/capistrano/defaults.rb +11 -0
  19. data/lib/capistrano/deploy.rb +3 -0
  20. data/lib/capistrano/dotfile.rb +3 -0
  21. data/lib/capistrano/dsl/env.rb +57 -0
  22. data/lib/capistrano/dsl/paths.rb +74 -0
  23. data/lib/capistrano/dsl/stages.rb +15 -0
  24. data/lib/capistrano/dsl/task_enhancements.rb +15 -0
  25. data/lib/capistrano/dsl.rb +38 -0
  26. data/lib/capistrano/git.rb +1 -0
  27. data/lib/capistrano/i18n.rb +33 -0
  28. data/lib/capistrano/install.rb +1 -0
  29. data/lib/capistrano/setup.rb +17 -0
  30. data/lib/capistrano/tasks/bundler.rake +13 -0
  31. data/lib/capistrano/tasks/console.rake +21 -0
  32. data/lib/capistrano/tasks/deploy.rake +153 -0
  33. data/lib/capistrano/tasks/framework.rake +45 -0
  34. data/lib/capistrano/tasks/git.rake +65 -0
  35. data/lib/capistrano/tasks/install.rake +39 -0
  36. data/lib/capistrano/templates/Capfile +43 -0
  37. data/lib/capistrano/templates/deploy.rb.erb +17 -0
  38. data/lib/capistrano/templates/stage.rb.erb +20 -0
  39. data/lib/capistrano/version.rb +1 -11
  40. data/lib/capistrano.rb +9 -3
  41. data/spec/lib/capistrano/configuration/question_spec.rb +54 -0
  42. data/spec/lib/capistrano/configuration/server_spec.rb +48 -0
  43. data/spec/lib/capistrano/configuration/servers_spec.rb +79 -0
  44. data/spec/lib/capistrano/configuration_spec.rb +80 -0
  45. data/spec/lib/capistrano/dsl/env_spec.rb +83 -0
  46. data/spec/lib/capistrano/dsl/paths_spec.rb +69 -0
  47. data/spec/lib/capistrano/dsl_spec.rb +51 -0
  48. data/spec/lib/capistrano_spec.rb +8 -0
  49. data/spec/spec_helper.rb +14 -0
  50. metadata +89 -215
  51. data/.travis.yml +0 -9
  52. data/CHANGELOG +0 -1203
  53. data/lib/capistrano/callback.rb +0 -45
  54. data/lib/capistrano/cli/execute.rb +0 -85
  55. data/lib/capistrano/cli/help.rb +0 -125
  56. data/lib/capistrano/cli/help.txt +0 -81
  57. data/lib/capistrano/cli/options.rb +0 -243
  58. data/lib/capistrano/cli/ui.rb +0 -40
  59. data/lib/capistrano/cli.rb +0 -47
  60. data/lib/capistrano/command.rb +0 -303
  61. data/lib/capistrano/configuration/actions/file_transfer.rb +0 -50
  62. data/lib/capistrano/configuration/actions/inspect.rb +0 -46
  63. data/lib/capistrano/configuration/actions/invocation.rb +0 -329
  64. data/lib/capistrano/configuration/alias_task.rb +0 -26
  65. data/lib/capistrano/configuration/callbacks.rb +0 -147
  66. data/lib/capistrano/configuration/connections.rb +0 -237
  67. data/lib/capistrano/configuration/execution.rb +0 -142
  68. data/lib/capistrano/configuration/loading.rb +0 -205
  69. data/lib/capistrano/configuration/log_formatters.rb +0 -75
  70. data/lib/capistrano/configuration/namespaces.rb +0 -223
  71. data/lib/capistrano/configuration/roles.rb +0 -83
  72. data/lib/capistrano/configuration/variables.rb +0 -127
  73. data/lib/capistrano/errors.rb +0 -19
  74. data/lib/capistrano/ext/multistage.rb +0 -67
  75. data/lib/capistrano/ext/string.rb +0 -5
  76. data/lib/capistrano/extensions.rb +0 -57
  77. data/lib/capistrano/fix_rake_deprecated_dsl.rb +0 -8
  78. data/lib/capistrano/logger.rb +0 -166
  79. data/lib/capistrano/processable.rb +0 -55
  80. data/lib/capistrano/recipes/compat.rb +0 -32
  81. data/lib/capistrano/recipes/deploy/assets.rb +0 -202
  82. data/lib/capistrano/recipes/deploy/dependencies.rb +0 -44
  83. data/lib/capistrano/recipes/deploy/local_dependency.rb +0 -54
  84. data/lib/capistrano/recipes/deploy/remote_dependency.rb +0 -117
  85. data/lib/capistrano/recipes/deploy/scm/accurev.rb +0 -169
  86. data/lib/capistrano/recipes/deploy/scm/base.rb +0 -200
  87. data/lib/capistrano/recipes/deploy/scm/bzr.rb +0 -86
  88. data/lib/capistrano/recipes/deploy/scm/cvs.rb +0 -153
  89. data/lib/capistrano/recipes/deploy/scm/darcs.rb +0 -96
  90. data/lib/capistrano/recipes/deploy/scm/git.rb +0 -299
  91. data/lib/capistrano/recipes/deploy/scm/mercurial.rb +0 -137
  92. data/lib/capistrano/recipes/deploy/scm/none.rb +0 -55
  93. data/lib/capistrano/recipes/deploy/scm/perforce.rb +0 -152
  94. data/lib/capistrano/recipes/deploy/scm/subversion.rb +0 -121
  95. data/lib/capistrano/recipes/deploy/scm.rb +0 -19
  96. data/lib/capistrano/recipes/deploy/strategy/base.rb +0 -92
  97. data/lib/capistrano/recipes/deploy/strategy/checkout.rb +0 -20
  98. data/lib/capistrano/recipes/deploy/strategy/copy.rb +0 -338
  99. data/lib/capistrano/recipes/deploy/strategy/export.rb +0 -20
  100. data/lib/capistrano/recipes/deploy/strategy/remote.rb +0 -52
  101. data/lib/capistrano/recipes/deploy/strategy/remote_cache.rb +0 -57
  102. data/lib/capistrano/recipes/deploy/strategy/unshared_remote_cache.rb +0 -21
  103. data/lib/capistrano/recipes/deploy/strategy.rb +0 -20
  104. data/lib/capistrano/recipes/deploy.rb +0 -625
  105. data/lib/capistrano/recipes/standard.rb +0 -37
  106. data/lib/capistrano/recipes/templates/maintenance.rhtml +0 -53
  107. data/lib/capistrano/role.rb +0 -102
  108. data/lib/capistrano/server_definition.rb +0 -56
  109. data/lib/capistrano/shell.rb +0 -265
  110. data/lib/capistrano/ssh.rb +0 -95
  111. data/lib/capistrano/task_definition.rb +0 -77
  112. data/lib/capistrano/transfer.rb +0 -218
  113. data/test/cli/execute_test.rb +0 -132
  114. data/test/cli/help_test.rb +0 -165
  115. data/test/cli/options_test.rb +0 -329
  116. data/test/cli/ui_test.rb +0 -28
  117. data/test/cli_test.rb +0 -17
  118. data/test/command_test.rb +0 -322
  119. data/test/configuration/actions/file_transfer_test.rb +0 -61
  120. data/test/configuration/actions/inspect_test.rb +0 -76
  121. data/test/configuration/actions/invocation_test.rb +0 -306
  122. data/test/configuration/alias_task_test.rb +0 -118
  123. data/test/configuration/callbacks_test.rb +0 -201
  124. data/test/configuration/connections_test.rb +0 -439
  125. data/test/configuration/execution_test.rb +0 -175
  126. data/test/configuration/loading_test.rb +0 -148
  127. data/test/configuration/namespace_dsl_test.rb +0 -332
  128. data/test/configuration/roles_test.rb +0 -157
  129. data/test/configuration/servers_test.rb +0 -183
  130. data/test/configuration/variables_test.rb +0 -190
  131. data/test/configuration_test.rb +0 -77
  132. data/test/deploy/local_dependency_test.rb +0 -76
  133. data/test/deploy/remote_dependency_test.rb +0 -146
  134. data/test/deploy/scm/accurev_test.rb +0 -23
  135. data/test/deploy/scm/base_test.rb +0 -55
  136. data/test/deploy/scm/bzr_test.rb +0 -51
  137. data/test/deploy/scm/darcs_test.rb +0 -37
  138. data/test/deploy/scm/git_test.rb +0 -274
  139. data/test/deploy/scm/mercurial_test.rb +0 -134
  140. data/test/deploy/scm/none_test.rb +0 -35
  141. data/test/deploy/scm/perforce_test.rb +0 -23
  142. data/test/deploy/scm/subversion_test.rb +0 -68
  143. data/test/deploy/strategy/copy_test.rb +0 -360
  144. data/test/extensions_test.rb +0 -69
  145. data/test/fixtures/cli_integration.rb +0 -5
  146. data/test/fixtures/config.rb +0 -5
  147. data/test/fixtures/custom.rb +0 -3
  148. data/test/logger_formatting_test.rb +0 -149
  149. data/test/logger_test.rb +0 -134
  150. data/test/recipes_test.rb +0 -25
  151. data/test/role_test.rb +0 -11
  152. data/test/server_definition_test.rb +0 -121
  153. data/test/shell_test.rb +0 -96
  154. data/test/ssh_test.rb +0 -113
  155. data/test/task_definition_test.rb +0 -117
  156. data/test/transfer_test.rb +0 -168
  157. data/test/utils.rb +0 -37
  158. data/test/version_test.rb +0 -11
@@ -1,115 +1,63 @@
1
+ require 'set'
1
2
  module Capistrano
2
3
  class Configuration
3
- module Servers
4
- # Identifies all servers that the given task should be executed on.
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
- if hosts.any?
51
- if options[:skip_hostfilter]
52
- hosts.uniq
53
- else
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
- else
57
- roles = role_list_from(ENV['ROLES'] || options[:roles] || self.roles.keys)
58
- roles = roles & Array(options[:roles]) if preserve_roles && !options[:roles].nil?
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
- only = options[:only] || {}
61
- except = options[:except] || {}
29
+ def fetch_roles(names)
30
+ roles_for(names)
31
+ end
62
32
 
63
- # If we don't have a def for a role it means its bogus, skip it so higher level can handle
64
- servers = roles.inject([]) { |list, role| list.concat(self.roles[role] || []) }
65
- servers = servers.select { |server| only.all? { |key,value| server.options[key] == value } }
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
- if options[:skip_hostfilter]
69
- servers.uniq
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
- protected
41
+ private
77
42
 
78
- def filter_server_list(servers)
79
- return servers unless ENV['HOSTFILTER'] or ENV['HOSTROLEFILTER']
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 server_list_from(hosts)
97
- hosts = hosts.split(/,/) if String === hosts
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 role_list_from(roles)
103
- roles = roles.split(/,/) if String === roles
104
- roles = build_list(roles)
105
- roles.map do |role|
106
- role = String === role ? role.strip.to_sym : role
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 build_list(list)
112
- Array(list).map { |item| item.respond_to?(:call) ? item.call : item }.flatten
59
+ def servers
60
+ @servers ||= Set.new
113
61
  end
114
62
  end
115
63
  end
@@ -1,57 +1,94 @@
1
- require 'capistrano/logger'
2
-
3
- require 'capistrano/configuration/alias_task'
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
- def initialize(options={}) #:nodoc:
27
- @debug = false
28
- @dry_run = false
29
- @preserve_roles = false
30
- @logger = Logger.new(options)
8
+ class << self
9
+ def env
10
+ @env ||= new
11
+ end
31
12
  end
32
13
 
33
- # make the DSL easier to read when using lazy evaluation via lambdas
34
- alias defer lambda
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
- # The includes must come at the bottom, since they may redefine methods
37
- # defined in the base class.
38
- include AliasTask, Connections, Execution, Loading, LogFormatters, Namespaces, Roles, Servers, Variables
71
+ def timestamp
72
+ @timestamp ||= Time.now.utc
73
+ end
39
74
 
40
- # Mix in the actions
41
- include Actions::FileTransfer, Actions::Inspect, Actions::Invocation
75
+ private
42
76
 
43
- # Must mix last, because it hooks into previously defined methods
44
- include Callbacks
77
+ def servers
78
+ @servers ||= Servers.new
79
+ end
45
80
 
46
- (self.instance_methods & Kernel.methods).select do |name|
47
- # Select the instance methods owned by the Configuration class.
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,11 @@
1
+ set :scm, :git
2
+ set :branch, :master
3
+ set :deploy_to, "/var/www/#{fetch(:application)}"
4
+
5
+ set :default_environment, {}
6
+ set :keep_releases, 5
7
+
8
+ set :format, :pretty
9
+ set :log_level, :debug
10
+
11
+ set :pty, true
@@ -0,0 +1,3 @@
1
+ load File.expand_path("../tasks/framework.rake", __FILE__)
2
+ load File.expand_path("../tasks/deploy.rake", __FILE__)
3
+ require 'capistrano/install'
@@ -0,0 +1,3 @@
1
+ dotfile = Pathname.new(File.join(Dir.home, '.capfile'))
2
+ load dotfile if dotfile.file?
3
+
@@ -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 DSL
3
+ module Stages
4
+
5
+ def stages
6
+ Dir['config/deploy/*.rb'].map { |f| File.basename(f, '.rb') }
7
+ end
8
+
9
+ def stage_set?
10
+ !!fetch(:stage, false)
11
+ end
12
+
13
+ end
14
+ end
15
+ 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