forked from cakephp/plugins.cakephp.org
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCapfile
More file actions
428 lines (365 loc) · 15.2 KB
/
Capfile
File metadata and controls
428 lines (365 loc) · 15.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
load 'deploy' if respond_to?(:namespace) # cap2 differentiator
$config = {
'application' => 'cakepackages.com',
'repository' => 'git://github.com/cakephp/cakepackages.git',
'remoteusername' => 'cakephp',
'cake_folder' => '/apps/production/resources',
'cake_version' => 'cakephp2.2',
'plugin_dir' => false,
'servers' => {
'production' => {
'server' => 'cakephp.org',
'application' => 'cakepackages.com',
'current_dir' => 'plugins.cakephp.org',
'remote_user' => 'cakephp',
'link_core' => false,
'link_cron' => false,
'deploy_to' => '/home/cakephp/www-live/cakephp-2.2',
'releases_path' => '/home/cakephp/www-live/cakephp-2.2/.plugins.cakephp.org-cap/releases',
'shared_path' => '/home/cakephp/www-live/cakephp-2.2/.plugins.cakephp.org-cap/shared',
},
'staging' => {
'server' => 'staging.cakepackages.com',
'application' => 'staging.cakepackages.com',
'current_dir' => 'public',
'remote_user' => 'deploy',
'link_core' => false,
'link_cron' => false,
'deploy_to' => '/apps/staging/cakepackages.com/default',
'releases_path' => '/apps/staging/cakepackages.com/default/releases',
'shared_path' => '/apps/staging/cakepackages.com/default/shared',
}
},
'cron_files' => [ 'cakepackages' ]
}
# The application name. Pretty arbitrary, doesn't affect anything I think
set :application, $config["application"]
# Where is the repository held? Depends on your application
set :repository, $config["repository"]
# Deploy as this username
set :user, "deploy"
# Do NOT use sudo by default. Helps with file permissions. You can still
# manually sudo by prepending #{sudo} to run commands
set :use_sudo, false
# SCM Settings
# Use git to deploy. You can also set this to 'svn'
set :scm, :git
# Only deploy the master branch
set :branch, "master"
# Keep Git quiet
set :scm_verbose, false
## Deploy Settings
# Deploy via a remote repository cache. In git's case, it
# does a "git fetch" on the remote cache before moving it into place
set :deploy_via, :remote_cache
# Overriding my 'current' directory to public, as that's how I roll
# This can be overriden by a particular environment
set :current_dir, "public"
## Deploy Specific settings
# The folder holding all of my CakePHP core stuff,
# like plugins and the individual cores
set :cake_folder, $config["cake_folder"]
# Folder name of the specific cakephp version I want to use.
# This is a raw checkout straight from github
# Assumes you have this folder in the :cake_folder directory
set :cake_version, $config["cake_version"]
# The plugin directory (relative to :cake_folder) to be deployed
set :plugin_dir, $config["plugin_dir"]
## SSH Options
# Deploy as this username
set :ssh_options, :username => $config["remoteusername"]
# SSH Agent forwarding, sends my personal keys for usage by git when deploying.
set :ssh_options, :forward_agent => true
## Available Environments
task :production do
server $config['servers']['production']['server'], :db, :web, :god, :cron
set :application, $config['servers']['production']['application']
set :deploy_to, $config['servers']['production']['deploy_to']
set :current_dir, $config['servers']['production']['current_dir']
set :user, $config['servers']['production']['remote_user']
set :link_core, $config['servers']['production']['link_core']
set :link_cron, $config['servers']['production']['link_cron']
set :releases_path, $config['servers']['production']['releases_path']
set :shared_path, $config['servers']['production']['shared_path']
set :branch, :master
set :deploy_env, :production
end
task :staging do
role :web, $config['servers']['staging']['server']
set :application, $config['servers']['staging']['application']
set :deploy_to, $config['servers']['staging']['deploy_to']
set :current_dir, $config['servers']['staging']['current_dir']
set :user, $config['servers']['staging']['remote_user']
set :link_core, $config['servers']['staging']['link_core']
set :link_cron, $config['servers']['staging']['link_cron']
set :releases_path, $config['servers']['staging']['releases_path']
set :shared_path, $config['servers']['staging']['shared_path']
set :branch, ENV['branch'] if ENV.has_key?('branch') && ENV['branch'] =~ /[\w-]+/i
set :deploy_env, :staging
end
## Deployment tasks
namespace :deploy do
task :start do
end
task :stop do
end
desc 'Override the original :restart'
task :restart, :roles => :app do
# after 'deploy:restart', 'misc:clear_cache'
end
desc 'Override the original :migrate'
task :migrate do
run "cd #{deploy_to}/#{current_dir} && CAKE_ENV=#{deploy_env} #{deploy_to}/lib/Cake/Console/cake Migrations.migration run all"
end
desc <<-DESC
Symlinks shared configuration and directories into the latest release
Also clear persistent and model cache and sessions and symlink for usability.
DESC
task :finalize_update do
top.link.core
top.link.plugins
top.link.config
top.link.tmp
top.misc.rm_test
top.misc.submodule
top.link.cron
top.asset.rebuild
top.deploy.migrate
end
desc <<-DESC
Copies over the latest release. Necessary unless we place the cake core inside releases
For larger repositories, something different should be tried instead
DESC
task :create_symlink do
run "rm -rf #{deploy_to}/#{current_dir} && cp -rf #{latest_release} #{deploy_to}/#{current_dir}"
end
end
## Link tasks
namespace :link do
desc <<-DESC
Link the CakePHP Core
You may need to change this to a 'cp -rf' instead of 'ln -s' depending upon your shell requirements
DESC
task :core do
if link_core
run "rm -rf #{deploy_to}/lib && ln -s #{cake_folder}/#{cake_version}/lib #{deploy_to}/lib"
end
end
desc 'Link the cron file'
task :cron, :roles => :cron do
if link_cron and deploy_env == :production
cmd = []
$config['cron_files'].each do |cron_file|
cmd << "sudo chown root:root #{current_path}/Config/#{cron_file}.cron"
cmd << "sudo ln -sf #{current_path}/Config/#{cron_file}.cron /etc/cron.d/#{cron_file}"
end
run cmd.join(' && ')
end
end
desc 'Link the CakePHP Plugins for this repository'
task :plugins do
if plugin_dir
run "rm -rf #{deploy_to}/Plugin && ln -s #{cake_folder}/#{plugin_dir} #{deploy_to}/Plugin"
end
begin
run [
"cd #{current_release}",
"git clone git@github.com:cakephp/csfnavbar.git Plugin/Csfnavbar",
"cd #{current_release}/Plugin/Csfnavbar",
"git checkout -t origin/2.0",
"cp -rfp #{current_release}/Plugin/Csfnavbar/webroot/img/main-link.png #{current_release}/webroot/cache_css"
].join(' && ')
rescue
puts "**** Could not clone CSF navbar, likely a permissions issue"
end
begin
run [
"cd #{current_release}",
"git clone git@github.com:cakephp/theme-packages.git View/Themed/Csf",
"mkdir #{current_release}/webroot/theme",
"ln -s #{current_release}/View/Themed/Csf/webroot #{current_release}/webroot/theme/Csf"
].join(' && ')
rescue
puts "**** Could not clone CSF theme, likely a permissions issue"
end
end
desc <<-DESC
Link the configuration files
May fail if you are not using the asset_compress plugin
DESC
task :config do
run [
"if [ ! -d '#{shared_path}/Config' ]; then " +
"mkdir -p #{shared_path}/Config && chmod -R 755 #{shared_path}/Config;" +
'fi',
"rm -rf #{current_release}/Config/bootstrap/environments/production.php",
"ln -s #{shared_path}/Config/bootstrap/environments/production.php #{current_release}/Config/bootstrap/environments/production.php",
"rm -rf #{current_release}/Config/database.php",
"ln -s #{shared_path}/Config/database.php #{current_release}/Config/database.php",
"if [ ! -d '#{shared_path}/webroot/cache_css' ]; then " +
"mkdir -p #{shared_path}/webroot/cache_css && chmod -R 755 #{shared_path}/webroot/cache_css;" +
'fi',
"if [ ! -d '#{shared_path}/webroot/cache_js' ]; then " +
"mkdir -p #{shared_path}/webroot/cache_js && chmod -R 755 #{shared_path}/webroot/cache_js;" +
'fi',
"if [ ! -d '#{shared_path}/webroot/uploads' ]; then " +
"mkdir -p #{shared_path}/webroot/uploads && chmod -R 755 #{shared_path}/webroot/uploads;" +
'fi',
"if [ ! -d '#{shared_path}/webroot/files' ]; then " +
"mkdir -p #{shared_path}/webroot/files && chmod -R 755 #{shared_path}/webroot/files;" +
'fi',
"find #{current_release}/webroot/cache_css -name '*.css' -exec rm -rf '{}' +",
"ln -s #{shared_path}/webroot/cache_css #{current_release}/webroot/cache_css",
"rm -rf #{current_release}/webroot/cache_js",
"ln -s #{shared_path}/webroot/cache_js #{current_release}/webroot/cache_js",
"rm -rf #{current_release}/webroot/uploads",
"ln -s #{shared_path}/webroot/uploads #{current_release}/webroot/uploads",
"rm -rf #{current_release}/webroot/files",
"ln -s #{shared_path}/webroot/files #{current_release}/webroot/files",
].join(' && ')
end
desc 'Link the temporary directory'
task :tmp do
run [
"rm -rf #{current_release}/tmp",
"if [ ! -d '#{shared_path}/tmp' ]; then " +
"mkdir -p #{shared_path}/tmp && " +
"mkdir -p #{shared_path}/tmp/cache/data && " +
"mkdir -p #{shared_path}/tmp/cache/debug_kit && " +
"mkdir -p #{shared_path}/tmp/cache/models && " +
"mkdir -p #{shared_path}/tmp/cache/persistent && " +
"mkdir -p #{shared_path}/tmp/cache/views && " +
"mkdir -p #{shared_path}/tmp/sessions && " +
"mkdir -p #{shared_path}/tmp/logs && " +
"mkdir -p #{shared_path}/tmp/tests && " +
"chmod -R 777 #{shared_path}/tmp;" +
'fi',
"ln -s #{shared_path}/tmp #{current_release}/tmp",
].join(' && ')
end
end
## Miscellaneous tasks
namespace :misc do
desc 'Blow up all the cache files CakePHP uses, ensuring a clean restart.'
task :clear_cache do
# Remove absolutely everything from TMP
run "rm -rf #{shared_path}/tmp/*"
# Create TMP folders
run [
"rm -rf #{shared_path}/tmp/*",
"rm -rf #{shared_path}/webroot/cache_css/*",
"rm -rf #{shared_path}/webroot/cache_js/*",
"mkdir -p #{shared_path}/tmp/cache/data",
"mkdir -p #{shared_path}/tmp/cache/debug_kit",
"mkdir -p #{shared_path}/tmp/cache/models",
"mkdir -p #{shared_path}/tmp/cache/persistent",
"mkdir -p #{shared_path}/tmp/cache/views",
"mkdir -p #{shared_path}/tmp/sessions",
"mkdir -p #{shared_path}/tmp/logs",
"mkdir -p #{shared_path}/tmp/tests",
"chmod -R 777 #{shared_path}/tmp",
].join(' && ')
end
desc 'Startup a new deployment'
task :startup do
# symlink the cake core folder to where we need it
after 'misc:startup', 'link:core', 'link:plugins', 'misc:clear_cache'
run [
# Setup shared folders
"mkdir -p #{shared_path}/tmp/cache/models",
"mkdir -p #{shared_path}/tmp/cache/persistent",
"mkdir -p #{shared_path}/tmp/cache/views",
"mkdir -p #{shared_path}/tmp/sessions",
"mkdir -p #{shared_path}/tmp/logs",
"mkdir -p #{shared_path}/tmp/tests",
"mkdir -p #{shared_path}/webroot/files",
"mkdir -p #{shared_path}/webroot/uploads",
"mkdir -p #{shared_path}/webroot/cache_css",
"mkdir -p #{shared_path}/webroot/cache_js",
# Make the TMP and Uploads folder writeable
"chmod -R 777 #{shared_path}/tmp",
"chmod -R 644 #{shared_path}/webroot/cache_css #{shared_path}/webroot/cache_js",
"chmod -R 755 #{shared_path}/tmp #{shared_path}/webroot/uploads #{shared_path}/webroot/files"
].join(' && ')
end
desc 'Initialize the submodules and update them'
task :submodule do
run "cd #{current_release} && git submodule init && git submodule update"
end
desc 'Initialize the submodules and update them'
task :rm_test do
run "cd #{current_release} && rm -rf webroot/test.php" if deploy_env == :production
end
desc 'Tail the log files'
task :tail do
run "tail -f #{deploy_to}/logs/*.log"
end
end
## Tasks involving assets
namespace :asset do
desc 'Clears assets'
task :clear do
run "cd #{current_release} && CAKE_ENV=#{deploy_env} #{deploy_to}/lib/Cake/Console/cake -app #{current_release} AssetCompress.asset_compress clear"
end
desc 'Builds all assets'
task :build do
run "cd #{current_release} && CAKE_ENV=#{deploy_env} #{deploy_to}/lib/Cake/Console/cake -app #{current_release} AssetCompress.asset_compress build"
end
desc 'Builds ini assets'
task :build_ini do
run "cd #{current_release} && CAKE_ENV=#{deploy_env} #{deploy_to}/lib/Cake/Console/cake -app #{current_release} AssetCompress.asset_compress build_ini"
end
desc 'Rebuilds assets'
task :rebuild do
run "cd #{current_release} && CAKE_ENV=#{deploy_env} #{deploy_to}/lib/Cake/Console/cake -app #{current_release} AssetCompress.asset_compress clear"
run "cd #{current_release} && CAKE_ENV=#{deploy_env} #{deploy_to}/lib/Cake/Console/cake -app #{current_release} AssetCompress.asset_compress build"
end
end
## Tasks involving migrations
namespace :migrate do
desc 'Run CakeDC Migrations'
task :all do
run "cd #{current_release} && CAKE_ENV=#{deploy_env} #{deploy_to}/lib/Cake/Console/cake Migrations.migration run all -app #{current_release}"
end
desc 'Gets the status of CakeDC Migrations'
task :status do
run "cd #{current_release} && CAKE_ENV=#{deploy_env} #{deploy_to}/lib/Cake/Console/cake Migrations.migration status -app #{current_release}"
end
end
## Tasks involving migrations
namespace :resque do
desc 'Start a resque worker'
task :start do
run "cd #{deploy_to}/#{current_dir} && CAKE_ENV=#{deploy_env} #{deploy_to}/lib/Cake/Console/cake Resque.resque start --queue=default,email"
end
desc 'Stop a resque worker'
task :stop do
run "cd #{deploy_to}/#{current_dir} && CAKE_ENV=#{deploy_env} #{deploy_to}/lib/Cake/Console/cake Resque.resque stop"
end
desc 'Get stats on a resque worker'
task :stats do
run "cd #{deploy_to}/#{current_dir} && CAKE_ENV=#{deploy_env} #{deploy_to}/lib/Cake/Console/cake Resque.resque stats"
end
end
## Tasks involving God+CakeDJJob
namespace :god do
task :stop, :roles => :god do
run "#{sudo} service god stop"
end
task :start, :roles => :god do
run "#{sudo} service god start"
end
task :status, :roles => :god do
run "#{sudo} service god status"
end
task :restart, :roles => :god do
run [
"#{sudo} service god stop",
"#{sudo} rm /etc/god/conf.d/workers.god",
"#{sudo} rm /etc/god/conf.d/cakephp_god.rb",
"#{sudo} ln -s #{current_release}/Config/workers.god /etc/god/conf.d/workers.god",
"#{sudo} ln -s #{current_release}/Config/cakephp_god.rb /etc/god/conf.d/cakephp_god.rb",
"#{sudo} service god start"
].join(' && ')
end
end