fotonauts-capistrano 2.5.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +728 -0
- data/Manifest +104 -0
- data/README.rdoc +66 -0
- data/Rakefile +34 -0
- data/bin/cap +4 -0
- data/bin/capify +78 -0
- data/capistrano.gemspec +49 -0
- data/examples/sample.rb +14 -0
- data/lib/capistrano.rb +2 -0
- data/lib/capistrano/callback.rb +45 -0
- data/lib/capistrano/cli.rb +47 -0
- data/lib/capistrano/cli/execute.rb +84 -0
- data/lib/capistrano/cli/help.rb +118 -0
- data/lib/capistrano/cli/help.txt +62 -0
- data/lib/capistrano/cli/options.rb +224 -0
- data/lib/capistrano/cli/ui.rb +40 -0
- data/lib/capistrano/command.rb +283 -0
- data/lib/capistrano/configuration.rb +43 -0
- data/lib/capistrano/configuration/actions/file_transfer.rb +47 -0
- data/lib/capistrano/configuration/actions/inspect.rb +46 -0
- data/lib/capistrano/configuration/actions/invocation.rb +193 -0
- data/lib/capistrano/configuration/callbacks.rb +148 -0
- data/lib/capistrano/configuration/connections.rb +196 -0
- data/lib/capistrano/configuration/execution.rb +132 -0
- data/lib/capistrano/configuration/loading.rb +197 -0
- data/lib/capistrano/configuration/namespaces.rb +197 -0
- data/lib/capistrano/configuration/roles.rb +65 -0
- data/lib/capistrano/configuration/servers.rb +85 -0
- data/lib/capistrano/configuration/variables.rb +127 -0
- data/lib/capistrano/errors.rb +15 -0
- data/lib/capistrano/extensions.rb +57 -0
- data/lib/capistrano/logger.rb +59 -0
- data/lib/capistrano/processable.rb +53 -0
- data/lib/capistrano/recipes/compat.rb +32 -0
- data/lib/capistrano/recipes/deploy.rb +555 -0
- data/lib/capistrano/recipes/deploy/dependencies.rb +44 -0
- data/lib/capistrano/recipes/deploy/local_dependency.rb +54 -0
- data/lib/capistrano/recipes/deploy/remote_dependency.rb +105 -0
- data/lib/capistrano/recipes/deploy/scm.rb +19 -0
- data/lib/capistrano/recipes/deploy/scm/accurev.rb +169 -0
- data/lib/capistrano/recipes/deploy/scm/base.rb +196 -0
- data/lib/capistrano/recipes/deploy/scm/bzr.rb +83 -0
- data/lib/capistrano/recipes/deploy/scm/cvs.rb +152 -0
- data/lib/capistrano/recipes/deploy/scm/darcs.rb +85 -0
- data/lib/capistrano/recipes/deploy/scm/git.rb +271 -0
- data/lib/capistrano/recipes/deploy/scm/mercurial.rb +137 -0
- data/lib/capistrano/recipes/deploy/scm/none.rb +44 -0
- data/lib/capistrano/recipes/deploy/scm/perforce.rb +133 -0
- data/lib/capistrano/recipes/deploy/scm/subversion.rb +121 -0
- data/lib/capistrano/recipes/deploy/strategy.rb +19 -0
- data/lib/capistrano/recipes/deploy/strategy/base.rb +79 -0
- data/lib/capistrano/recipes/deploy/strategy/checkout.rb +20 -0
- data/lib/capistrano/recipes/deploy/strategy/copy.rb +210 -0
- data/lib/capistrano/recipes/deploy/strategy/export.rb +20 -0
- data/lib/capistrano/recipes/deploy/strategy/remote.rb +52 -0
- data/lib/capistrano/recipes/deploy/strategy/remote_cache.rb +56 -0
- data/lib/capistrano/recipes/deploy/templates/maintenance.rhtml +53 -0
- data/lib/capistrano/recipes/standard.rb +37 -0
- data/lib/capistrano/recipes/templates/maintenance.rhtml +53 -0
- data/lib/capistrano/recipes/upgrade.rb +33 -0
- data/lib/capistrano/role.rb +102 -0
- data/lib/capistrano/server_definition.rb +56 -0
- data/lib/capistrano/shell.rb +260 -0
- data/lib/capistrano/ssh.rb +79 -0
- data/lib/capistrano/task_definition.rb +70 -0
- data/lib/capistrano/transfer.rb +216 -0
- data/lib/capistrano/version.rb +18 -0
- data/setup.rb +1346 -0
- data/test/cli/execute_test.rb +132 -0
- data/test/cli/help_test.rb +165 -0
- data/test/cli/options_test.rb +317 -0
- data/test/cli/ui_test.rb +28 -0
- data/test/cli_test.rb +17 -0
- data/test/command_test.rb +286 -0
- data/test/configuration/actions/file_transfer_test.rb +61 -0
- data/test/configuration/actions/inspect_test.rb +65 -0
- data/test/configuration/actions/invocation_test.rb +210 -0
- data/test/configuration/callbacks_test.rb +220 -0
- data/test/configuration/connections_test.rb +348 -0
- data/test/configuration/execution_test.rb +175 -0
- data/test/configuration/loading_test.rb +132 -0
- data/test/configuration/namespace_dsl_test.rb +305 -0
- data/test/configuration/roles_test.rb +143 -0
- data/test/configuration/servers_test.rb +121 -0
- data/test/configuration/variables_test.rb +180 -0
- data/test/configuration_test.rb +88 -0
- data/test/deploy/local_dependency_test.rb +76 -0
- data/test/deploy/remote_dependency_test.rb +114 -0
- data/test/deploy/scm/accurev_test.rb +23 -0
- data/test/deploy/scm/base_test.rb +55 -0
- data/test/deploy/scm/git_test.rb +159 -0
- data/test/deploy/scm/mercurial_test.rb +129 -0
- data/test/deploy/scm/none_test.rb +35 -0
- data/test/deploy/strategy/copy_test.rb +258 -0
- data/test/extensions_test.rb +69 -0
- data/test/fixtures/cli_integration.rb +5 -0
- data/test/fixtures/config.rb +5 -0
- data/test/fixtures/custom.rb +3 -0
- data/test/logger_test.rb +123 -0
- data/test/role_test.rb +11 -0
- data/test/server_definition_test.rb +121 -0
- data/test/shell_test.rb +90 -0
- data/test/ssh_test.rb +102 -0
- data/test/task_definition_test.rb +101 -0
- data/test/transfer_test.rb +160 -0
- data/test/utils.rb +38 -0
- metadata +310 -0
@@ -0,0 +1,32 @@
|
|
1
|
+
# A collection of compatibility scripts, to ease the transition between
|
2
|
+
# Capistrano 1.x and Capistrano 2.x.
|
3
|
+
|
4
|
+
# Depends on the deployment system
|
5
|
+
load 'deploy'
|
6
|
+
|
7
|
+
map = { "diff_from_last_deploy" => "deploy:pending:diff",
|
8
|
+
"update" => "deploy:update",
|
9
|
+
"update_code" => "deploy:update_code",
|
10
|
+
"symlink" => "deploy:symlink",
|
11
|
+
"restart" => "deploy:restart",
|
12
|
+
"rollback" => "deploy:rollback",
|
13
|
+
"cleanup" => "deploy:cleanup",
|
14
|
+
"disable_web" => "deploy:web:disable",
|
15
|
+
"enable_web" => "deploy:web:enable",
|
16
|
+
"cold_deploy" => "deploy:cold",
|
17
|
+
"deploy_with_migrations" => "deploy:migrations" }
|
18
|
+
|
19
|
+
map.each do |old, new|
|
20
|
+
desc "DEPRECATED: See #{new}."
|
21
|
+
eval "task(#{old.inspect}) do
|
22
|
+
warn \"[DEPRECATED] `#{old}' is deprecated. Use `#{new}' instead.\"
|
23
|
+
find_and_execute_task(#{new.inspect})
|
24
|
+
end"
|
25
|
+
end
|
26
|
+
|
27
|
+
desc "DEPRECATED: See deploy:start."
|
28
|
+
task :spinner do
|
29
|
+
warn "[DEPRECATED] `spinner' is deprecated. Use `deploy:start' instead."
|
30
|
+
set :runner, fetch(:spinner_user, "app")
|
31
|
+
deploy.start
|
32
|
+
end
|
@@ -0,0 +1,555 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'capistrano/recipes/deploy/scm'
|
3
|
+
require 'capistrano/recipes/deploy/strategy'
|
4
|
+
|
5
|
+
def _cset(name, *args, &block)
|
6
|
+
unless exists?(name)
|
7
|
+
set(name, *args, &block)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
# =========================================================================
|
12
|
+
# These variables MUST be set in the client capfiles. If they are not set,
|
13
|
+
# the deploy will fail with an error.
|
14
|
+
# =========================================================================
|
15
|
+
|
16
|
+
_cset(:application) { abort "Please specify the name of your application, set :application, 'foo'" }
|
17
|
+
_cset(:repository) { abort "Please specify the repository that houses your application's code, set :repository, 'foo'" }
|
18
|
+
|
19
|
+
# =========================================================================
|
20
|
+
# These variables may be set in the client capfile if their default values
|
21
|
+
# are not sufficient.
|
22
|
+
# =========================================================================
|
23
|
+
|
24
|
+
_cset :scm, :subversion
|
25
|
+
_cset :deploy_via, :checkout
|
26
|
+
|
27
|
+
_cset(:deploy_to) { "/u/apps/#{application}" }
|
28
|
+
_cset(:revision) { source.head }
|
29
|
+
|
30
|
+
# =========================================================================
|
31
|
+
# These variables should NOT be changed unless you are very confident in
|
32
|
+
# what you are doing. Make sure you understand all the implications of your
|
33
|
+
# changes if you do decide to muck with these!
|
34
|
+
# =========================================================================
|
35
|
+
|
36
|
+
_cset(:source) { Capistrano::Deploy::SCM.new(scm, self) }
|
37
|
+
_cset(:real_revision) { source.local.query_revision(revision) { |cmd| with_env("LC_ALL", "C") { run_locally(cmd) } } }
|
38
|
+
|
39
|
+
_cset(:strategy) { Capistrano::Deploy::Strategy.new(deploy_via, self) }
|
40
|
+
|
41
|
+
_cset(:release_name) { set :deploy_timestamped, true; Time.now.utc.strftime("%Y%m%d%H%M%S") }
|
42
|
+
|
43
|
+
_cset :version_dir, "releases"
|
44
|
+
_cset :shared_dir, "shared"
|
45
|
+
_cset :shared_children, %w(system log pids)
|
46
|
+
_cset :current_dir, "current"
|
47
|
+
|
48
|
+
_cset(:releases_path) { File.join(deploy_to, version_dir) }
|
49
|
+
_cset(:shared_path) { File.join(deploy_to, shared_dir) }
|
50
|
+
_cset(:current_path) { File.join(deploy_to, current_dir) }
|
51
|
+
_cset(:release_path) { File.join(releases_path, release_name) }
|
52
|
+
|
53
|
+
_cset(:releases) { capture("ls -xt #{releases_path}").split.reverse }
|
54
|
+
_cset(:current_release) { File.join(releases_path, releases.last) }
|
55
|
+
_cset(:previous_release) { File.join(releases_path, releases[-2]) }
|
56
|
+
|
57
|
+
_cset(:current_revision) { capture("cat #{current_path}/REVISION").chomp }
|
58
|
+
_cset(:latest_revision) { capture("cat #{current_release}/REVISION").chomp }
|
59
|
+
_cset(:previous_revision) { capture("cat #{previous_release}/REVISION").chomp }
|
60
|
+
|
61
|
+
_cset(:run_method) { fetch(:use_sudo, true) ? :sudo : :run }
|
62
|
+
|
63
|
+
# some tasks, like symlink, need to always point at the latest release, but
|
64
|
+
# they can also (occassionally) be called standalone. In the standalone case,
|
65
|
+
# the timestamped release_path will be inaccurate, since the directory won't
|
66
|
+
# actually exist. This variable lets tasks like symlink work either in the
|
67
|
+
# standalone case, or during deployment.
|
68
|
+
_cset(:latest_release) { exists?(:deploy_timestamped) ? release_path : current_release }
|
69
|
+
|
70
|
+
# =========================================================================
|
71
|
+
# These are helper methods that will be available to your recipes.
|
72
|
+
# =========================================================================
|
73
|
+
|
74
|
+
# Auxiliary helper method for the `deploy:check' task. Lets you set up your
|
75
|
+
# own dependencies.
|
76
|
+
def depend(location, type, *args)
|
77
|
+
deps = fetch(:dependencies, {})
|
78
|
+
deps[location] ||= {}
|
79
|
+
deps[location][type] ||= []
|
80
|
+
deps[location][type] << args
|
81
|
+
set :dependencies, deps
|
82
|
+
end
|
83
|
+
|
84
|
+
# Temporarily sets an environment variable, yields to a block, and restores
|
85
|
+
# the value when it is done.
|
86
|
+
def with_env(name, value)
|
87
|
+
saved, ENV[name] = ENV[name], value
|
88
|
+
yield
|
89
|
+
ensure
|
90
|
+
ENV[name] = saved
|
91
|
+
end
|
92
|
+
|
93
|
+
# logs the command then executes it locally.
|
94
|
+
# returns the command output as a string
|
95
|
+
def run_locally(cmd)
|
96
|
+
logger.trace "executing locally: #{cmd.inspect}" if logger
|
97
|
+
`#{cmd}`
|
98
|
+
end
|
99
|
+
|
100
|
+
# If a command is given, this will try to execute the given command, as
|
101
|
+
# described below. Otherwise, it will return a string for use in embedding in
|
102
|
+
# another command, for executing that command as described below.
|
103
|
+
#
|
104
|
+
# If :run_method is :sudo (or :use_sudo is true), this executes the given command
|
105
|
+
# via +sudo+. Otherwise is uses +run+. If :as is given as a key, it will be
|
106
|
+
# passed as the user to sudo as, if using sudo. If the :as key is not given,
|
107
|
+
# it will default to whatever the value of the :admin_runner variable is,
|
108
|
+
# which (by default) is unset.
|
109
|
+
#
|
110
|
+
# THUS, if you want to try to run something via sudo, and what to use the
|
111
|
+
# root user, you'd just to try_sudo('something'). If you wanted to try_sudo as
|
112
|
+
# someone else, you'd just do try_sudo('something', :as => "bob"). If you
|
113
|
+
# always wanted sudo to run as a particular user, you could do
|
114
|
+
# set(:admin_runner, "bob").
|
115
|
+
def try_sudo(*args)
|
116
|
+
options = args.last.is_a?(Hash) ? args.pop : {}
|
117
|
+
command = args.shift
|
118
|
+
raise ArgumentError, "too many arguments" if args.any?
|
119
|
+
|
120
|
+
as = options.fetch(:as, fetch(:admin_runner, nil))
|
121
|
+
via = fetch(:run_method, :sudo)
|
122
|
+
if command
|
123
|
+
invoke_command(command, :via => via, :as => as)
|
124
|
+
elsif via == :sudo
|
125
|
+
sudo(:as => as)
|
126
|
+
else
|
127
|
+
""
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
# Same as sudo, but tries sudo with :as set to the value of the :runner
|
132
|
+
# variable (which defaults to "app").
|
133
|
+
def try_runner(*args)
|
134
|
+
options = args.last.is_a?(Hash) ? args.pop : {}
|
135
|
+
args << options.merge(:as => fetch(:runner, "app"))
|
136
|
+
try_sudo(*args)
|
137
|
+
end
|
138
|
+
|
139
|
+
# =========================================================================
|
140
|
+
# These are the tasks that are available to help with deploying web apps,
|
141
|
+
# and specifically, Rails applications. You can have cap give you a summary
|
142
|
+
# of them with `cap -T'.
|
143
|
+
# =========================================================================
|
144
|
+
|
145
|
+
namespace :deploy do
|
146
|
+
desc <<-DESC
|
147
|
+
Deploys your project. This calls both `update' and `restart'. Note that \
|
148
|
+
this will generally only work for applications that have already been deployed \
|
149
|
+
once. For a "cold" deploy, you'll want to take a look at the `deploy:cold' \
|
150
|
+
task, which handles the cold start specifically.
|
151
|
+
DESC
|
152
|
+
task :default do
|
153
|
+
update
|
154
|
+
restart
|
155
|
+
end
|
156
|
+
|
157
|
+
desc <<-DESC
|
158
|
+
Prepares one or more servers for deployment. Before you can use any \
|
159
|
+
of the Capistrano deployment tasks with your project, you will need to \
|
160
|
+
make sure all of your servers have been prepared with `cap deploy:setup'. When \
|
161
|
+
you add a new server to your cluster, you can easily run the setup task \
|
162
|
+
on just that server by specifying the HOSTS environment variable:
|
163
|
+
|
164
|
+
$ cap HOSTS=new.server.com deploy:setup
|
165
|
+
|
166
|
+
It is safe to run this task on servers that have already been set up; it \
|
167
|
+
will not destroy any deployed revisions or data.
|
168
|
+
DESC
|
169
|
+
task :setup, :except => { :no_release => true } do
|
170
|
+
dirs = [deploy_to, releases_path, shared_path]
|
171
|
+
dirs += shared_children.map { |d| File.join(shared_path, d) }
|
172
|
+
run "#{try_sudo} mkdir -p #{dirs.join(' ')} && #{try_sudo} chmod g+w #{dirs.join(' ')}"
|
173
|
+
end
|
174
|
+
|
175
|
+
desc <<-DESC
|
176
|
+
Copies your project and updates the symlink. It does this in a \
|
177
|
+
transaction, so that if either `update_code' or `symlink' fail, all \
|
178
|
+
changes made to the remote servers will be rolled back, leaving your \
|
179
|
+
system in the same state it was in before `update' was invoked. Usually, \
|
180
|
+
you will want to call `deploy' instead of `update', but `update' can be \
|
181
|
+
handy if you want to deploy, but not immediately restart your application.
|
182
|
+
DESC
|
183
|
+
task :update do
|
184
|
+
transaction do
|
185
|
+
update_code
|
186
|
+
symlink
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
desc <<-DESC
|
191
|
+
Copies your project to the remote servers. This is the first stage \
|
192
|
+
of any deployment; moving your updated code and assets to the deployment \
|
193
|
+
servers. You will rarely call this task directly, however; instead, you \
|
194
|
+
should call the `deploy' task (to do a complete deploy) or the `update' \
|
195
|
+
task (if you want to perform the `restart' task separately).
|
196
|
+
|
197
|
+
You will need to make sure you set the :scm variable to the source \
|
198
|
+
control software you are using (it defaults to :subversion), and the \
|
199
|
+
:deploy_via variable to the strategy you want to use to deploy (it \
|
200
|
+
defaults to :checkout).
|
201
|
+
DESC
|
202
|
+
task :update_code, :except => { :no_release => true } do
|
203
|
+
on_rollback { run "rm -rf #{release_path}; true" }
|
204
|
+
strategy.deploy!
|
205
|
+
finalize_update
|
206
|
+
end
|
207
|
+
|
208
|
+
desc <<-DESC
|
209
|
+
[internal] Touches up the released code. This is called by update_code \
|
210
|
+
after the basic deploy finishes. It assumes a Rails project was deployed, \
|
211
|
+
so if you are deploying something else, you may want to override this \
|
212
|
+
task with your own environment's requirements.
|
213
|
+
|
214
|
+
This task will make the release group-writable (if the :group_writable \
|
215
|
+
variable is set to true, which is the default). It will then set up \
|
216
|
+
symlinks to the shared directory for the log, system, and tmp/pids \
|
217
|
+
directories, and will lastly touch all assets in public/images, \
|
218
|
+
public/stylesheets, and public/javascripts so that the times are \
|
219
|
+
consistent (so that asset timestamping works). This touch process \
|
220
|
+
is only carried out if the :normalize_asset_timestamps variable is \
|
221
|
+
set to true, which is the default.
|
222
|
+
DESC
|
223
|
+
task :finalize_update, :except => { :no_release => true } do
|
224
|
+
run "chmod -R g+w #{latest_release}" if fetch(:group_writable, true)
|
225
|
+
|
226
|
+
# mkdir -p is making sure that the directories are there for some SCM's that don't
|
227
|
+
# save empty folders
|
228
|
+
run <<-CMD
|
229
|
+
rm -rf #{latest_release}/log #{latest_release}/public/system #{latest_release}/tmp/pids &&
|
230
|
+
mkdir -p #{latest_release}/public &&
|
231
|
+
mkdir -p #{latest_release}/tmp &&
|
232
|
+
ln -s #{shared_path}/log #{latest_release}/log &&
|
233
|
+
ln -s #{shared_path}/system #{latest_release}/public/system &&
|
234
|
+
ln -s #{shared_path}/pids #{latest_release}/tmp/pids
|
235
|
+
CMD
|
236
|
+
|
237
|
+
if fetch(:normalize_asset_timestamps, true)
|
238
|
+
stamp = Time.now.utc.strftime("%Y%m%d%H%M.%S")
|
239
|
+
asset_paths = %w(images stylesheets javascripts).map { |p| "#{latest_release}/public/#{p}" }.join(" ")
|
240
|
+
run "find #{asset_paths} -exec touch -t #{stamp} {} ';'; true", :env => { "TZ" => "UTC" }
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
desc <<-DESC
|
245
|
+
Updates the symlink to the most recently deployed version. Capistrano works \
|
246
|
+
by putting each new release of your application in its own directory. When \
|
247
|
+
you deploy a new version, this task's job is to update the `current' symlink \
|
248
|
+
to point at the new version. You will rarely need to call this task \
|
249
|
+
directly; instead, use the `deploy' task (which performs a complete \
|
250
|
+
deploy, including `restart') or the 'update' task (which does everything \
|
251
|
+
except `restart').
|
252
|
+
DESC
|
253
|
+
task :symlink, :except => { :no_release => true } do
|
254
|
+
on_rollback { run "rm -f #{current_path}; ln -s #{previous_release} #{current_path}; true" }
|
255
|
+
run "rm -f #{current_path} && ln -s #{latest_release} #{current_path}"
|
256
|
+
end
|
257
|
+
|
258
|
+
desc <<-DESC
|
259
|
+
Copy files to the currently deployed version. This is useful for updating \
|
260
|
+
files piecemeal, such as when you need to quickly deploy only a single \
|
261
|
+
file. Some files, such as updated templates, images, or stylesheets, \
|
262
|
+
might not require a full deploy, and especially in emergency situations \
|
263
|
+
it can be handy to just push the updates to production, quickly.
|
264
|
+
|
265
|
+
To use this task, specify the files and directories you want to copy as a \
|
266
|
+
comma-delimited list in the FILES environment variable. All directories \
|
267
|
+
will be processed recursively, with all files being pushed to the \
|
268
|
+
deployment servers.
|
269
|
+
|
270
|
+
$ cap deploy:upload FILES=templates,controller.rb
|
271
|
+
|
272
|
+
Dir globs are also supported:
|
273
|
+
|
274
|
+
$ cap deploy:upload FILES='config/apache/*.conf'
|
275
|
+
DESC
|
276
|
+
task :upload, :except => { :no_release => true } do
|
277
|
+
files = (ENV["FILES"] || "").split(",").map { |f| Dir[f.strip] }.flatten
|
278
|
+
abort "Please specify at least one file or directory to update (via the FILES environment variable)" if files.empty?
|
279
|
+
|
280
|
+
files.each { |file| top.upload(file, File.join(current_path, file)) }
|
281
|
+
end
|
282
|
+
|
283
|
+
desc <<-DESC
|
284
|
+
Restarts your application. This works by calling the script/process/reaper \
|
285
|
+
script under the current path.
|
286
|
+
|
287
|
+
By default, this will be invoked via sudo as the `app' user. If \
|
288
|
+
you wish to run it as a different user, set the :runner variable to \
|
289
|
+
that user. If you are in an environment where you can't use sudo, set \
|
290
|
+
the :use_sudo variable to false:
|
291
|
+
|
292
|
+
set :use_sudo, false
|
293
|
+
DESC
|
294
|
+
task :restart, :roles => :app, :except => { :no_release => true } do
|
295
|
+
try_runner "#{current_path}/script/process/reaper"
|
296
|
+
end
|
297
|
+
|
298
|
+
namespace :rollback do
|
299
|
+
desc <<-DESC
|
300
|
+
[internal] Points the current symlink at the previous revision.
|
301
|
+
This is called by the rollback sequence, and should rarely (if
|
302
|
+
ever) need to be called directly.
|
303
|
+
DESC
|
304
|
+
task :revision, :except => { :no_release => true } do
|
305
|
+
if releases.length < 2
|
306
|
+
abort "could not rollback the code because there is no prior release"
|
307
|
+
else
|
308
|
+
run "rm #{current_path}; ln -s #{previous_release} #{current_path}"
|
309
|
+
end
|
310
|
+
end
|
311
|
+
|
312
|
+
desc <<-DESC
|
313
|
+
[internal] Removes the most recently deployed release.
|
314
|
+
This is called by the rollback sequence, and should rarely
|
315
|
+
(if ever) need to be called directly.
|
316
|
+
DESC
|
317
|
+
task :cleanup, :except => { :no_release => true } do
|
318
|
+
run "if [ `readlink #{current_path}` != #{current_release} ]; then rm -rf #{current_release}; fi"
|
319
|
+
end
|
320
|
+
|
321
|
+
desc <<-DESC
|
322
|
+
Rolls back to the previously deployed version. The `current' symlink will \
|
323
|
+
be updated to point at the previously deployed version, and then the \
|
324
|
+
current release will be removed from the servers. You'll generally want \
|
325
|
+
to call `rollback' instead, as it performs a `restart' as well.
|
326
|
+
DESC
|
327
|
+
task :code, :except => { :no_release => true } do
|
328
|
+
revision
|
329
|
+
cleanup
|
330
|
+
end
|
331
|
+
|
332
|
+
desc <<-DESC
|
333
|
+
Rolls back to a previous version and restarts. This is handy if you ever \
|
334
|
+
discover that you've deployed a lemon; `cap rollback' and you're right \
|
335
|
+
back where you were, on the previously deployed version.
|
336
|
+
DESC
|
337
|
+
task :default do
|
338
|
+
revision
|
339
|
+
restart
|
340
|
+
cleanup
|
341
|
+
end
|
342
|
+
end
|
343
|
+
|
344
|
+
desc <<-DESC
|
345
|
+
Run the migrate rake task. By default, it runs this in most recently \
|
346
|
+
deployed version of the app. However, you can specify a different release \
|
347
|
+
via the migrate_target variable, which must be one of :latest (for the \
|
348
|
+
default behavior), or :current (for the release indicated by the \
|
349
|
+
`current' symlink). Strings will work for those values instead of symbols, \
|
350
|
+
too. You can also specify additional environment variables to pass to rake \
|
351
|
+
via the migrate_env variable. Finally, you can specify the full path to the \
|
352
|
+
rake executable by setting the rake variable. The defaults are:
|
353
|
+
|
354
|
+
set :rake, "rake"
|
355
|
+
set :rails_env, "production"
|
356
|
+
set :migrate_env, ""
|
357
|
+
set :migrate_target, :latest
|
358
|
+
DESC
|
359
|
+
task :migrate, :roles => :db, :only => { :primary => true } do
|
360
|
+
rake = fetch(:rake, "rake")
|
361
|
+
rails_env = fetch(:rails_env, "production")
|
362
|
+
migrate_env = fetch(:migrate_env, "")
|
363
|
+
migrate_target = fetch(:migrate_target, :latest)
|
364
|
+
|
365
|
+
directory = case migrate_target.to_sym
|
366
|
+
when :current then current_path
|
367
|
+
when :latest then current_release
|
368
|
+
else raise ArgumentError, "unknown migration target #{migrate_target.inspect}"
|
369
|
+
end
|
370
|
+
|
371
|
+
run "cd #{directory}; #{rake} RAILS_ENV=#{rails_env} #{migrate_env} db:migrate"
|
372
|
+
end
|
373
|
+
|
374
|
+
desc <<-DESC
|
375
|
+
Deploy and run pending migrations. This will work similarly to the \
|
376
|
+
`deploy' task, but will also run any pending migrations (via the \
|
377
|
+
`deploy:migrate' task) prior to updating the symlink. Note that the \
|
378
|
+
update in this case it is not atomic, and transactions are not used, \
|
379
|
+
because migrations are not guaranteed to be reversible.
|
380
|
+
DESC
|
381
|
+
task :migrations do
|
382
|
+
set :migrate_target, :latest
|
383
|
+
update_code
|
384
|
+
migrate
|
385
|
+
symlink
|
386
|
+
restart
|
387
|
+
end
|
388
|
+
|
389
|
+
desc <<-DESC
|
390
|
+
Clean up old releases. By default, the last 5 releases are kept on each \
|
391
|
+
server (though you can change this with the keep_releases variable). All \
|
392
|
+
other deployed revisions are removed from the servers. By default, this \
|
393
|
+
will use sudo to clean up the old releases, but if sudo is not available \
|
394
|
+
for your environment, set the :use_sudo variable to false instead.
|
395
|
+
DESC
|
396
|
+
task :cleanup, :except => { :no_release => true } do
|
397
|
+
count = fetch(:keep_releases, 5).to_i
|
398
|
+
if count >= releases.length
|
399
|
+
logger.important "no old releases to clean up"
|
400
|
+
else
|
401
|
+
logger.info "keeping #{count} of #{releases.length} deployed releases"
|
402
|
+
|
403
|
+
directories = (releases - releases.last(count)).map { |release|
|
404
|
+
File.join(releases_path, release) }.join(" ")
|
405
|
+
|
406
|
+
try_sudo "rm -rf #{directories}"
|
407
|
+
end
|
408
|
+
end
|
409
|
+
|
410
|
+
desc <<-DESC
|
411
|
+
Test deployment dependencies. Checks things like directory permissions, \
|
412
|
+
necessary utilities, and so forth, reporting on the things that appear to \
|
413
|
+
be incorrect or missing. This is good for making sure a deploy has a \
|
414
|
+
chance of working before you actually run `cap deploy'.
|
415
|
+
|
416
|
+
You can define your own dependencies, as well, using the `depend' method:
|
417
|
+
|
418
|
+
depend :remote, :gem, "tzinfo", ">=0.3.3"
|
419
|
+
depend :local, :command, "svn"
|
420
|
+
depend :remote, :directory, "/u/depot/files"
|
421
|
+
DESC
|
422
|
+
task :check, :except => { :no_release => true } do
|
423
|
+
dependencies = strategy.check!
|
424
|
+
|
425
|
+
other = fetch(:dependencies, {})
|
426
|
+
other.each do |location, types|
|
427
|
+
types.each do |type, calls|
|
428
|
+
if type == :gem
|
429
|
+
dependencies.send(location).command(fetch(:gem_command, "gem")).or("`gem' command could not be found. Try setting :gem_command")
|
430
|
+
end
|
431
|
+
|
432
|
+
calls.each do |args|
|
433
|
+
dependencies.send(location).send(type, *args)
|
434
|
+
end
|
435
|
+
end
|
436
|
+
end
|
437
|
+
|
438
|
+
if dependencies.pass?
|
439
|
+
puts "You appear to have all necessary dependencies installed"
|
440
|
+
else
|
441
|
+
puts "The following dependencies failed. Please check them and try again:"
|
442
|
+
dependencies.reject { |d| d.pass? }.each do |d|
|
443
|
+
puts "--> #{d.message}"
|
444
|
+
end
|
445
|
+
abort
|
446
|
+
end
|
447
|
+
end
|
448
|
+
|
449
|
+
desc <<-DESC
|
450
|
+
Deploys and starts a `cold' application. This is useful if you have not \
|
451
|
+
deployed your application before, or if your application is (for some \
|
452
|
+
other reason) not currently running. It will deploy the code, run any \
|
453
|
+
pending migrations, and then instead of invoking `deploy:restart', it will \
|
454
|
+
invoke `deploy:start' to fire up the application servers.
|
455
|
+
DESC
|
456
|
+
task :cold do
|
457
|
+
update
|
458
|
+
migrate
|
459
|
+
start
|
460
|
+
end
|
461
|
+
|
462
|
+
desc <<-DESC
|
463
|
+
Start the application servers. This will attempt to invoke a script \
|
464
|
+
in your application called `script/spin', which must know how to start \
|
465
|
+
your application listeners. For Rails applications, you might just have \
|
466
|
+
that script invoke `script/process/spawner' with the appropriate \
|
467
|
+
arguments.
|
468
|
+
|
469
|
+
By default, the script will be executed via sudo as the `app' user. If \
|
470
|
+
you wish to run it as a different user, set the :runner variable to \
|
471
|
+
that user. If you are in an environment where you can't use sudo, set \
|
472
|
+
the :use_sudo variable to false.
|
473
|
+
DESC
|
474
|
+
task :start, :roles => :app do
|
475
|
+
run "cd #{current_path} && #{try_runner} nohup script/spin"
|
476
|
+
end
|
477
|
+
|
478
|
+
desc <<-DESC
|
479
|
+
Stop the application servers. This will call script/process/reaper for \
|
480
|
+
both the spawner process, and all of the application processes it has \
|
481
|
+
spawned. As such, it is fairly Rails specific and may need to be \
|
482
|
+
overridden for other systems.
|
483
|
+
|
484
|
+
By default, the script will be executed via sudo as the `app' user. If \
|
485
|
+
you wish to run it as a different user, set the :runner variable to \
|
486
|
+
that user. If you are in an environment where you can't use sudo, set \
|
487
|
+
the :use_sudo variable to false.
|
488
|
+
DESC
|
489
|
+
task :stop, :roles => :app do
|
490
|
+
run "if [ -f #{current_path}/tmp/pids/dispatch.spawner.pid ]; then #{try_runner} #{current_path}/script/process/reaper -a kill -r dispatch.spawner.pid; fi"
|
491
|
+
try_runner "#{current_path}/script/process/reaper -a kill"
|
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.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.html" }
|
535
|
+
|
536
|
+
reason = ENV['REASON']
|
537
|
+
deadline = ENV['UNTIL']
|
538
|
+
|
539
|
+
template = File.read(File.join(File.dirname(__FILE__), "templates", "maintenance.rhtml"))
|
540
|
+
result = ERB.new(template).result(binding)
|
541
|
+
|
542
|
+
put result, "#{shared_path}/system/maintenance.html", :mode => 0644
|
543
|
+
end
|
544
|
+
|
545
|
+
desc <<-DESC
|
546
|
+
Makes the application web-accessible again. Removes the \
|
547
|
+
"maintenance.html" page generated by deploy:web:disable, which (if your \
|
548
|
+
web servers are configured correctly) will make your application \
|
549
|
+
web-accessible again.
|
550
|
+
DESC
|
551
|
+
task :enable, :roles => :web, :except => { :no_release => true } do
|
552
|
+
run "rm #{shared_path}/system/maintenance.html"
|
553
|
+
end
|
554
|
+
end
|
555
|
+
end
|