capifony 2.1.7 → 2.1.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,13 @@
1
+ namespace :deploy do
2
+ namespace :web do
3
+ desc "Use symfony 1.4 task to disable the application"
4
+ task :disable, :roles => :web, :except => { :no_release => true } do
5
+ symfony.project.disable
6
+ end
7
+
8
+ desc "Use symfony 1.4 task to enable the application"
9
+ task :enable, :roles => :web, :except => { :no_release => true } do
10
+ symfony.project.enable
11
+ end
12
+ end
13
+ end
@@ -1,4 +1,15 @@
1
1
  load Gem.find_files('capifony.rb').last.to_s
2
+ load_paths.push File.expand_path('../', __FILE__)
3
+
4
+ load 'symfony2/output'
5
+ load 'symfony2/database'
6
+ load 'symfony2/deploy'
7
+ load 'symfony2/doctrine'
8
+ load 'symfony2/propel'
9
+ load 'symfony2/symfony'
10
+ load 'symfony2/web'
11
+
12
+ require 'yaml'
2
13
 
3
14
  # Symfony application path
4
15
  set :app_path, "app"
@@ -69,534 +80,6 @@ def guess_symfony_version
69
80
  capture("cd #{latest_release} && #{php_bin} #{symfony_console} --version |cut -d \" \" -f 3")
70
81
  end
71
82
 
72
- namespace :database do
73
- namespace :dump do
74
- desc "Dumps remote database"
75
- task :remote do
76
- filename = "#{application}.remote_dump.#{Time.now.to_i}.sql.gz"
77
- file = "/tmp/#{filename}"
78
- sqlfile = "#{application}_dump.sql"
79
- config = ""
80
-
81
- run "cat #{current_path}/app/config/parameters.yml" do |ch, st, data|
82
- config = load_database_config data, symfony_env_prod
83
- end
84
-
85
- case config['database_driver']
86
- when "pdo_mysql", "mysql"
87
- run "mysqldump -u#{config['database_user']} --password='#{config['database_password']}' #{config['database_name']} | gzip -c > #{file}" do |ch, stream, data|
88
- puts data
89
- end
90
- when "pdo_pgsql", "pgsql"
91
- run "pg_dump -U #{config['database_user']} #{config['database_name']} | gzip -c > #{file}" do |ch, stream, data|
92
- puts data
93
- end
94
- end
95
-
96
- require "fileutils"
97
- FileUtils.mkdir_p("backups")
98
- get file, "backups/#{filename}"
99
- begin
100
- FileUtils.ln_sf(filename, "backups/#{application}.remote_dump.latest.sql.gz")
101
- rescue NotImplementedError # hack for windows which doesnt support symlinks
102
- FileUtils.cp_r("backups/#{filename}", "backups/#{application}.remote_dump.latest.sql.gz")
103
- end
104
- run "rm #{file}"
105
- end
106
-
107
- desc "Dumps local database"
108
- task :local do
109
- filename = "#{application}.local_dump.#{Time.now.to_i}.sql.gz"
110
- tmpfile = "backups/#{application}_dump_tmp.sql"
111
- file = "backups/#{filename}"
112
- config = load_database_config IO.read('app/config/parameters.yml'), symfony_env_local
113
- sqlfile = "#{application}_dump.sql"
114
-
115
- require "fileutils"
116
- FileUtils::mkdir_p("backups")
117
- case config['database_driver']
118
- when "pdo_mysql", "mysql"
119
- `mysqldump -u#{config['database_user']} --password=\"#{config['database_password']}\" #{config['database_name']} > #{tmpfile}`
120
- when "pdo_pgsql", "pgsql"
121
- `pg_dump -U #{config['database_user']} #{config['database_name']} > #{tmpfile}`
122
- end
123
-
124
- File.open(tmpfile, "r+") do |f|
125
- gz = Zlib::GzipWriter.open(file)
126
- while (line = f.gets)
127
- gz << line
128
- end
129
- gz.flush
130
- gz.close
131
- end
132
-
133
- begin
134
- FileUtils.ln_sf(filename, "backups/#{application}.local_dump.latest.sql.gz")
135
- rescue NotImplementedError # hack for windows which doesnt support symlinks
136
- FileUtils.cp_r("backups/#{filename}", "backups/#{application}.local_dump.latest.sql.gz")
137
- end
138
- FileUtils.rm(tmpfile)
139
- end
140
- end
141
-
142
- namespace :move do
143
- desc "Dumps remote database, downloads it to local, and populates here"
144
- task :to_local do
145
- filename = "#{application}.remote_dump.latest.sql.gz"
146
- config = load_database_config IO.read('app/config/parameters.yml'), symfony_env_local
147
- sqlfile = "#{application}_dump.sql"
148
-
149
- database.dump.remote
150
-
151
- require "fileutils"
152
- f = File.new("backups/#{sqlfile}", "a+")
153
- require "zlib"
154
- gz = Zlib::GzipReader.new(File.open("backups/#{filename}", "r"))
155
- f << gz.read
156
- f.close
157
-
158
- case config['database_driver']
159
- when "pdo_mysql", "mysql"
160
- `mysql -u#{config['database_user']} --password=\"#{config['database_password']}\" #{config['database_name']} < backups/#{sqlfile}`
161
- when "pdo_pgsql", "pgsql"
162
- `psql -U #{config['database_user']} --password=\"#{config['database_password']}\" #{config['database_name']} < backups/#{sqlfile}`
163
- end
164
- FileUtils.rm("backups/#{sqlfile}")
165
- end
166
-
167
- desc "Dumps local database, loads it to remote, and populates there"
168
- task :to_remote do
169
- filename = "#{application}.local_dump.latest.sql.gz"
170
- file = "backups/#{filename}"
171
- sqlfile = "#{application}_dump.sql"
172
- config = ""
173
-
174
- database.dump.local
175
-
176
- upload(file, "/tmp/#{filename}", :via => :scp)
177
- run "gunzip -c /tmp/#{filename} > /tmp/#{sqlfile}"
178
-
179
- run "cat #{shared_path}/config/databases.yml" do |ch, st, data|
180
- config = load_database_config data, symfony_env_prod
181
- end
182
-
183
- case config['database_driver']
184
- when "pdo_mysql", "mysql"
185
- run "mysql -u#{config['database_user']} --password='#{config['database_password']}' #{config['database_name']} < /tmp/#{sqlfile}" do |ch, stream, data|
186
- puts data
187
- end
188
- when "pdo_pgsql", "pgsql"
189
- run "psql -U #{config['database_user']} --password='#{config['database_password']}' #{config['database_name']} < /tmp/#{sqlfile}" do |ch, stream, data|
190
- puts data
191
- end
192
- end
193
-
194
- run "rm /tmp/#{filename}"
195
- run "rm /tmp/#{sqlfile}"
196
- end
197
- end
198
- end
199
-
200
- namespace :deploy do
201
- desc "Symlinks static directories and static files that need to remain between deployments"
202
- task :share_childs do
203
- if shared_children
204
- shared_children.each do |link|
205
- run "mkdir -p #{shared_path}/#{link}"
206
- run "if [ -d #{release_path}/#{link} ] ; then rm -rf #{release_path}/#{link}; fi"
207
- run "ln -nfs #{shared_path}/#{link} #{release_path}/#{link}"
208
- end
209
- end
210
- if shared_files
211
- shared_files.each do |link|
212
- link_dir = File.dirname("#{shared_path}/#{link}")
213
- run "mkdir -p #{link_dir}"
214
- run "touch #{shared_path}/#{link}"
215
- run "ln -nfs #{shared_path}/#{link} #{release_path}/#{link}"
216
- end
217
- end
218
- end
219
-
220
- desc "Updates latest release source path"
221
- task :finalize_update, :except => { :no_release => true } do
222
- run "chmod -R g+w #{latest_release}" if fetch(:group_writable, true)
223
- run "if [ -d #{latest_release}/#{cache_path} ] ; then rm -rf #{latest_release}/#{cache_path}; fi"
224
- run "mkdir -p #{latest_release}/#{cache_path} && chmod -R 0777 #{latest_release}/#{cache_path}"
225
- run "chmod -R g+w #{latest_release}/#{cache_path}"
226
-
227
- share_childs
228
-
229
- if fetch(:normalize_asset_timestamps, true)
230
- stamp = Time.now.utc.strftime("%Y%m%d%H%M.%S")
231
- asset_paths = asset_children.map { |p| "#{latest_release}/#{p}" }.join(" ")
232
-
233
- if asset_paths.chomp.empty?
234
- puts " No asset paths found, skipped"
235
- else
236
- run "find #{asset_paths} -exec touch -t #{stamp} {} ';'; true", :env => { "TZ" => "UTC" }
237
- end
238
- end
239
- end
240
-
241
- desc "Deploys the application and starts it"
242
- task :cold do
243
- update
244
- start
245
- end
246
-
247
- desc "Deploys the application and runs the test suite"
248
- task :testall do
249
- update_code
250
- symlink
251
- run "cd #{latest_release} && phpunit -c #{app_path} src"
252
- end
253
-
254
- desc "Runs the Symfony2 migrations"
255
- task :migrate do
256
- if model_manager == "doctrine"
257
- symfony.doctrine.migrations.migrate
258
- else
259
- if model_manager == "propel"
260
- puts " Propel doesn't have built-in migration for now"
261
- end
262
- end
263
- end
264
-
265
- namespace :web do
266
- desc <<-DESC
267
- Present a maintenance page to visitors. Disables your application's web \
268
- interface by writing a "#{maintenance_basename}.html" file to each web server. The \
269
- servers must be configured to detect the presence of this file, and if \
270
- it is present, always display it instead of performing the request.
271
-
272
- By default, the maintenance page will just say the site is down for \
273
- "maintenance", and will be back "shortly", but you can customize the \
274
- page by specifying the REASON and UNTIL environment variables:
275
-
276
- $ cap deploy:web:disable \\
277
- REASON="hardware upgrade" \\
278
- UNTIL="12pm Central Time"
279
-
280
- You can use a different template for the maintenance page by setting the \
281
- :maintenance_template_path variable in your deploy.rb file. The template file \
282
- should either be a plaintext or an erb file.
283
-
284
- Further customization will require that you write your own task.
285
- DESC
286
- task :disable, :roles => :web, :except => { :no_release => true } do
287
- require 'erb'
288
- on_rollback { run "rm #{latest_release}/#{web_path}/#{maintenance_basename}.html" }
289
-
290
- warn <<-EOHTACCESS
291
-
292
- # Please add something like this to your site's Apache htaccess to redirect users to the maintenance page.
293
- # More Info: http://www.shiftcommathree.com/articles/make-your-rails-maintenance-page-respond-with-a-503
294
-
295
- ErrorDocument 503 /#{maintenance_basename}.html
296
- RewriteEngine On
297
- RewriteCond %{REQUEST_URI} !\.(css|gif|jpg|png)$
298
- RewriteCond %{DOCUMENT_ROOT}/#{maintenance_basename}.html -f
299
- RewriteCond %{SCRIPT_FILENAME} !#{maintenance_basename}.html
300
- RewriteRule ^.*$ - [redirect=503,last]
301
-
302
- # Or if you are using Nginx add this to your server config:
303
-
304
- if (-f $document_root/maintenance.html) {
305
- return 503;
306
- }
307
- error_page 503 @maintenance;
308
- location @maintenance {
309
- rewrite ^(.*)$ /maintenance.html last;
310
- break;
311
- }
312
- EOHTACCESS
313
-
314
- reason = ENV['REASON']
315
- deadline = ENV['UNTIL']
316
- template = File.read(maintenance_template_path)
317
- result = ERB.new(template).result(binding)
318
-
319
- put result, "#{latest_release}/#{web_path}/#{maintenance_basename}.html", :mode => 0644
320
- end
321
-
322
- desc <<-DESC
323
- Makes the application web-accessible again. Removes the \
324
- "#{maintenance_basename}.html" page generated by deploy:web:disable, which (if your \
325
- web servers are configured correctly) will make your application \
326
- web-accessible again.
327
- DESC
328
- task :enable, :roles => :web, :except => { :no_release => true } do
329
- run "rm #{latest_release}/#{web_path}/#{maintenance_basename}.html"
330
- end
331
- end
332
- end
333
-
334
- namespace :symfony do
335
- desc "Runs custom symfony command"
336
- task :default do
337
- prompt_with_default(:task_arguments, "cache:clear")
338
-
339
- stream "cd #{latest_release} && #{php_bin} #{symfony_console} #{task_arguments} --env=#{symfony_env_prod}"
340
- end
341
-
342
- namespace :assets do
343
- desc "Installs bundle's assets"
344
- task :install do
345
- run "cd #{latest_release} && #{php_bin} #{symfony_console} assets:install #{web_path} --env=#{symfony_env_prod}"
346
- end
347
- end
348
-
349
- namespace :assetic do
350
- desc "Dumps all assets to the filesystem"
351
- task :dump do
352
- run "cd #{latest_release} && #{php_bin} #{symfony_console} assetic:dump --env=#{symfony_env_prod} --no-debug"
353
- end
354
- end
355
-
356
- namespace :vendors do
357
- desc "Runs the bin/vendors script to install the vendors (fast if already installed)"
358
- task :install do
359
- run "cd #{latest_release} && #{php_bin} #{symfony_vendors} install"
360
- end
361
-
362
- desc "Runs the bin/vendors script to reinstall the vendors"
363
- task :reinstall do
364
- run "cd #{latest_release} && #{php_bin} #{symfony_vendors} install --reinstall"
365
- end
366
-
367
- desc "Runs the bin/vendors script to upgrade the vendors"
368
- task :upgrade do
369
- run "cd #{latest_release} && #{php_bin} #{symfony_vendors} update"
370
- end
371
- end
372
-
373
- namespace :bootstrap do
374
- desc "Runs the bin/build_bootstrap script"
375
- task :build do
376
- run "cd #{latest_release} && test -f #{build_bootstrap} && #{php_bin} #{build_bootstrap} || echo '#{build_bootstrap} not found, skipped'"
377
- end
378
- end
379
-
380
- namespace :composer do
381
- desc "Gets composer and installs it"
382
- task :get do
383
- run "cd #{latest_release} && curl -s http://getcomposer.org/installer | #{php_bin}"
384
- end
385
-
386
- desc "Runs composer to install vendors from composer.lock file"
387
- task :install do
388
- if !File.exist?("#{latest_release}/composer.phar")
389
- symfony.composer.get
390
- end
391
-
392
- run "cd #{latest_release} && #{php_bin} composer.phar install"
393
- end
394
-
395
- desc "Runs composer to update vendors, and composer.lock file"
396
- task :update do
397
- if !File.exist?("#{latest_release}/composer.phar")
398
- symfony.composer.get
399
- end
400
-
401
- run "cd #{latest_release} && #{php_bin} composer.phar update"
402
- end
403
- end
404
-
405
- namespace :cache do
406
- desc "Clears project cache"
407
- task :clear do
408
- run "cd #{latest_release} && #{php_bin} #{symfony_console} cache:clear --env=#{symfony_env_prod}"
409
- run "chmod -R g+w #{latest_release}/#{cache_path}"
410
- end
411
-
412
- desc "Warms up an empty cache"
413
- task :warmup do
414
- run "cd #{latest_release} && #{php_bin} #{symfony_console} cache:warmup --env=#{symfony_env_prod}"
415
- run "chmod -R g+w #{latest_release}/#{cache_path}"
416
- end
417
- end
418
-
419
- namespace :doctrine do
420
- namespace :cache do
421
- desc "Clears all metadata cache for a entity manager"
422
- task :clear_metadata do
423
- run "cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:cache:clear-metadata --env=#{symfony_env_prod}"
424
- end
425
-
426
- desc "Clears all query cache for a entity manager"
427
- task :clear_query do
428
- run "cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:cache:clear-query --env=#{symfony_env_prod}"
429
- end
430
-
431
- desc "Clears result cache for a entity manager"
432
- task :clear_result do
433
- run "cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:cache:clear-result --env=#{symfony_env_prod}"
434
- end
435
- end
436
-
437
- namespace :database do
438
- desc "Creates the configured databases"
439
- task :create do
440
- run "cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:database:create --env=#{symfony_env_prod}"
441
- end
442
-
443
- desc "Drops the configured databases"
444
- task :drop do
445
- run "cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:database:drop --env=#{symfony_env_prod}"
446
- end
447
- end
448
-
449
- namespace :generate do
450
- desc "Generates proxy classes for entity classes"
451
- task :hydrators do
452
- run "cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:generate:proxies --env=#{symfony_env_prod}"
453
- end
454
-
455
- desc "Generates repository classes from your mapping information"
456
- task :hydrators do
457
- run "cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:generate:repositories --env=#{symfony_env_prod}"
458
- end
459
- end
460
-
461
- namespace :schema do
462
- desc "Processes the schema and either create it directly on EntityManager Storage Connection or generate the SQL output"
463
- task :create do
464
- run "cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:schema:create --env=#{symfony_env_prod}"
465
- end
466
-
467
- desc "Drops the complete database schema of EntityManager Storage Connection or generate the corresponding SQL output"
468
- task :drop do
469
- run "cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:schema:drop --env=#{symfony_env_prod}"
470
- end
471
- end
472
-
473
- namespace :migrations do
474
- desc "Executes a migration to a specified version or the latest available version"
475
- task :migrate do
476
- currentVersion = nil
477
- run "cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:migrations:status --env=#{symfony_env_prod}" do |ch, stream, out|
478
- if stream == :out and out =~ /Current Version:[^$]+\(([\w]+)\)/
479
- currentVersion = Regexp.last_match(1)
480
- end
481
- if stream == :out and out =~ /Current Version:\s*0\s*$/
482
- currentVersion = 0
483
- end
484
- end
485
-
486
- if currentVersion == nil
487
- raise "Could not find current database migration version"
488
- end
489
- puts " Current database version: #{currentVersion}"
490
-
491
- on_rollback {
492
- if !interactive_mode || Capistrano::CLI.ui.agree("Do you really want to migrate #{symfony_env_prod}'s database back to version #{currentVersion}? (y/N)")
493
- run "cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:migrations:migrate #{currentVersion} --env=#{symfony_env_prod} --no-interaction"
494
- end
495
- }
496
-
497
- if !interactive_mode || Capistrano::CLI.ui.agree("Do you really want to migrate #{symfony_env_prod}'s database? (y/N)")
498
- run "cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:migrations:migrate --env=#{symfony_env_prod} --no-interaction"
499
- end
500
- end
501
-
502
- desc "Views the status of a set of migrations"
503
- task :status do
504
- run "cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:migrations:status --env=#{symfony_env_prod}"
505
- end
506
- end
507
-
508
- namespace :mongodb do
509
- namespace :generate do
510
- desc "Generates hydrator classes for document classes"
511
- task :hydrators do
512
- run "cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:mongodb:generate:hydrators --env=#{symfony_env_prod}"
513
- end
514
-
515
- desc "Generates proxy classes for document classes"
516
- task :hydrators do
517
- run "cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:mongodb:generate:proxies --env=#{symfony_env_prod}"
518
- end
519
-
520
- desc "Generates repository classes for document classes"
521
- task :hydrators do
522
- run "cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:mongodb:generate:repositories --env=#{symfony_env_prod}"
523
- end
524
- end
525
-
526
- namespace :schema do
527
- desc "Allows you to create databases, collections and indexes for your documents"
528
- task :create do
529
- run "cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:mongodb:schema:create --env=#{symfony_env_prod}"
530
- end
531
-
532
- desc "Allows you to drop databases, collections and indexes for your documents"
533
- task :drop do
534
- run "cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:mongodb:schema:drop --env=#{symfony_env_prod}"
535
- end
536
- end
537
- end
538
- end
539
-
540
- namespace :init do
541
- desc "Mounts ACL tables in the database"
542
- task :acl do
543
- run "cd #{latest_release} && #{php_bin} #{symfony_console} init:acl --env=#{symfony_env_prod}"
544
- end
545
- end
546
-
547
- namespace :propel do
548
- namespace :database do
549
- desc "Creates the configured databases"
550
- task :create do
551
- run "cd #{latest_release} && #{php_bin} #{symfony_console} propel:database:create --env=#{symfony_env_prod}"
552
- end
553
-
554
- desc "Drops the configured databases"
555
- task :drop do
556
- run "cd #{latest_release} && #{php_bin} #{symfony_console} propel:database:drop --env=#{symfony_env_prod}"
557
- end
558
- end
559
-
560
- namespace :build do
561
- desc "Builds the Model classes"
562
- task :model do
563
- command = "propel:model:build"
564
- if /2\.0\.[0-9]+.*/ =~ symfony_version
565
- command = "propel:build-model"
566
- end
567
-
568
- run "cd #{latest_release} && #{php_bin} #{symfony_console} #{command} --env=#{symfony_env_prod}"
569
- end
570
-
571
- desc "Builds SQL statements"
572
- task :sql do
573
- command = "propel:sql:build"
574
- if /2\.0\.[0-9]+.*/ =~ symfony_version
575
- command = "propel:build-sql"
576
- end
577
-
578
- run "cd #{latest_release} && #{php_bin} #{symfony_console} #{command} --env=#{symfony_env_prod}"
579
- end
580
-
581
- desc "Builds the Model classes, SQL statements and insert SQL"
582
- task :all_and_load do
583
- run "cd #{latest_release} && #{php_bin} #{symfony_console} propel:build --insert-sql --env=#{symfony_env_prod}"
584
- end
585
-
586
- desc "Generates ACLs models"
587
- task :acl do
588
- run "cd #{latest_release} && #{php_bin} #{symfony_console} propel:acl:init --env=#{symfony_env_prod}"
589
- end
590
-
591
- desc "Inserts propel ACL tables"
592
- task :acl_load do
593
- run "cd #{latest_release} && #{php_bin} #{symfony_console} propel:acl:init --env=#{symfony_env_prod} --force"
594
- end
595
- end
596
- end
597
- end
598
-
599
- # After finalizing update:
600
83
  after "deploy:finalize_update" do
601
84
  if use_composer
602
85
  if update_vendors
@@ -633,3 +116,18 @@ after "deploy:finalize_update" do
633
116
  symfony.assetic.dump # 4. Dump assetic assets
634
117
  end
635
118
  end
119
+
120
+ before "deploy:update_code" do
121
+ msg = "--> Updating code base with #{deploy_via} strategy"
122
+
123
+ if logger.level == Logger::IMPORTANT
124
+ pretty_errors
125
+ puts msg
126
+ else
127
+ puts msg.green
128
+ end
129
+ end
130
+
131
+ after "deploy:create_symlink" do
132
+ puts "--> Successfully deployed!".green
133
+ end