capistrano 2.8.0 → 3.19.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (239) hide show
  1. checksums.yaml +7 -0
  2. data/.docker/Dockerfile +7 -0
  3. data/.docker/ssh_key_rsa +49 -0
  4. data/.docker/ssh_key_rsa.pub +1 -0
  5. data/.docker/ubuntu_setup.sh +23 -0
  6. data/.github/issue_template.md +19 -0
  7. data/.github/pull_request_template.md +22 -0
  8. data/.github/release-drafter.yml +25 -0
  9. data/.github/workflows/ci.yml +80 -0
  10. data/.github/workflows/release-drafter.yml +18 -0
  11. data/.gitignore +23 -8
  12. data/.rubocop.yml +62 -0
  13. data/CHANGELOG.md +1 -0
  14. data/CONTRIBUTING.md +63 -0
  15. data/DEVELOPMENT.md +112 -0
  16. data/Gemfile +42 -9
  17. data/LICENSE.txt +21 -0
  18. data/README.md +221 -0
  19. data/RELEASING.md +17 -0
  20. data/Rakefile +17 -8
  21. data/UPGRADING-3.7.md +86 -0
  22. data/bin/cap +2 -3
  23. data/bin/capify +7 -89
  24. data/capistrano.gemspec +29 -43
  25. data/docker-compose.yml +8 -0
  26. data/features/configuration.feature +28 -0
  27. data/features/deploy.feature +92 -0
  28. data/features/deploy_failure.feature +17 -0
  29. data/features/doctor.feature +11 -0
  30. data/features/installation.feature +21 -0
  31. data/features/sshconnect.feature +11 -0
  32. data/features/stage_failure.feature +9 -0
  33. data/features/step_definitions/assertions.rb +162 -0
  34. data/features/step_definitions/cap_commands.rb +21 -0
  35. data/features/step_definitions/setup.rb +91 -0
  36. data/features/subdirectory.feature +9 -0
  37. data/features/support/docker_gateway.rb +53 -0
  38. data/features/support/env.rb +1 -0
  39. data/features/support/remote_command_helpers.rb +29 -0
  40. data/features/support/remote_ssh_helpers.rb +33 -0
  41. data/lib/Capfile +3 -0
  42. data/lib/capistrano/all.rb +17 -0
  43. data/lib/capistrano/application.rb +153 -0
  44. data/lib/capistrano/configuration/empty_filter.rb +9 -0
  45. data/lib/capistrano/configuration/filter.rb +26 -0
  46. data/lib/capistrano/configuration/host_filter.rb +29 -0
  47. data/lib/capistrano/configuration/null_filter.rb +9 -0
  48. data/lib/capistrano/configuration/plugin_installer.rb +51 -0
  49. data/lib/capistrano/configuration/question.rb +76 -0
  50. data/lib/capistrano/configuration/role_filter.rb +29 -0
  51. data/lib/capistrano/configuration/scm_resolver.rb +149 -0
  52. data/lib/capistrano/configuration/server.rb +137 -0
  53. data/lib/capistrano/configuration/servers.rb +56 -96
  54. data/lib/capistrano/configuration/validated_variables.rb +110 -0
  55. data/lib/capistrano/configuration/variables.rb +79 -94
  56. data/lib/capistrano/configuration.rb +178 -33
  57. data/lib/capistrano/console.rb +1 -0
  58. data/lib/capistrano/defaults.rb +36 -0
  59. data/lib/capistrano/deploy.rb +3 -0
  60. data/lib/capistrano/doctor/environment_doctor.rb +19 -0
  61. data/lib/capistrano/doctor/gems_doctor.rb +45 -0
  62. data/lib/capistrano/doctor/output_helpers.rb +79 -0
  63. data/lib/capistrano/doctor/servers_doctor.rb +105 -0
  64. data/lib/capistrano/doctor/variables_doctor.rb +74 -0
  65. data/lib/capistrano/doctor.rb +6 -0
  66. data/lib/capistrano/dotfile.rb +2 -0
  67. data/lib/capistrano/dsl/env.rb +43 -0
  68. data/lib/capistrano/dsl/paths.rb +89 -0
  69. data/lib/capistrano/dsl/stages.rb +31 -0
  70. data/lib/capistrano/dsl/task_enhancements.rb +61 -0
  71. data/lib/capistrano/dsl.rb +95 -0
  72. data/lib/capistrano/framework.rb +2 -0
  73. data/lib/capistrano/i18n.rb +46 -0
  74. data/lib/capistrano/immutable_task.rb +30 -0
  75. data/lib/capistrano/install.rb +1 -0
  76. data/lib/capistrano/plugin.rb +95 -0
  77. data/lib/capistrano/proc_helpers.rb +13 -0
  78. data/lib/capistrano/scm/git.rb +105 -0
  79. data/lib/capistrano/scm/hg.rb +55 -0
  80. data/lib/capistrano/scm/plugin.rb +13 -0
  81. data/lib/capistrano/scm/svn.rb +56 -0
  82. data/lib/capistrano/scm/tasks/git.rake +84 -0
  83. data/lib/capistrano/scm/tasks/hg.rake +53 -0
  84. data/lib/capistrano/scm/tasks/svn.rake +53 -0
  85. data/lib/capistrano/scm.rb +115 -0
  86. data/lib/capistrano/setup.rb +36 -0
  87. data/lib/capistrano/tasks/console.rake +25 -0
  88. data/lib/capistrano/tasks/deploy.rake +280 -0
  89. data/lib/capistrano/tasks/doctor.rake +24 -0
  90. data/lib/capistrano/tasks/framework.rake +67 -0
  91. data/lib/capistrano/tasks/install.rake +41 -0
  92. data/lib/capistrano/templates/Capfile +38 -0
  93. data/lib/capistrano/templates/deploy.rb.erb +39 -0
  94. data/lib/capistrano/templates/stage.rb.erb +61 -0
  95. data/lib/capistrano/upload_task.rb +9 -0
  96. data/lib/capistrano/version.rb +1 -14
  97. data/lib/capistrano/version_validator.rb +32 -0
  98. data/lib/capistrano.rb +0 -3
  99. data/spec/integration/dsl_spec.rb +632 -0
  100. data/spec/integration_spec_helper.rb +5 -0
  101. data/spec/lib/capistrano/application_spec.rb +60 -0
  102. data/spec/lib/capistrano/configuration/empty_filter_spec.rb +17 -0
  103. data/spec/lib/capistrano/configuration/filter_spec.rb +109 -0
  104. data/spec/lib/capistrano/configuration/host_filter_spec.rb +71 -0
  105. data/spec/lib/capistrano/configuration/null_filter_spec.rb +17 -0
  106. data/spec/lib/capistrano/configuration/plugin_installer_spec.rb +98 -0
  107. data/spec/lib/capistrano/configuration/question_spec.rb +92 -0
  108. data/spec/lib/capistrano/configuration/role_filter_spec.rb +80 -0
  109. data/spec/lib/capistrano/configuration/scm_resolver_spec.rb +56 -0
  110. data/spec/lib/capistrano/configuration/server_spec.rb +309 -0
  111. data/spec/lib/capistrano/configuration/servers_spec.rb +331 -0
  112. data/spec/lib/capistrano/configuration_spec.rb +357 -0
  113. data/spec/lib/capistrano/doctor/environment_doctor_spec.rb +44 -0
  114. data/spec/lib/capistrano/doctor/gems_doctor_spec.rb +67 -0
  115. data/spec/lib/capistrano/doctor/output_helpers_spec.rb +47 -0
  116. data/spec/lib/capistrano/doctor/servers_doctor_spec.rb +86 -0
  117. data/spec/lib/capistrano/doctor/variables_doctor_spec.rb +89 -0
  118. data/spec/lib/capistrano/dsl/paths_spec.rb +228 -0
  119. data/spec/lib/capistrano/dsl/task_enhancements_spec.rb +108 -0
  120. data/spec/lib/capistrano/dsl_spec.rb +125 -0
  121. data/spec/lib/capistrano/immutable_task_spec.rb +31 -0
  122. data/spec/lib/capistrano/plugin_spec.rb +84 -0
  123. data/spec/lib/capistrano/scm/git_spec.rb +194 -0
  124. data/spec/lib/capistrano/scm/hg_spec.rb +109 -0
  125. data/spec/lib/capistrano/scm/svn_spec.rb +137 -0
  126. data/spec/lib/capistrano/scm_spec.rb +103 -0
  127. data/spec/lib/capistrano/upload_task_spec.rb +19 -0
  128. data/spec/lib/capistrano/version_validator_spec.rb +118 -0
  129. data/spec/lib/capistrano_spec.rb +7 -0
  130. data/spec/spec_helper.rb +29 -0
  131. data/spec/support/matchers.rb +5 -0
  132. data/spec/support/tasks/database.rake +11 -0
  133. data/spec/support/tasks/fail.rake +8 -0
  134. data/spec/support/tasks/failed.rake +5 -0
  135. data/spec/support/tasks/plugin.rake +6 -0
  136. data/spec/support/tasks/root.rake +11 -0
  137. data/spec/support/test_app.rb +205 -0
  138. metadata +234 -208
  139. data/.rvmrc +0 -1
  140. data/CHANGELOG +0 -954
  141. data/README.mdown +0 -76
  142. data/lib/capistrano/callback.rb +0 -45
  143. data/lib/capistrano/cli/execute.rb +0 -85
  144. data/lib/capistrano/cli/help.rb +0 -125
  145. data/lib/capistrano/cli/help.txt +0 -81
  146. data/lib/capistrano/cli/options.rb +0 -243
  147. data/lib/capistrano/cli/ui.rb +0 -40
  148. data/lib/capistrano/cli.rb +0 -47
  149. data/lib/capistrano/command.rb +0 -286
  150. data/lib/capistrano/configuration/actions/file_transfer.rb +0 -51
  151. data/lib/capistrano/configuration/actions/inspect.rb +0 -46
  152. data/lib/capistrano/configuration/actions/invocation.rb +0 -298
  153. data/lib/capistrano/configuration/callbacks.rb +0 -148
  154. data/lib/capistrano/configuration/connections.rb +0 -230
  155. data/lib/capistrano/configuration/execution.rb +0 -143
  156. data/lib/capistrano/configuration/loading.rb +0 -197
  157. data/lib/capistrano/configuration/namespaces.rb +0 -197
  158. data/lib/capistrano/configuration/roles.rb +0 -73
  159. data/lib/capistrano/errors.rb +0 -19
  160. data/lib/capistrano/ext/string.rb +0 -5
  161. data/lib/capistrano/extensions.rb +0 -57
  162. data/lib/capistrano/logger.rb +0 -59
  163. data/lib/capistrano/processable.rb +0 -53
  164. data/lib/capistrano/recipes/compat.rb +0 -32
  165. data/lib/capistrano/recipes/deploy/assets.rb +0 -57
  166. data/lib/capistrano/recipes/deploy/dependencies.rb +0 -44
  167. data/lib/capistrano/recipes/deploy/local_dependency.rb +0 -54
  168. data/lib/capistrano/recipes/deploy/remote_dependency.rb +0 -111
  169. data/lib/capistrano/recipes/deploy/scm/accurev.rb +0 -169
  170. data/lib/capistrano/recipes/deploy/scm/base.rb +0 -196
  171. data/lib/capistrano/recipes/deploy/scm/bzr.rb +0 -86
  172. data/lib/capistrano/recipes/deploy/scm/cvs.rb +0 -153
  173. data/lib/capistrano/recipes/deploy/scm/darcs.rb +0 -96
  174. data/lib/capistrano/recipes/deploy/scm/git.rb +0 -282
  175. data/lib/capistrano/recipes/deploy/scm/mercurial.rb +0 -137
  176. data/lib/capistrano/recipes/deploy/scm/none.rb +0 -44
  177. data/lib/capistrano/recipes/deploy/scm/perforce.rb +0 -138
  178. data/lib/capistrano/recipes/deploy/scm/subversion.rb +0 -121
  179. data/lib/capistrano/recipes/deploy/scm.rb +0 -19
  180. data/lib/capistrano/recipes/deploy/strategy/base.rb +0 -88
  181. data/lib/capistrano/recipes/deploy/strategy/checkout.rb +0 -20
  182. data/lib/capistrano/recipes/deploy/strategy/copy.rb +0 -224
  183. data/lib/capistrano/recipes/deploy/strategy/export.rb +0 -20
  184. data/lib/capistrano/recipes/deploy/strategy/remote.rb +0 -52
  185. data/lib/capistrano/recipes/deploy/strategy/remote_cache.rb +0 -57
  186. data/lib/capistrano/recipes/deploy/strategy.rb +0 -19
  187. data/lib/capistrano/recipes/deploy/templates/maintenance.rhtml +0 -53
  188. data/lib/capistrano/recipes/deploy.rb +0 -568
  189. data/lib/capistrano/recipes/standard.rb +0 -37
  190. data/lib/capistrano/recipes/templates/maintenance.rhtml +0 -53
  191. data/lib/capistrano/role.rb +0 -102
  192. data/lib/capistrano/server_definition.rb +0 -56
  193. data/lib/capistrano/shell.rb +0 -260
  194. data/lib/capistrano/ssh.rb +0 -101
  195. data/lib/capistrano/task_definition.rb +0 -75
  196. data/lib/capistrano/transfer.rb +0 -216
  197. data/rvmrc.sample +0 -1
  198. data/test/cli/execute_test.rb +0 -132
  199. data/test/cli/help_test.rb +0 -165
  200. data/test/cli/options_test.rb +0 -329
  201. data/test/cli/ui_test.rb +0 -28
  202. data/test/cli_test.rb +0 -17
  203. data/test/command_test.rb +0 -289
  204. data/test/configuration/actions/file_transfer_test.rb +0 -61
  205. data/test/configuration/actions/inspect_test.rb +0 -65
  206. data/test/configuration/actions/invocation_test.rb +0 -247
  207. data/test/configuration/callbacks_test.rb +0 -220
  208. data/test/configuration/connections_test.rb +0 -420
  209. data/test/configuration/execution_test.rb +0 -175
  210. data/test/configuration/loading_test.rb +0 -132
  211. data/test/configuration/namespace_dsl_test.rb +0 -311
  212. data/test/configuration/roles_test.rb +0 -144
  213. data/test/configuration/servers_test.rb +0 -183
  214. data/test/configuration/variables_test.rb +0 -190
  215. data/test/configuration_test.rb +0 -88
  216. data/test/deploy/local_dependency_test.rb +0 -76
  217. data/test/deploy/remote_dependency_test.rb +0 -135
  218. data/test/deploy/scm/accurev_test.rb +0 -23
  219. data/test/deploy/scm/base_test.rb +0 -55
  220. data/test/deploy/scm/bzr_test.rb +0 -51
  221. data/test/deploy/scm/darcs_test.rb +0 -37
  222. data/test/deploy/scm/git_test.rb +0 -184
  223. data/test/deploy/scm/mercurial_test.rb +0 -134
  224. data/test/deploy/scm/none_test.rb +0 -35
  225. data/test/deploy/scm/subversion_test.rb +0 -32
  226. data/test/deploy/strategy/copy_test.rb +0 -321
  227. data/test/extensions_test.rb +0 -69
  228. data/test/fixtures/cli_integration.rb +0 -5
  229. data/test/fixtures/config.rb +0 -5
  230. data/test/fixtures/custom.rb +0 -3
  231. data/test/logger_test.rb +0 -123
  232. data/test/recipes_test.rb +0 -25
  233. data/test/role_test.rb +0 -11
  234. data/test/server_definition_test.rb +0 -121
  235. data/test/shell_test.rb +0 -90
  236. data/test/ssh_test.rb +0 -113
  237. data/test/task_definition_test.rb +0 -116
  238. data/test/transfer_test.rb +0 -160
  239. data/test/utils.rb +0 -37
@@ -1,568 +0,0 @@
1
- require 'benchmark'
2
- require 'yaml'
3
- require 'capistrano/recipes/deploy/scm'
4
- require 'capistrano/recipes/deploy/strategy'
5
-
6
- def _cset(name, *args, &block)
7
- unless exists?(name)
8
- set(name, *args, &block)
9
- end
10
- end
11
-
12
- # =========================================================================
13
- # These variables MUST be set in the client capfiles. If they are not set,
14
- # the deploy will fail with an error.
15
- # =========================================================================
16
-
17
- _cset(:application) { abort "Please specify the name of your application, set :application, 'foo'" }
18
- _cset(:repository) { abort "Please specify the repository that houses your application's code, set :repository, 'foo'" }
19
-
20
- # =========================================================================
21
- # These variables may be set in the client capfile if their default values
22
- # are not sufficient.
23
- # =========================================================================
24
-
25
- _cset :scm, :subversion
26
- _cset :deploy_via, :checkout
27
-
28
- _cset(:deploy_to) { "/u/apps/#{application}" }
29
- _cset(:revision) { source.head }
30
-
31
- _cset :rails_env, "production"
32
- _cset :rake, "rake"
33
-
34
- _cset :maintenance_basename, "maintenance"
35
-
36
- # =========================================================================
37
- # These variables should NOT be changed unless you are very confident in
38
- # what you are doing. Make sure you understand all the implications of your
39
- # changes if you do decide to muck with these!
40
- # =========================================================================
41
-
42
- _cset(:source) { Capistrano::Deploy::SCM.new(scm, self) }
43
- _cset(:real_revision) { source.local.query_revision(revision) { |cmd| with_env("LC_ALL", "C") { run_locally(cmd) } } }
44
-
45
- _cset(:strategy) { Capistrano::Deploy::Strategy.new(deploy_via, self) }
46
-
47
- # If overriding release name, please also select an appropriate setting for :releases below.
48
- _cset(:release_name) { set :deploy_timestamped, true; Time.now.utc.strftime("%Y%m%d%H%M%S") }
49
-
50
- _cset :version_dir, "releases"
51
- _cset :shared_dir, "shared"
52
- _cset :shared_children, %w(system log pids)
53
- _cset :current_dir, "current"
54
-
55
- _cset(:releases_path) { File.join(deploy_to, version_dir) }
56
- _cset(:shared_path) { File.join(deploy_to, shared_dir) }
57
- _cset(:current_path) { File.join(deploy_to, current_dir) }
58
- _cset(:release_path) { File.join(releases_path, release_name) }
59
-
60
- _cset(:releases) { capture("ls -x #{releases_path}", :except => { :no_release => true }).split.sort }
61
- _cset(:current_release) { releases.length > 0 ? File.join(releases_path, releases.last) : nil }
62
- _cset(:previous_release) { releases.length > 1 ? File.join(releases_path, releases[-2]) : nil }
63
-
64
- _cset(:current_revision) { capture("cat #{current_path}/REVISION", :except => { :no_release => true }).chomp }
65
- _cset(:latest_revision) { capture("cat #{current_release}/REVISION", :except => { :no_release => true }).chomp }
66
- _cset(:previous_revision) { capture("cat #{previous_release}/REVISION", :except => { :no_release => true }).chomp if previous_release }
67
-
68
- _cset(:run_method) { fetch(:use_sudo, true) ? :sudo : :run }
69
-
70
- # some tasks, like symlink, need to always point at the latest release, but
71
- # they can also (occassionally) be called standalone. In the standalone case,
72
- # the timestamped release_path will be inaccurate, since the directory won't
73
- # actually exist. This variable lets tasks like symlink work either in the
74
- # standalone case, or during deployment.
75
- _cset(:latest_release) { exists?(:deploy_timestamped) ? release_path : current_release }
76
-
77
- # =========================================================================
78
- # These are helper methods that will be available to your recipes.
79
- # =========================================================================
80
-
81
- # Auxiliary helper method for the `deploy:check' task. Lets you set up your
82
- # own dependencies.
83
- def depend(location, type, *args)
84
- deps = fetch(:dependencies, {})
85
- deps[location] ||= {}
86
- deps[location][type] ||= []
87
- deps[location][type] << args
88
- set :dependencies, deps
89
- end
90
-
91
- # Temporarily sets an environment variable, yields to a block, and restores
92
- # the value when it is done.
93
- def with_env(name, value)
94
- saved, ENV[name] = ENV[name], value
95
- yield
96
- ensure
97
- ENV[name] = saved
98
- end
99
-
100
- # logs the command then executes it locally.
101
- # returns the command output as a string
102
- def run_locally(cmd)
103
- logger.trace "executing locally: #{cmd.inspect}" if logger
104
- output_on_stdout = nil
105
- elapsed = Benchmark.realtime do
106
- output_on_stdout = `#{cmd}`
107
- end
108
- if $?.to_i > 0 # $? is command exit code (posix style)
109
- raise Capistrano::LocalArgumentError, "Command #{cmd} returned status code #{$?}"
110
- end
111
- logger.trace "command finished in #{(elapsed * 1000).round}ms" if logger
112
- output_on_stdout
113
- end
114
-
115
-
116
- # If a command is given, this will try to execute the given command, as
117
- # described below. Otherwise, it will return a string for use in embedding in
118
- # another command, for executing that command as described below.
119
- #
120
- # If :run_method is :sudo (or :use_sudo is true), this executes the given command
121
- # via +sudo+. Otherwise is uses +run+. If :as is given as a key, it will be
122
- # passed as the user to sudo as, if using sudo. If the :as key is not given,
123
- # it will default to whatever the value of the :admin_runner variable is,
124
- # which (by default) is unset.
125
- #
126
- # THUS, if you want to try to run something via sudo, and what to use the
127
- # root user, you'd just to try_sudo('something'). If you wanted to try_sudo as
128
- # someone else, you'd just do try_sudo('something', :as => "bob"). If you
129
- # always wanted sudo to run as a particular user, you could do
130
- # set(:admin_runner, "bob").
131
- def try_sudo(*args)
132
- options = args.last.is_a?(Hash) ? args.pop : {}
133
- command = args.shift
134
- raise ArgumentError, "too many arguments" if args.any?
135
-
136
- as = options.fetch(:as, fetch(:admin_runner, nil))
137
- via = fetch(:run_method, :sudo)
138
- if command
139
- invoke_command(command, :via => via, :as => as)
140
- elsif via == :sudo
141
- sudo(:as => as)
142
- else
143
- ""
144
- end
145
- end
146
-
147
- # Same as sudo, but tries sudo with :as set to the value of the :runner
148
- # variable (which defaults to "app").
149
- def try_runner(*args)
150
- options = args.last.is_a?(Hash) ? args.pop : {}
151
- args << options.merge(:as => fetch(:runner, "app"))
152
- try_sudo(*args)
153
- end
154
-
155
- # =========================================================================
156
- # These are the tasks that are available to help with deploying web apps,
157
- # and specifically, Rails applications. You can have cap give you a summary
158
- # of them with `cap -T'.
159
- # =========================================================================
160
-
161
- namespace :deploy do
162
- desc <<-DESC
163
- Deploys your project. This calls both `update' and `restart'. Note that \
164
- this will generally only work for applications that have already been deployed \
165
- once. For a "cold" deploy, you'll want to take a look at the `deploy:cold' \
166
- task, which handles the cold start specifically.
167
- DESC
168
- task :default do
169
- update
170
- restart
171
- end
172
-
173
- desc <<-DESC
174
- Prepares one or more servers for deployment. Before you can use any \
175
- of the Capistrano deployment tasks with your project, you will need to \
176
- make sure all of your servers have been prepared with `cap deploy:setup'. When \
177
- you add a new server to your cluster, you can easily run the setup task \
178
- on just that server by specifying the HOSTS environment variable:
179
-
180
- $ cap HOSTS=new.server.com deploy:setup
181
-
182
- It is safe to run this task on servers that have already been set up; it \
183
- will not destroy any deployed revisions or data.
184
- DESC
185
- task :setup, :except => { :no_release => true } do
186
- dirs = [deploy_to, releases_path, shared_path]
187
- dirs += shared_children.map { |d| File.join(shared_path, d) }
188
- run "#{try_sudo} mkdir -p #{dirs.join(' ')}"
189
- run "#{try_sudo} chmod g+w #{dirs.join(' ')}" if fetch(:group_writable, true)
190
- end
191
-
192
- desc <<-DESC
193
- Copies your project and updates the symlink. It does this in a \
194
- transaction, so that if either `update_code' or `symlink' fail, all \
195
- changes made to the remote servers will be rolled back, leaving your \
196
- system in the same state it was in before `update' was invoked. Usually, \
197
- you will want to call `deploy' instead of `update', but `update' can be \
198
- handy if you want to deploy, but not immediately restart your application.
199
- DESC
200
- task :update do
201
- transaction do
202
- update_code
203
- symlink
204
- end
205
- end
206
-
207
- desc <<-DESC
208
- Copies your project to the remote servers. This is the first stage \
209
- of any deployment; moving your updated code and assets to the deployment \
210
- servers. You will rarely call this task directly, however; instead, you \
211
- should call the `deploy' task (to do a complete deploy) or the `update' \
212
- task (if you want to perform the `restart' task separately).
213
-
214
- You will need to make sure you set the :scm variable to the source \
215
- control software you are using (it defaults to :subversion), and the \
216
- :deploy_via variable to the strategy you want to use to deploy (it \
217
- defaults to :checkout).
218
- DESC
219
- task :update_code, :except => { :no_release => true } do
220
- on_rollback { run "rm -rf #{release_path}; true" }
221
- strategy.deploy!
222
- finalize_update
223
- end
224
-
225
- desc <<-DESC
226
- [internal] Touches up the released code. This is called by update_code \
227
- after the basic deploy finishes. It assumes a Rails project was deployed, \
228
- so if you are deploying something else, you may want to override this \
229
- task with your own environment's requirements.
230
-
231
- This task will make the release group-writable (if the :group_writable \
232
- variable is set to true, which is the default). It will then set up \
233
- symlinks to the shared directory for the log, system, and tmp/pids \
234
- directories, and will lastly touch all assets in public/images, \
235
- public/stylesheets, and public/javascripts so that the times are \
236
- consistent (so that asset timestamping works). This touch process \
237
- is only carried out if the :normalize_asset_timestamps variable is \
238
- set to true, which is the default The asset directories can be overridden \
239
- using the :public_children variable.
240
- DESC
241
- task :finalize_update, :except => { :no_release => true } do
242
- run "chmod -R g+w #{latest_release}" if fetch(:group_writable, true)
243
-
244
- # mkdir -p is making sure that the directories are there for some SCM's that don't
245
- # save empty folders
246
- run <<-CMD
247
- rm -rf #{latest_release}/log #{latest_release}/public/system #{latest_release}/tmp/pids &&
248
- mkdir -p #{latest_release}/public &&
249
- mkdir -p #{latest_release}/tmp &&
250
- ln -s #{shared_path}/log #{latest_release}/log &&
251
- ln -s #{shared_path}/system #{latest_release}/public/system &&
252
- ln -s #{shared_path}/pids #{latest_release}/tmp/pids
253
- CMD
254
-
255
- if fetch(:normalize_asset_timestamps, true)
256
- stamp = Time.now.utc.strftime("%Y%m%d%H%M.%S")
257
- asset_paths = fetch(:public_children, %w(images stylesheets javascripts)).map { |p| "#{latest_release}/public/#{p}" }.join(" ")
258
- run "find #{asset_paths} -exec touch -t #{stamp} {} ';'; true", :env => { "TZ" => "UTC" }
259
- end
260
- end
261
-
262
- desc <<-DESC
263
- Updates the symlink to the most recently deployed version. Capistrano works \
264
- by putting each new release of your application in its own directory. When \
265
- you deploy a new version, this task's job is to update the `current' symlink \
266
- to point at the new version. You will rarely need to call this task \
267
- directly; instead, use the `deploy' task (which performs a complete \
268
- deploy, including `restart') or the 'update' task (which does everything \
269
- except `restart').
270
- DESC
271
- task :symlink, :except => { :no_release => true } do
272
- on_rollback do
273
- if previous_release
274
- run "rm -f #{current_path}; ln -s #{previous_release} #{current_path}; true"
275
- else
276
- logger.important "no previous release to rollback to, rollback of symlink skipped"
277
- end
278
- end
279
-
280
- run "rm -f #{current_path} && ln -s #{latest_release} #{current_path}"
281
- end
282
-
283
- desc <<-DESC
284
- Copy files to the currently deployed version. This is useful for updating \
285
- files piecemeal, such as when you need to quickly deploy only a single \
286
- file. Some files, such as updated templates, images, or stylesheets, \
287
- might not require a full deploy, and especially in emergency situations \
288
- it can be handy to just push the updates to production, quickly.
289
-
290
- To use this task, specify the files and directories you want to copy as a \
291
- comma-delimited list in the FILES environment variable. All directories \
292
- will be processed recursively, with all files being pushed to the \
293
- deployment servers.
294
-
295
- $ cap deploy:upload FILES=templates,controller.rb
296
-
297
- Dir globs are also supported:
298
-
299
- $ cap deploy:upload FILES='config/apache/*.conf'
300
- DESC
301
- task :upload, :except => { :no_release => true } do
302
- files = (ENV["FILES"] || "").split(",").map { |f| Dir[f.strip] }.flatten
303
- abort "Please specify at least one file or directory to update (via the FILES environment variable)" if files.empty?
304
-
305
- files.each { |file| top.upload(file, File.join(current_path, file)) }
306
- end
307
-
308
- desc <<-DESC
309
- Blank task exists as a hook into which to install your own environment \
310
- specific behaviour.
311
- DESC
312
- task :restart, :roles => :app, :except => { :no_release => true } do
313
- # Empty Task to overload with your platform specifics
314
- end
315
-
316
- namespace :rollback do
317
- desc <<-DESC
318
- [internal] Points the current symlink at the previous revision.
319
- This is called by the rollback sequence, and should rarely (if
320
- ever) need to be called directly.
321
- DESC
322
- task :revision, :except => { :no_release => true } do
323
- if previous_release
324
- run "rm #{current_path}; ln -s #{previous_release} #{current_path}"
325
- else
326
- abort "could not rollback the code because there is no prior release"
327
- end
328
- end
329
-
330
- desc <<-DESC
331
- [internal] Removes the most recently deployed release.
332
- This is called by the rollback sequence, and should rarely
333
- (if ever) need to be called directly.
334
- DESC
335
- task :cleanup, :except => { :no_release => true } do
336
- run "if [ `readlink #{current_path}` != #{current_release} ]; then rm -rf #{current_release}; fi"
337
- end
338
-
339
- desc <<-DESC
340
- Rolls back to the previously deployed version. The `current' symlink will \
341
- be updated to point at the previously deployed version, and then the \
342
- current release will be removed from the servers. You'll generally want \
343
- to call `rollback' instead, as it performs a `restart' as well.
344
- DESC
345
- task :code, :except => { :no_release => true } do
346
- revision
347
- cleanup
348
- end
349
-
350
- desc <<-DESC
351
- Rolls back to a previous version and restarts. This is handy if you ever \
352
- discover that you've deployed a lemon; `cap rollback' and you're right \
353
- back where you were, on the previously deployed version.
354
- DESC
355
- task :default do
356
- revision
357
- restart
358
- cleanup
359
- end
360
- end
361
-
362
- desc <<-DESC
363
- Run the migrate rake task. By default, it runs this in most recently \
364
- deployed version of the app. However, you can specify a different release \
365
- via the migrate_target variable, which must be one of :latest (for the \
366
- default behavior), or :current (for the release indicated by the \
367
- `current' symlink). Strings will work for those values instead of symbols, \
368
- too. You can also specify additional environment variables to pass to rake \
369
- via the migrate_env variable. Finally, you can specify the full path to the \
370
- rake executable by setting the rake variable. The defaults are:
371
-
372
- set :rake, "rake"
373
- set :rails_env, "production"
374
- set :migrate_env, ""
375
- set :migrate_target, :latest
376
- DESC
377
- task :migrate, :roles => :db, :only => { :primary => true } do
378
- migrate_env = fetch(:migrate_env, "")
379
- migrate_target = fetch(:migrate_target, :latest)
380
-
381
- directory = case migrate_target.to_sym
382
- when :current then current_path
383
- when :latest then latest_release
384
- else raise ArgumentError, "unknown migration target #{migrate_target.inspect}"
385
- end
386
-
387
- run "cd #{directory} && #{rake} RAILS_ENV=#{rails_env} #{migrate_env} db:migrate"
388
- end
389
-
390
- desc <<-DESC
391
- Deploy and run pending migrations. This will work similarly to the \
392
- `deploy' task, but will also run any pending migrations (via the \
393
- `deploy:migrate' task) prior to updating the symlink. Note that the \
394
- update in this case it is not atomic, and transactions are not used, \
395
- because migrations are not guaranteed to be reversible.
396
- DESC
397
- task :migrations do
398
- set :migrate_target, :latest
399
- update_code
400
- migrate
401
- symlink
402
- restart
403
- end
404
-
405
- desc <<-DESC
406
- Clean up old releases. By default, the last 5 releases are kept on each \
407
- server (though you can change this with the keep_releases variable). All \
408
- other deployed revisions are removed from the servers. By default, this \
409
- will use sudo to clean up the old releases, but if sudo is not available \
410
- for your environment, set the :use_sudo variable to false instead.
411
- DESC
412
- task :cleanup, :except => { :no_release => true } do
413
- count = fetch(:keep_releases, 5).to_i
414
- if count >= releases.length
415
- logger.important "no old releases to clean up"
416
- else
417
- logger.info "keeping #{count} of #{releases.length} deployed releases"
418
-
419
- directories = (releases - releases.last(count)).map { |release|
420
- File.join(releases_path, release) }.join(" ")
421
-
422
- try_sudo "rm -rf #{directories}"
423
- end
424
- end
425
-
426
- desc <<-DESC
427
- Test deployment dependencies. Checks things like directory permissions, \
428
- necessary utilities, and so forth, reporting on the things that appear to \
429
- be incorrect or missing. This is good for making sure a deploy has a \
430
- chance of working before you actually run `cap deploy'.
431
-
432
- You can define your own dependencies, as well, using the `depend' method:
433
-
434
- depend :remote, :gem, "tzinfo", ">=0.3.3"
435
- depend :local, :command, "svn"
436
- depend :remote, :directory, "/u/depot/files"
437
- DESC
438
- task :check, :except => { :no_release => true } do
439
- dependencies = strategy.check!
440
-
441
- other = fetch(:dependencies, {})
442
- other.each do |location, types|
443
- types.each do |type, calls|
444
- if type == :gem
445
- dependencies.send(location).command(fetch(:gem_command, "gem")).or("`gem' command could not be found. Try setting :gem_command")
446
- end
447
-
448
- calls.each do |args|
449
- dependencies.send(location).send(type, *args)
450
- end
451
- end
452
- end
453
-
454
- if dependencies.pass?
455
- puts "You appear to have all necessary dependencies installed"
456
- else
457
- puts "The following dependencies failed. Please check them and try again:"
458
- dependencies.reject { |d| d.pass? }.each do |d|
459
- puts "--> #{d.message}"
460
- end
461
- abort
462
- end
463
- end
464
-
465
- desc <<-DESC
466
- Deploys and starts a `cold' application. This is useful if you have not \
467
- deployed your application before, or if your application is (for some \
468
- other reason) not currently running. It will deploy the code, run any \
469
- pending migrations, and then instead of invoking `deploy:restart', it will \
470
- invoke `deploy:start' to fire up the application servers.
471
- DESC
472
- task :cold do
473
- update
474
- migrate
475
- start
476
- end
477
-
478
- desc <<-DESC
479
- Blank task exists as a hook into which to install your own environment \
480
- specific behaviour.
481
- DESC
482
- task :start, :roles => :app do
483
- # Empty Task to overload with your platform specifics
484
- end
485
-
486
- desc <<-DESC
487
- Blank task exists as a hook into which to install your own environment \
488
- specific behaviour.
489
- DESC
490
- task :stop, :roles => :app do
491
- # Empty Task to overload with your platform specifics
492
- end
493
-
494
- namespace :pending do
495
- desc <<-DESC
496
- Displays the `diff' since your last deploy. This is useful if you want \
497
- to examine what changes are about to be deployed. Note that this might \
498
- not be supported on all SCM's.
499
- DESC
500
- task :diff, :except => { :no_release => true } do
501
- system(source.local.diff(current_revision))
502
- end
503
-
504
- desc <<-DESC
505
- Displays the commits since your last deploy. This is good for a summary \
506
- of the changes that have occurred since the last deploy. Note that this \
507
- might not be supported on all SCM's.
508
- DESC
509
- task :default, :except => { :no_release => true } do
510
- from = source.next_revision(current_revision)
511
- system(source.local.log(from))
512
- end
513
- end
514
-
515
- namespace :web do
516
- desc <<-DESC
517
- Present a maintenance page to visitors. Disables your application's web \
518
- interface by writing a "#{maintenance_basename}.html" file to each web server. The \
519
- servers must be configured to detect the presence of this file, and if \
520
- it is present, always display it instead of performing the request.
521
-
522
- By default, the maintenance page will just say the site is down for \
523
- "maintenance", and will be back "shortly", but you can customize the \
524
- page by specifying the REASON and UNTIL environment variables:
525
-
526
- $ cap deploy:web:disable \\
527
- REASON="hardware upgrade" \\
528
- UNTIL="12pm Central Time"
529
-
530
- Further customization will require that you write your own task.
531
- DESC
532
- task :disable, :roles => :web, :except => { :no_release => true } do
533
- require 'erb'
534
- on_rollback { run "rm #{shared_path}/system/#{maintenance_basename}.html" }
535
-
536
- warn <<-EOHTACCESS
537
-
538
- # Please add something like this to your site's htaccess to redirect users to the maintenance page.
539
- # More Info: http://www.shiftcommathree.com/articles/make-your-rails-maintenance-page-respond-with-a-503
540
-
541
- ErrorDocument 503 /system/#{maintenance_basename}.html
542
- RewriteEngine On
543
- RewriteCond %{REQUEST_URI} !\.(css|gif|jpg|png)$
544
- RewriteCond %{DOCUMENT_ROOT}/system/#{maintenance_basename}.html -f
545
- RewriteCond %{SCRIPT_FILENAME} !#{maintenance_basename}.html
546
- RewriteRule ^.*$ - [redirect=503,last]
547
- EOHTACCESS
548
-
549
- reason = ENV['REASON']
550
- deadline = ENV['UNTIL']
551
-
552
- template = File.read(File.join(File.dirname(__FILE__), "templates", "maintenance.rhtml"))
553
- result = ERB.new(template).result(binding)
554
-
555
- put result, "#{shared_path}/system/#{maintenance_basename}.html", :mode => 0644
556
- end
557
-
558
- desc <<-DESC
559
- Makes the application web-accessible again. Removes the \
560
- "#{maintenance_basename}.html" page generated by deploy:web:disable, which (if your \
561
- web servers are configured correctly) will make your application \
562
- web-accessible again.
563
- DESC
564
- task :enable, :roles => :web, :except => { :no_release => true } do
565
- run "rm #{shared_path}/system/#{maintenance_basename}.html"
566
- end
567
- end
568
- end
@@ -1,37 +0,0 @@
1
- desc <<-DESC
2
- Invoke a single command on the remote servers. This is useful for performing \
3
- one-off commands that may not require a full task to be written for them. \
4
- Simply specify the command to execute via the COMMAND environment variable. \
5
- To execute the command only on certain roles, specify the ROLES environment \
6
- variable as a comma-delimited list of role names. Alternatively, you can \
7
- specify the HOSTS environment variable as a comma-delimited list of hostnames \
8
- to execute the task on those hosts, explicitly. Lastly, if you want to \
9
- execute the command via sudo, specify a non-empty value for the SUDO \
10
- environment variable.
11
-
12
- Sample usage:
13
-
14
- $ cap COMMAND=uptime HOSTS=foo.capistano.test invoke
15
- $ cap ROLES=app,web SUDO=1 COMMAND="tail -f /var/log/messages" invoke
16
- DESC
17
- task :invoke do
18
- command = ENV["COMMAND"] || ""
19
- abort "Please specify a command to execute on the remote servers (via the COMMAND environment variable)" if command.empty?
20
- method = ENV["SUDO"] ? :sudo : :run
21
- invoke_command(command, :via => method)
22
- end
23
-
24
- desc <<-DESC
25
- Begin an interactive Capistrano session. This gives you an interactive \
26
- terminal from which to execute tasks and commands on all of your servers. \
27
- (This is still an experimental feature, and is subject to change without \
28
- notice!)
29
-
30
- Sample usage:
31
-
32
- $ cap shell
33
- DESC
34
- task :shell do
35
- require 'capistrano/shell'
36
- Capistrano::Shell.run(self)
37
- end
@@ -1,53 +0,0 @@
1
-
2
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
3
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4
-
5
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
6
-
7
- <head>
8
- <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
9
- <title>System down for maintenance</title>
10
-
11
- <style type="text/css">
12
- div.outer {
13
- position: absolute;
14
- left: 50%;
15
- top: 50%;
16
- width: 500px;
17
- height: 300px;
18
- margin-left: -260px;
19
- margin-top: -150px;
20
- }
21
-
22
- .DialogBody {
23
- margin: 0;
24
- padding: 10px;
25
- text-align: left;
26
- border: 1px solid #ccc;
27
- border-right: 1px solid #999;
28
- border-bottom: 1px solid #999;
29
- background-color: #fff;
30
- }
31
-
32
- body { background-color: #fff; }
33
- </style>
34
- </head>
35
-
36
- <body>
37
-
38
- <div class="outer">
39
- <div class="DialogBody" style="text-align: center;">
40
- <div style="text-align: center; width: 200px; margin: 0 auto;">
41
- <p style="color: red; font-size: 16px; line-height: 20px;">
42
- The system is down for <%= reason ? reason : "maintenance" %>
43
- as of <%= Time.now.strftime("%H:%M %Z") %>.
44
- </p>
45
- <p style="color: #666;">
46
- It'll be back <%= deadline ? deadline : "shortly" %>.
47
- </p>
48
- </div>
49
- </div>
50
- </div>
51
-
52
- </body>
53
- </html>