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