capcake 2.0.3 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/LICENSE +17 -22
- data/README.md +81 -0
- data/Rakefile +1 -0
- data/capcake.gemspec +25 -0
- data/lib/capcake.rb +0 -574
- data/lib/capistrano/cakephp.rb +13 -0
- data/lib/capistrano/cakephp/asset_compress.rb +1 -0
- data/lib/capistrano/cakephp/cake.rb +1 -0
- data/lib/capistrano/cakephp/defaults.rb +11 -0
- data/lib/capistrano/cakephp/migrations.rb +1 -0
- data/lib/capistrano/tasks/asset_compress.rake +25 -0
- data/lib/capistrano/tasks/cake.rake +25 -0
- data/lib/capistrano/tasks/migrations.rake +44 -0
- metadata +124 -58
- data/README.markdown +0 -126
- data/lib/templates/create_database.rsql +0 -6
- data/lib/templates/database.rphp +0 -14
- data/lib/templates/deploy.rb.default +0 -43
- data/lib/templates/maintenance.rhtml +0 -52
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 46eb003bd6e0b05d8bc0cb0fdceb0f18500d2d36
|
4
|
+
data.tar.gz: 43ad4d926541b31d9800cbf70be1b1a1b65059e9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4fd273215cb36ecc14c1ecb27892af8ab94aa78e4e39e57d482dfe55abeed1a8c767ddc9e0959d4bb2f13e875747e5042ba7aea767baa8ecc189fc23ae5ce6cd
|
7
|
+
data.tar.gz: 8f8831e628d3e7959d01f987f84618bb357322f82542cffa22703d621dfece27909c9e25bcd49b2d12e93601919887ea6568b1caa3d351d8b4365943a08e39b7
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
CHANGED
@@ -1,25 +1,20 @@
|
|
1
|
-
|
2
|
-
All rights reserved.
|
1
|
+
The MIT License (MIT)
|
3
2
|
|
4
|
-
|
5
|
-
are permitted provided that the following conditions are met:
|
3
|
+
Copyright (c) 2014 Jad Bitar (bitarjad@gmail.com)
|
6
4
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
may be used to endorse or promote products derived from this software
|
14
|
-
without specific prior written permission.
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
15
11
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
OF
|
24
|
-
|
25
|
-
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
# Capistrano::cakephp
|
2
|
+
|
3
|
+
Deploy CakePHP applications with Capistrano v3.*
|
4
|
+
|
5
|
+
IMPORTANT: Tested with CakePHP 3 thus far, but should work for CakePHP 2 that uses composer.
|
6
|
+
|
7
|
+
## Requirements
|
8
|
+
|
9
|
+
The remote server(s) require the `acl` package:
|
10
|
+
|
11
|
+
```
|
12
|
+
$ sudo apt-get install acl
|
13
|
+
```
|
14
|
+
|
15
|
+
## Installation
|
16
|
+
|
17
|
+
Add this line to your application's Gemfile:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
gem 'capistrano', '~> 3.0.0'
|
21
|
+
gem 'capcake', '~> 3.0.0'
|
22
|
+
```
|
23
|
+
|
24
|
+
And then execute:
|
25
|
+
|
26
|
+
$ bundle
|
27
|
+
|
28
|
+
Or install it yourself as:
|
29
|
+
|
30
|
+
$ gem install capcake
|
31
|
+
|
32
|
+
At this point, you can install capistrano:
|
33
|
+
|
34
|
+
$ cap install
|
35
|
+
|
36
|
+
This will create the required files in your `ROOT/config` directory
|
37
|
+
|
38
|
+
At any time, for help:
|
39
|
+
|
40
|
+
$ cap -T
|
41
|
+
|
42
|
+
### Suggestions
|
43
|
+
|
44
|
+
Add `.capistrano` to your `.gitignore`:
|
45
|
+
|
46
|
+
```
|
47
|
+
echo .capistrano/* >> .gitignore
|
48
|
+
```
|
49
|
+
|
50
|
+
## Usage
|
51
|
+
|
52
|
+
Require the module in your `Capfile`:
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
require 'capistrano/cakephp'
|
56
|
+
```
|
57
|
+
|
58
|
+
Some extras:
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
require 'capistrano/cakephp/assets'
|
62
|
+
require 'capistrano/cakephp/migrations'
|
63
|
+
```
|
64
|
+
|
65
|
+
### Configuration
|
66
|
+
|
67
|
+
The gem makes the following configuration variables available (shown with defaults)
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
set :cakephp_roles, :all
|
71
|
+
set :cakephp_flags, ''
|
72
|
+
set :cakephp_user, 'www-data'
|
73
|
+
```
|
74
|
+
|
75
|
+
## Contributing
|
76
|
+
|
77
|
+
1. Fork it
|
78
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
79
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
80
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
81
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/capcake.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = 'capcake'
|
6
|
+
spec.version = '3.0.0'
|
7
|
+
spec.authors = ['Jad Bitar']
|
8
|
+
spec.email = ['bitarjad@gmail.com']
|
9
|
+
spec.description = %q{CakePHP deployment for Capistrano 3.x}
|
10
|
+
spec.summary = %q{Native integration with popular CakePHP plugins (i.e. AssetCompress, Migrations)}
|
11
|
+
spec.homepage = 'https://github.com/jadb/capcake'
|
12
|
+
spec.license = 'MIT'
|
13
|
+
|
14
|
+
spec.files = `git ls-files`.split($/)
|
15
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
16
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
|
+
spec.require_paths = ['lib']
|
18
|
+
|
19
|
+
spec.add_dependency 'capistrano', '~> 3.0', '>= 3.0.0'
|
20
|
+
spec.add_dependency 'capistrano-composer', '~> 0', '>= 0.0.3'
|
21
|
+
spec.add_dependency 'capistrano-file-permissions', '~> 0', '>= 0.0.1'
|
22
|
+
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
24
|
+
spec.add_development_dependency 'rake', '~> 0'
|
25
|
+
end
|
data/lib/capcake.rb
CHANGED
@@ -1,574 +0,0 @@
|
|
1
|
-
# Capcake capistrano's recipe
|
2
|
-
#
|
3
|
-
# Author:: Jad Bitar (mailto:jadbitar@mac.com)
|
4
|
-
# Copyright:: Copyright (c) 2005-2009, WDT Media Corp (http://wdtmedia.net)
|
5
|
-
# License:: http://opensource.org/licenses/bsd-license.php The BSD License
|
6
|
-
|
7
|
-
Capistrano::Configuration.instance(:must_exist).load do
|
8
|
-
|
9
|
-
require 'capistrano/recipes/deploy/scm'
|
10
|
-
require 'capistrano/recipes/deploy/strategy'
|
11
|
-
|
12
|
-
# =========================================================================
|
13
|
-
# These variables may be set in the client capfile if their default values
|
14
|
-
# are not sufficient.
|
15
|
-
# =========================================================================
|
16
|
-
|
17
|
-
set :application, ""
|
18
|
-
set :branch, "master"
|
19
|
-
set :deploy_to, ""
|
20
|
-
set :keep_releases, 5
|
21
|
-
set :repository, ""
|
22
|
-
set :use_sudo, false
|
23
|
-
set :user, "deployer"
|
24
|
-
|
25
|
-
# =========================================================================
|
26
|
-
# These variables should NOT be changed unless you are very confident in
|
27
|
-
# what you are doing. Make sure you understand all the implications of your
|
28
|
-
# changes if you do decide to muck with these!
|
29
|
-
# =========================================================================
|
30
|
-
|
31
|
-
set :cake2, true
|
32
|
-
set :scm, :git
|
33
|
-
set :git_enable_submodules, 1
|
34
|
-
set :deploy_via, :checkout
|
35
|
-
|
36
|
-
set :git_flag_quiet, ""
|
37
|
-
|
38
|
-
_cset(:cake_branch) { "" }
|
39
|
-
_cset(:cake_repo) { "git://github.com/cakephp/cakephp.git" }
|
40
|
-
_cset :tmp_children, %w(cache logs sessions tests)
|
41
|
-
_cset :cache_children, %w(models persistent views)
|
42
|
-
_cset :logs_files, %w(debug error)
|
43
|
-
|
44
|
-
def capcake()
|
45
|
-
set :deploy_to, "/var/www/#{application}" if (deploy_to.empty?)
|
46
|
-
set(:current_path) { File.join(deploy_to, current_dir) }
|
47
|
-
if cake2
|
48
|
-
set :shared_children, %w(Config System tmp)
|
49
|
-
set :database_partial_path, "Config/database.php"
|
50
|
-
else
|
51
|
-
set :shared_children, %w(config system tmp)
|
52
|
-
set :database_partial_path, "config/database.php"
|
53
|
-
end
|
54
|
-
set(:database_path) { File.join(shared_path, database_partial_path) }
|
55
|
-
set(:shared_path) { File.join(deploy_to, shared_dir) }
|
56
|
-
_cset(:cake_path) { shared_path }
|
57
|
-
_cset(:tmp_path) { File.join(shared_path, "tmp") }
|
58
|
-
_cset(:cache_path) { File.join(tmp_path, "cache") }
|
59
|
-
_cset(:logs_path) { File.join(tmp_path, "logs") }
|
60
|
-
|
61
|
-
end
|
62
|
-
|
63
|
-
def defaults(val, default)
|
64
|
-
val = default if (val.empty?)
|
65
|
-
val
|
66
|
-
end
|
67
|
-
|
68
|
-
def remote_file_exists?(full_path)
|
69
|
-
'true' == capture("if [ -e #{full_path} ]; then echo 'true'; fi").strip
|
70
|
-
end
|
71
|
-
|
72
|
-
# =========================================================================
|
73
|
-
# These are the tasks that are available to help with deploying web apps,
|
74
|
-
# and specifically, Rails applications. You can have cap give you a summary
|
75
|
-
# of them with `cap -T'.
|
76
|
-
# =========================================================================
|
77
|
-
|
78
|
-
namespace :deploy do
|
79
|
-
desc <<-DESC
|
80
|
-
Deploys your project. This calls `update`. Note that \
|
81
|
-
this will generally only work for applications that have already been deployed \
|
82
|
-
once. For a "cold" deploy, you'll want to take a look at the `deploy:cold` \
|
83
|
-
task, which handles the cold start specifically.
|
84
|
-
DESC
|
85
|
-
task :default do
|
86
|
-
update
|
87
|
-
end
|
88
|
-
desc <<-DESC
|
89
|
-
Prepares one or more servers for deployment. Before you can use any \
|
90
|
-
of the Capistrano deployment tasks with your project, you will need to \
|
91
|
-
make sure all of your servers have been prepared with `cap deploy:setup`. When \
|
92
|
-
you add a new server to your cluster, you can easily run the setup task \
|
93
|
-
on just that server by specifying the HOSTS environment variable:
|
94
|
-
|
95
|
-
$ cap HOSTS=new.server.com deploy:setup
|
96
|
-
|
97
|
-
It is safe to run this task on servers that have already been set up; it \
|
98
|
-
will not destroy any deployed revisions or data.
|
99
|
-
DESC
|
100
|
-
task :setup, :except => { :no_release => true } do
|
101
|
-
dirs = [deploy_to, releases_path, shared_path]
|
102
|
-
dirs += shared_children.map { |d| File.join(shared_path, d) }
|
103
|
-
tmp_dirs = tmp_children.map { |d| File.join(tmp_path, d) }
|
104
|
-
tmp_dirs += cache_children.map { |d| File.join(cache_path, d) }
|
105
|
-
run "#{try_sudo} mkdir -p #{(dirs + tmp_dirs).join(' ')} && #{try_sudo} chmod -R 777 #{tmp_path}" if (!user.empty?)
|
106
|
-
set :git_flag_quiet, "-q "
|
107
|
-
cake.setup if (!cake_branch.empty?)
|
108
|
-
cake.database.config if (!remote_file_exists?(database_path))
|
109
|
-
end
|
110
|
-
|
111
|
-
desc <<-DESC
|
112
|
-
Copies your project and updates the symlink. It does this in a \
|
113
|
-
transaction, so that if either `update_code` or `symlink` fail, all \
|
114
|
-
changes made to the remote servers will be rolled back, leaving your \
|
115
|
-
system in the same state it was in before `update` was invoked. Usually, \
|
116
|
-
you will want to call `deploy` instead of `update`, but `update` can be \
|
117
|
-
handy if you want to deploy, but not immediately restart your application.
|
118
|
-
DESC
|
119
|
-
task :update do
|
120
|
-
transaction do
|
121
|
-
update_code
|
122
|
-
symlink
|
123
|
-
cake.cache.clear
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
desc <<-DESC
|
128
|
-
Copies your project to the remote servers. This is the first stage \
|
129
|
-
of any deployment; moving your updated code and assets to the deployment \
|
130
|
-
servers. You will rarely call this task directly, however; instead, you \
|
131
|
-
should call the `deploy` task (to do a complete deploy) or the `update` \
|
132
|
-
task (if you want to perform the `restart` task separately).
|
133
|
-
|
134
|
-
You will need to make sure you set the :scm variable to the source \
|
135
|
-
control software you are using (it defaults to :subversion), and the \
|
136
|
-
:deploy_via variable to the strategy you want to use to deploy (it \
|
137
|
-
defaults to :checkout).
|
138
|
-
DESC
|
139
|
-
task :update_code, :except => { :no_release => true } do
|
140
|
-
on_rollback { run "rm -rf #{release_path}; true" }
|
141
|
-
strategy.deploy!
|
142
|
-
finalize_update
|
143
|
-
end
|
144
|
-
|
145
|
-
desc <<-DESC
|
146
|
-
[internal] This task will make the release group-writable (if the :group_writable \
|
147
|
-
variable is set to true, which is the default).
|
148
|
-
DESC
|
149
|
-
task :finalize_update, :except => { :no_release => true } do
|
150
|
-
run "chmod -R g+w #{latest_release}" if fetch(:group_writable, true)
|
151
|
-
end
|
152
|
-
|
153
|
-
desc <<-DESC
|
154
|
-
Updates the symlinks to the most recently deployed version. Capistrano works \
|
155
|
-
by putting each new release of your application in its own directory. When \
|
156
|
-
you deploy a new version, this task's job is to update the `current`, \
|
157
|
-
`current/tmp`, `current/webroot/system` symlinks to point at the new version. \
|
158
|
-
|
159
|
-
You will rarely need to call this task directly; instead, use the `deploy` \
|
160
|
-
task (which performs a complete deploy, including `restart`) or the 'update` \
|
161
|
-
task (which does everything except `restart`).
|
162
|
-
DESC
|
163
|
-
task :symlink, :except => { :no_release => true } do
|
164
|
-
on_rollback do
|
165
|
-
if previous_release
|
166
|
-
run "rm -f #{current_path}; ln -s #{previous_release} #{current_path}; true"
|
167
|
-
else
|
168
|
-
logger.important "no previous release to rollback to, rollback of symlink skipped"
|
169
|
-
end
|
170
|
-
end
|
171
|
-
run "rm -rf #{latest_release}/tmp" if (!remote_file_exists?("#{latest_release}/tmp/empty"))
|
172
|
-
run "ln -s #{shared_path}/system #{latest_release}/webroot/system && ln -s #{shared_path}/tmp #{latest_release}/tmp";
|
173
|
-
run "rm -f #{current_path} && ln -s #{latest_release} #{current_path}"
|
174
|
-
cake.database.symlink if (remote_file_exists?(database_path))
|
175
|
-
end
|
176
|
-
|
177
|
-
desc <<-DESC
|
178
|
-
Copy files to the currently deployed version. This is useful for updating \
|
179
|
-
files piecemeal, such as when you need to quickly deploy only a single \
|
180
|
-
file. Some files, such as updated templates, images, or stylesheets, \
|
181
|
-
might not require a full deploy, and especially in emergency situations \
|
182
|
-
it can be handy to just push the updates to production, quickly.
|
183
|
-
|
184
|
-
To use this task, specify the files and directories you want to copy as a \
|
185
|
-
comma-delimited list in the FILES environment variable. All directories \
|
186
|
-
will be processed recursively, with all files being pushed to the \
|
187
|
-
deployment servers.
|
188
|
-
|
189
|
-
$ cap deploy:upload FILES=templates,controller.rb
|
190
|
-
|
191
|
-
Dir globs are also supported:
|
192
|
-
|
193
|
-
$ cap deploy:upload FILES='config/apache/*.conf'
|
194
|
-
DESC
|
195
|
-
task :upload, :except => { :no_release => true } do
|
196
|
-
files = (ENV["FILES"] || "").split(",").map { |f| Dir[f.strip] }.flatten
|
197
|
-
abort "Please specify at least one file or directory to update (via the FILES environment variable)" if files.empty?
|
198
|
-
|
199
|
-
files.each { |file| top.upload(file, File.join(current_path, file)) }
|
200
|
-
end
|
201
|
-
|
202
|
-
namespace :rollback do
|
203
|
-
desc <<-DESC
|
204
|
-
[internal] Points the current symlink at the previous revision.
|
205
|
-
This is called by the rollback sequence, and should rarely (if
|
206
|
-
ever) need to be called directly.
|
207
|
-
DESC
|
208
|
-
task :revision, :except => { :no_release => true } do
|
209
|
-
if previous_release
|
210
|
-
run "rm #{current_path}; ln -s #{previous_release} #{current_path};"
|
211
|
-
else
|
212
|
-
abort "could not rollback the code because there is no prior release"
|
213
|
-
end
|
214
|
-
end
|
215
|
-
|
216
|
-
desc <<-DESC
|
217
|
-
[internal] Removes the most recently deployed release.
|
218
|
-
This is called by the rollback sequence, and should rarely
|
219
|
-
(if ever) need to be called directly.
|
220
|
-
DESC
|
221
|
-
task :cleanup, :except => { :no_release => true } do
|
222
|
-
run "if [ `readlink #{current_path}` != #{current_release} ]; then rm -rf #{current_release}; fi"
|
223
|
-
end
|
224
|
-
|
225
|
-
desc <<-DESC
|
226
|
-
Rolls back to the previously deployed version. The `current` symlink will \
|
227
|
-
be updated to point at the previously deployed version, and then the \
|
228
|
-
current release will be removed from the servers.
|
229
|
-
DESC
|
230
|
-
task :code, :except => { :no_release => true } do
|
231
|
-
revision
|
232
|
-
cleanup
|
233
|
-
end
|
234
|
-
|
235
|
-
desc <<-DESC
|
236
|
-
Rolls back to a previous version and restarts. This is handy if you ever \
|
237
|
-
discover that you've deployed a lemon; `cap rollback` and you're right \
|
238
|
-
back where you were, on the previously deployed version.
|
239
|
-
DESC
|
240
|
-
task :default do
|
241
|
-
revision
|
242
|
-
cleanup
|
243
|
-
end
|
244
|
-
end
|
245
|
-
|
246
|
-
desc <<-DESC
|
247
|
-
Clean up old releases. By default, the last 5 releases are kept on each \
|
248
|
-
server (though you can change this with the keep_releases variable). All \
|
249
|
-
other deployed revisions are removed from the servers. By default, this \
|
250
|
-
will use sudo to clean up the old releases, but if sudo is not available \
|
251
|
-
for your environment, set the :use_sudo variable to false instead.
|
252
|
-
DESC
|
253
|
-
task :cleanup, :except => { :no_release => true } do
|
254
|
-
count = fetch(:keep_releases, 5).to_i
|
255
|
-
if count >= releases.length
|
256
|
-
logger.important "no old releases to clean up"
|
257
|
-
else
|
258
|
-
logger.info "keeping #{count} of #{releases.length} deployed releases"
|
259
|
-
|
260
|
-
directories = (releases - releases.last(count)).map { |release|
|
261
|
-
File.join(releases_path, release) }.join(" ")
|
262
|
-
|
263
|
-
try_sudo "rm -rf #{directories}"
|
264
|
-
end
|
265
|
-
end
|
266
|
-
|
267
|
-
desc <<-DESC
|
268
|
-
Test deployment dependencies. Checks things like directory permissions, \
|
269
|
-
necessary utilities, and so forth, reporting on the things that appear to \
|
270
|
-
be incorrect or missing. This is good for making sure a deploy has a \
|
271
|
-
chance of working before you actually run `cap deploy`.
|
272
|
-
|
273
|
-
You can define your own dependencies, as well, using the `depend' method:
|
274
|
-
|
275
|
-
depend :remote, :gem, "tzinfo", ">=0.3.3"
|
276
|
-
depend :local, :command, "svn"
|
277
|
-
depend :remote, :directory, "/u/depot/files"
|
278
|
-
DESC
|
279
|
-
task :check, :except => { :no_release => true } do
|
280
|
-
dependencies = strategy.check!
|
281
|
-
|
282
|
-
other = fetch(:dependencies, {})
|
283
|
-
other.each do |location, types|
|
284
|
-
types.each do |type, calls|
|
285
|
-
if type == :gem
|
286
|
-
dependencies.send(location).command(fetch(:gem_command, "gem")).or("`gem' command could not be found. Try setting :gem_command")
|
287
|
-
end
|
288
|
-
|
289
|
-
calls.each do |args|
|
290
|
-
dependencies.send(location).send(type, *args)
|
291
|
-
end
|
292
|
-
end
|
293
|
-
end
|
294
|
-
|
295
|
-
if dependencies.pass?
|
296
|
-
puts "You appear to have all necessary dependencies installed"
|
297
|
-
else
|
298
|
-
puts "The following dependencies failed. Please check them and try again:"
|
299
|
-
dependencies.reject { |d| d.pass? }.each do |d|
|
300
|
-
puts "--> #{d.message}"
|
301
|
-
end
|
302
|
-
abort
|
303
|
-
end
|
304
|
-
end
|
305
|
-
|
306
|
-
desc <<-DESC
|
307
|
-
Deploys and starts a `cold` application. This is useful if you have never \
|
308
|
-
deployed your application before. It currently runs `deploy:setup` followed \
|
309
|
-
by `deploy:update`. \
|
310
|
-
(This is still an experimental feature, and is subject to change without \
|
311
|
-
notice!)
|
312
|
-
DESC
|
313
|
-
task :cold do
|
314
|
-
setup
|
315
|
-
update
|
316
|
-
end
|
317
|
-
|
318
|
-
namespace :pending do
|
319
|
-
desc <<-DESC
|
320
|
-
Displays the `diff` since your last deploy. This is useful if you want \
|
321
|
-
to examine what changes are about to be deployed. Note that this might \
|
322
|
-
not be supported on all SCM's.
|
323
|
-
DESC
|
324
|
-
task :diff, :except => { :no_release => true } do
|
325
|
-
system(source.local.diff(current_revision))
|
326
|
-
end
|
327
|
-
|
328
|
-
desc <<-DESC
|
329
|
-
Displays the commits since your last deploy. This is good for a summary \
|
330
|
-
of the changes that have occurred since the last deploy. Note that this \
|
331
|
-
might not be supported on all SCM's.
|
332
|
-
DESC
|
333
|
-
task :default, :except => { :no_release => true } do
|
334
|
-
from = source.next_revision(current_revision)
|
335
|
-
system(source.local.log(from))
|
336
|
-
end
|
337
|
-
end
|
338
|
-
|
339
|
-
namespace :web do
|
340
|
-
desc <<-DESC
|
341
|
-
Present a maintenance page to visitors. Disables your application's web \
|
342
|
-
interface by writing a "maintenance.html" file to each web server. The \
|
343
|
-
servers must be configured to detect the presence of this file, and if \
|
344
|
-
it is present, always display it instead of performing the request.
|
345
|
-
|
346
|
-
By default, the maintenance page will just say the site is down for \
|
347
|
-
"maintenance", and will be back "shortly", but you can customize the \
|
348
|
-
page by specifying the REASON and UNTIL environment variables:
|
349
|
-
|
350
|
-
$ cap deploy:web:disable \\
|
351
|
-
REASON="hardware upgrade" \\
|
352
|
-
UNTIL="12pm Central Time"
|
353
|
-
|
354
|
-
Further customization will require that you write your own task.
|
355
|
-
DESC
|
356
|
-
task :disable, :roles => :web, :except => { :no_release => true } do
|
357
|
-
require 'erb'
|
358
|
-
on_rollback { run "rm #{shared_path}/system/maintenance.html" }
|
359
|
-
|
360
|
-
warn <<-EOHTACCESS
|
361
|
-
|
362
|
-
# Please add something like this to your site's htaccess to redirect users to the maintenance page.
|
363
|
-
# More Info: http://www.shiftcommathree.com/articles/make-your-rails-maintenance-page-respond-with-a-503
|
364
|
-
|
365
|
-
ErrorDocument 503 /system/maintenance.html
|
366
|
-
RewriteEngine On
|
367
|
-
RewriteCond %{REQUEST_URI} !\.(css|gif|jpg|png)$
|
368
|
-
RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
|
369
|
-
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
|
370
|
-
RewriteRule ^.*$ - [redirect=503,last]
|
371
|
-
EOHTACCESS
|
372
|
-
|
373
|
-
reason = ENV['REASON']
|
374
|
-
deadline = ENV['UNTIL']
|
375
|
-
|
376
|
-
template = File.read(File.join(File.dirname(__FILE__), "templates", "maintenance.rhtml"))
|
377
|
-
result = ERB.new(template).result(binding)
|
378
|
-
|
379
|
-
put(result, "#{shared_path}/system/maintenance.html", :mode => 0644, :via => :scp)
|
380
|
-
end
|
381
|
-
|
382
|
-
desc <<-DESC
|
383
|
-
Makes the application web-accessible again. Removes the \
|
384
|
-
"maintenance.html" page generated by deploy:web:disable, which (if your \
|
385
|
-
web servers are configured correctly) will make your application \
|
386
|
-
web-accessible again.
|
387
|
-
DESC
|
388
|
-
task :enable, :roles => :web, :except => { :no_release => true } do
|
389
|
-
run "rm #{shared_path}/system/maintenance.html"
|
390
|
-
end
|
391
|
-
end
|
392
|
-
|
393
|
-
desc <<-DESC
|
394
|
-
Quick server(s) reset. For now, it deletes all files/folders in :deploy_to \
|
395
|
-
(This is still an experimental feature, and is subject to change without \
|
396
|
-
notice!) \
|
397
|
-
|
398
|
-
Used only when first testing setup deploy recipes and want to quickly \
|
399
|
-
reset servers.
|
400
|
-
DESC
|
401
|
-
task :destroy do
|
402
|
-
set(:confirm) do
|
403
|
-
Capistrano::CLI.ui.ask "This will delete your project on all servers. Are you sure you wish to continue? [Y/n]"
|
404
|
-
end
|
405
|
-
run "#{try_sudo} rm -rf #{deploy_to}/*" if (confirm == "Y")
|
406
|
-
end
|
407
|
-
|
408
|
-
end
|
409
|
-
|
410
|
-
namespace :cake do
|
411
|
-
|
412
|
-
desc <<-DESC
|
413
|
-
Prepares server for deployment of a CakePHP application. \
|
414
|
-
|
415
|
-
By default, it will create a shallow clone of the CakePHP repository \
|
416
|
-
inside #{shared_path}/cakephp and run `deploy:cake:update`.
|
417
|
-
|
418
|
-
For more info about shallow clones: \
|
419
|
-
http://www.kernel.org/pub/software/scm/git/docs/git-clone.html \
|
420
|
-
|
421
|
-
Further customization will require that you write your own task.
|
422
|
-
DESC
|
423
|
-
desc "Prepares server for deployment of a CakePHP application"
|
424
|
-
task :setup do
|
425
|
-
run "cd #{cake_path} && git clone --depth 1 #{cake_repo} cakephp"
|
426
|
-
set :git_flag_quiet, "-q "
|
427
|
-
update
|
428
|
-
end
|
429
|
-
desc <<-DESC
|
430
|
-
Force CakePHP installation to checkout a new branch/tag. \
|
431
|
-
|
432
|
-
By default, it will checkout the :cake_branch you set in \
|
433
|
-
deploy.rb, but you can change that on runtime by specifying \
|
434
|
-
the BRANCH environment variable:
|
435
|
-
|
436
|
-
$ cap deploy:cake:update \\
|
437
|
-
BRANCH="1.3.0-alpha"
|
438
|
-
|
439
|
-
Further customization will require that you write your own task.
|
440
|
-
DESC
|
441
|
-
task :update do
|
442
|
-
set :cake_branch, ENV['BRANCH'] if ENV.has_key?('BRANCH')
|
443
|
-
stream "cd #{cake_path}/cakephp && git checkout #{git_flag_quiet}#{cake_branch}"
|
444
|
-
if cake2
|
445
|
-
run "#{try_sudo} ln -s #{shared_path}/cakephp/lib #{deploy_to}/#{version_dir}/lib"
|
446
|
-
else
|
447
|
-
run "#{try_sudo} ln -s #{shared_path}/cakephp/cake #{deploy_to}/#{version_dir}/cake"
|
448
|
-
end
|
449
|
-
run "#{try_sudo} mkdir -m 777 -p #{shared_path}/cakephp/media/transfer/img"
|
450
|
-
run "#{try_sudo} mkdir -m 777 -p #{shared_path}/cakephp/media/static/img"
|
451
|
-
run "#{try_sudo} mkdir -m 777 -p #{shared_path}/cakephp/media/filter"
|
452
|
-
run "#{try_sudo} ln -s #{shared_path}/cakephp/media #{deploy_to}/#{version_dir}/media"
|
453
|
-
run "#{try_sudo} ln -s #{shared_path}/cakephp/plugins #{deploy_to}/#{version_dir}/plugins"
|
454
|
-
run "#{try_sudo} ln -s #{shared_path}/cakephp/vendors #{deploy_to}/#{version_dir}/vendors"
|
455
|
-
end
|
456
|
-
|
457
|
-
namespace :cache do
|
458
|
-
desc <<-DESC
|
459
|
-
Clears CakePHP's APP/tmp/cache and its sub-directories.
|
460
|
-
|
461
|
-
Recursively finds all files in :cache_path and runs `rm -f` on each. If a file \
|
462
|
-
is renamed/removed after it was found but before it removes it, no error \
|
463
|
-
will prompt (-ignore_readdir_race). If symlinks are found, they will not be followed
|
464
|
-
|
465
|
-
You will rarely need to call this task directly; instead, use the `deploy` \
|
466
|
-
task (which performs a complete deploy, including `cake:cache:clear`)
|
467
|
-
DESC
|
468
|
-
task :clear, :roles => :web, :except => { :no_release => true } do
|
469
|
-
run "#{try_sudo} find -P #{cache_path} -ignore_readdir_race -type f -name '*' -exec rm -f {} \\;"
|
470
|
-
end
|
471
|
-
end
|
472
|
-
|
473
|
-
namespace :database do
|
474
|
-
desc <<-DESC
|
475
|
-
Generates CakePHP database configuration file in #{shared_path}/config \
|
476
|
-
and symlinks #{current_path}/config/database.php to it
|
477
|
-
DESC
|
478
|
-
task :config, :roles => :web, :except => { :no_release => true } do
|
479
|
-
require 'erb'
|
480
|
-
on_rollback { run "rm #{database_path}" }
|
481
|
-
puts "Database configuration"
|
482
|
-
if cake2
|
483
|
-
set :db_driver_or_datasource, 'datasource'
|
484
|
-
_cset :db_driver_or_datasource_value, defaults(Capistrano::CLI.ui.ask("datasource [Database/Mysql]:"), 'Database/Mysql')
|
485
|
-
else
|
486
|
-
set :db_driver_or_datasource, 'driver'
|
487
|
-
_cset :db_driver_or_datasource_value, defaults(Capistrano::CLI.ui.ask("driver [mysql]:"), 'mysql')
|
488
|
-
end
|
489
|
-
_cset :db_host, defaults(Capistrano::CLI.ui.ask("hostname [localhost]:"), 'localhost')
|
490
|
-
_cset :db_login, defaults(Capistrano::CLI.ui.ask("username [#{user}]:"), user)
|
491
|
-
_cset :db_password, Capistrano::CLI.password_prompt("password:")
|
492
|
-
_cset :db_name, defaults(Capistrano::CLI.ui.ask("db name [#{application}]:"), application)
|
493
|
-
_cset :db_prefix, Capistrano::CLI.ui.ask("prefix:")
|
494
|
-
_cset :db_persistent, defaults(Capistrano::CLI.ui.ask("persistent [false]:"), 'false')
|
495
|
-
_cset :db_encoding, defaults(Capistrano::CLI.ui.ask("encoding [utf8]:"), 'utf8')
|
496
|
-
|
497
|
-
template = File.read(File.join(File.dirname(__FILE__), "templates", "database.rphp"))
|
498
|
-
result = ERB.new(template).result(binding)
|
499
|
-
|
500
|
-
put(result, "#{database_path}", :mode => 0644, :via => :scp)
|
501
|
-
after("deploy:symlink", "cake:database:symlink")
|
502
|
-
end
|
503
|
-
desc <<-DESC
|
504
|
-
Creates MySQL database, database user and grants permissions on DB servers
|
505
|
-
DESC
|
506
|
-
task :create, :roles => :db, :except => { :no_release => true } do
|
507
|
-
require 'erb'
|
508
|
-
|
509
|
-
_cset :mysql_admin_user, defaults(Capistrano::CLI.ui.ask("username [root]:"), 'root')
|
510
|
-
_cset :mysql_admin_password, Capistrano::CLI.password_prompt("password:")
|
511
|
-
|
512
|
-
_cset :mysql_grant_priv_type, defaults(Capistrano::CLI.ui.ask("Grant privilege types:"), 'ALL')
|
513
|
-
_cset :mysql_grant_locations, defaults(Capistrano::CLI.ui.ask("Grant locations:"), ["localhost"])
|
514
|
-
|
515
|
-
_cset :db_login, defaults(Capistrano::CLI.ui.ask("username [#{user}]:"), user)
|
516
|
-
_cset :db_password, Capistrano::CLI.password_prompt("password:")
|
517
|
-
_cset :db_name, defaults(Capistrano::CLI.ui.ask("db name [#{application}]:"), application)
|
518
|
-
_cset :db_encoding, defaults(Capistrano::CLI.ui.ask("encoding [utf8]:"), 'utf8')
|
519
|
-
|
520
|
-
set :tmp_filename, File.join(shared_path, "config/create_db_#{db_name}.sql")
|
521
|
-
|
522
|
-
template = File.read(File.join(File.dirname(__FILE__), "templates", "create_database.rsql"))
|
523
|
-
result = ERB.new(template).result(binding)
|
524
|
-
|
525
|
-
put(result, "#{tmp_filename}", :mode => 0644, :via => :scp)
|
526
|
-
|
527
|
-
run "mysql -u #{mysql_admin_user} -p#{mysql_admin_password} < #{tmp_filename}"
|
528
|
-
run "#{try_sudo} rm #{tmp_filename}"
|
529
|
-
end
|
530
|
-
desc <<-DESC
|
531
|
-
Creates database tables on primary DB servers
|
532
|
-
DESC
|
533
|
-
task :schema, :roles => :db, :primary => true, :except => { :no_release => true } do
|
534
|
-
# ...
|
535
|
-
end
|
536
|
-
desc <<-DESC
|
537
|
-
Creates required CakePHP's APP/config/database.php as a symlink to \
|
538
|
-
#{deploy_to}/shared/config/database.php
|
539
|
-
DESC
|
540
|
-
task :symlink, :roles => :web, :except => { :no_release => true } do
|
541
|
-
run "#{try_sudo} rm -f #{current_path}/#{database_partial_path} && #{try_sudo} ln -s #{database_path} #{current_path}/#{database_partial_path}"
|
542
|
-
end
|
543
|
-
end
|
544
|
-
|
545
|
-
namespace :logs do
|
546
|
-
desc <<-DESC
|
547
|
-
Clears CakePHP's APP/tmp/logs and its sub-directories
|
548
|
-
|
549
|
-
Recursively finds all files in :logs_path and runs `rm -f` on each. If a file \
|
550
|
-
is renamed/removed after it was found but before it removes it, no error \
|
551
|
-
will prompt (-ignore_readdir_race). If symlinks are found, they will not be followed
|
552
|
-
|
553
|
-
DESC
|
554
|
-
task :clear, :roles => :web, :except => { :no_release => true } do
|
555
|
-
run "#{try_sudo} find -P #{logs_path} -ignore_readdir_race -type f -name '*' -exec rm -f {} \\;"
|
556
|
-
end
|
557
|
-
desc <<-DESC
|
558
|
-
Streams the result of `tail -f` on all :logs_files \
|
559
|
-
|
560
|
-
By default, the files are `debug` and `error`. You can add your own \
|
561
|
-
in config/deploy.rb
|
562
|
-
|
563
|
-
set :logs_files %w(debug error my_log_file)
|
564
|
-
|
565
|
-
DESC
|
566
|
-
task :tail, :roles => :web, :except => { :no_release => true } do
|
567
|
-
files = logs_files.map { |d| File.join(logs_path, d) }
|
568
|
-
stream "#{try_sudo} tail -f #{files.join(' ')}"
|
569
|
-
end
|
570
|
-
end
|
571
|
-
|
572
|
-
end
|
573
|
-
|
574
|
-
end # Capistrano::Configuration.instance(:must_exist).load do
|