From 8531db379bc9f0121f9800e8b8e2dfc258cd08dc Mon Sep 17 00:00:00 2001 From: Benjamin Laugueux Date: Wed, 30 Apr 2014 11:11:03 +0200 Subject: [PATCH] Refactored structure. --- README.md | 92 +++++++++++++++-------- lib/capistrano/symfony.rb | 5 +- lib/capistrano/symfony/assets.rb | 1 - lib/capistrano/symfony/console.rb | 1 - lib/capistrano/symfony/defaults.rb | 13 +++- lib/capistrano/symfony/deploy.rb | 1 + lib/capistrano/symfony/symfony.rb | 1 + lib/capistrano/tasks/assets.rake | 7 -- lib/capistrano/tasks/deploy.rake | 18 +++++ lib/capistrano/tasks/symfony.rake | 82 +++++++++++++++----- lib/capistrano/tasks/symfony_console.rake | 29 ------- 11 files changed, 155 insertions(+), 95 deletions(-) delete mode 100644 lib/capistrano/symfony/assets.rb delete mode 100644 lib/capistrano/symfony/console.rb create mode 100644 lib/capistrano/symfony/deploy.rb create mode 100644 lib/capistrano/symfony/symfony.rb delete mode 100644 lib/capistrano/tasks/assets.rake create mode 100644 lib/capistrano/tasks/deploy.rake delete mode 100644 lib/capistrano/tasks/symfony_console.rake diff --git a/README.md b/README.md index d5934c5..36841cc 100644 --- a/README.md +++ b/README.md @@ -69,49 +69,69 @@ set :permission_method, false # Execute set permissions set :use_set_permissions, false -set :composer_install_flags, "--no-dev --no-scripts --verbose --prefer-dist --optimize-autoloader --no-progress" - +# Symfony console path set :symfony_console_path, fetch(:app_path) + "/console" + +# Symfony console flags set :symfony_console_flags, "--no-debug" -# Assets install +# Assets install path set :assets_install_path, fetch(:web_path) +# Assets install flags +set :assets_install_flags, '--symlink' + +# Assetic dump flags +set :assetic_dump_flags, '' + fetch(:default_env).merge!(symfony_env: fetch(:symfony_env)) ``` ### Flow -capistrano-symfony hooks into the [flow][1] offered by capistrano. It adds -to that flow like so +capistrano-symfony hooks into the [flow][1] offered by capistrano. It adds to that flow like so + +* ```symfony:create_cache_dir``` +* ```symfony:set_permissions``` +* ```symfony:cache:warmup``` +* ```symfony:clear_controllers``` ``` deploy - deploy:starting - [before] - deploy:ensure_stage - deploy:set_shared_assets - deploy:check - deploy:started - deploy:updating - git:create_release - deploy:symlink:shared - deploy:create_cache_dir - deploy:set_permissions:(acl|chmod|chgrp) # optional - deploy:updated - deploy:build_bootstrap - symfony:cache:warmup - [after] - deploy:clear_controllers - deploy:assets:install - deploy:publishing - deploy:symlink:release - deploy:restart - deploy:published - deploy:finishing - deploy:cleanup - deploy:finished - deploy:log_revision +|__ deploy:starting +| |__ [before] +| | |__ deploy:ensure_stage +| | |__ deploy:set_shared_assets +| |__ deploy:check +|__ deploy:started +|__ deploy:updating +| |__ git:create_release +| |__ deploy:symlink:shared +| |__ symfony:create_cache_dir +| |__ symfony:set_permissions +|__ deploy:updated +| |__ symfony:cache:warmup +| |__ symfony:clear_controllers +|__ deploy:publishing +| |__ deploy:symlink:release +| |__ deploy:restart +|__ deploy:published +|__ deploy:finishing +| |__ deploy:cleanup +|__ deploy:finished + |__ deploy:log_revision +``` + +### Integrated common tasks + +The folowing common tasks are already integrated: +* ```symfony:assets:install``` +* ```symfony:assetic:dump``` + +So you can use them with hooks like this: +```ruby + after 'deploy:updated', 'symfony:assets:install' + after 'deploy:updated', 'symfony:assetic:dump' ``` ### Using the Symfony console @@ -125,7 +145,17 @@ project you may want to run migrations during a deploy. ```ruby namespace :deploy do task :migrate do - invoke 'symfony:command', 'doctrine:migrations:migrate', '--no-interaction' + invoke 'symfony:console', 'doctrine:migrations:migrate', '--no-interaction' + end +end +``` + +You can also apply role filter on your commands by passing a fourth parameter. + +```ruby +namespace :deploy do + task :migrate do + invoke 'symfony:console', 'doctrine:migrations:migrate', '--no-interaction', 'db' end end ``` diff --git a/lib/capistrano/symfony.rb b/lib/capistrano/symfony.rb index 2d566cd..f91dfa8 100644 --- a/lib/capistrano/symfony.rb +++ b/lib/capistrano/symfony.rb @@ -1,11 +1,10 @@ require "capistrano/file-permissions" require "capistrano/composer" require "capistrano/symfony/dsl" -require "capistrano/symfony/console" -require "capistrano/symfony/assets" +require "capistrano/symfony/symfony" # Core tasks for deploying symfony -load File.expand_path("../tasks/symfony.rake", __FILE__) +load File.expand_path("../tasks/deploy.rake", __FILE__) namespace :load do task :defaults do diff --git a/lib/capistrano/symfony/assets.rb b/lib/capistrano/symfony/assets.rb deleted file mode 100644 index bca6045..0000000 --- a/lib/capistrano/symfony/assets.rb +++ /dev/null @@ -1 +0,0 @@ -load File.expand_path("../../tasks/assets.rake", __FILE__) diff --git a/lib/capistrano/symfony/console.rb b/lib/capistrano/symfony/console.rb deleted file mode 100644 index 2f05c12..0000000 --- a/lib/capistrano/symfony/console.rb +++ /dev/null @@ -1 +0,0 @@ -load File.expand_path("../../tasks/symfony_console.rake", __FILE__) diff --git a/lib/capistrano/symfony/defaults.rb b/lib/capistrano/symfony/defaults.rb index 2785ea6..fa19ae6 100644 --- a/lib/capistrano/symfony/defaults.rb +++ b/lib/capistrano/symfony/defaults.rb @@ -37,12 +37,19 @@ # Execute set permissions set :use_set_permissions, false -set :composer_install_flags, "--no-dev --no-scripts --verbose --prefer-dist --optimize-autoloader --no-progress" - +# Symfony console path set :symfony_console_path, fetch(:app_path) + "/console" + +# Symfony console flags set :symfony_console_flags, "--no-debug" -# Assets install +# Assets install path set :assets_install_path, fetch(:web_path) +# Assets install flags +set :assets_install_flags, '--symlink' + +# Assetic dump flags +set :assetic_dump_flags, '' + fetch(:default_env).merge!(symfony_env: fetch(:symfony_env)) diff --git a/lib/capistrano/symfony/deploy.rb b/lib/capistrano/symfony/deploy.rb new file mode 100644 index 0000000..af2bfe9 --- /dev/null +++ b/lib/capistrano/symfony/deploy.rb @@ -0,0 +1 @@ +load File.expand_path("../../tasks/deploy.rake", __FILE__) diff --git a/lib/capistrano/symfony/symfony.rb b/lib/capistrano/symfony/symfony.rb new file mode 100644 index 0000000..e57d553 --- /dev/null +++ b/lib/capistrano/symfony/symfony.rb @@ -0,0 +1 @@ +load File.expand_path("../../tasks/symfony.rake", __FILE__) diff --git a/lib/capistrano/tasks/assets.rake b/lib/capistrano/tasks/assets.rake deleted file mode 100644 index fe929d7..0000000 --- a/lib/capistrano/tasks/assets.rake +++ /dev/null @@ -1,7 +0,0 @@ -namespace :deploy do - namespace :assets do - task :install do - invoke "symfony:command", "assets:install", fetch(:assets_install_path) - end - end -end diff --git a/lib/capistrano/tasks/deploy.rake b/lib/capistrano/tasks/deploy.rake new file mode 100644 index 0000000..017a804 --- /dev/null +++ b/lib/capistrano/tasks/deploy.rake @@ -0,0 +1,18 @@ +module Capistrano + class FileNotFound < StandardError + end +end + +namespace :deploy do + + task :updating do + invoke "symfony:create_cache_dir" + invoke "symfony:set_permissions" + end + + task :updated do + invoke "symfony:cache:warmup" + invoke "symfony:clear_controllers" + end + +end diff --git a/lib/capistrano/tasks/symfony.rake b/lib/capistrano/tasks/symfony.rake index 7ced9cc..5128d68 100644 --- a/lib/capistrano/tasks/symfony.rake +++ b/lib/capistrano/tasks/symfony.rake @@ -1,9 +1,55 @@ -module Capistrano - class FileNotFound < StandardError +namespace :symfony do + desc "Execute a provided symfony command" + task :console, :command, :params, :role do |t, args| + # ask only runs if argument is not provided + ask(:cmd, "cache:clear") + command = args[:command] || fetch(:cmd) + role = args[:role] || :all + params = args[:params] || '' + + on release_roles(role) do + within release_path do + execute :php, fetch(:symfony_console_path), command, params, fetch(:symfony_console_flags) + end + end + + Rake::Task[t.name].reenable + end + + task :command, :command_name, :flags do |t, args| + on roles(:all) do + warn "The task symfony:command is deprecated in favor of symfony:console" + invoke "symfony:console", args[:command_name], args[:flags] + end + end + + + namespace :cache do + desc "Run app/console cache:clear for the #{fetch(:symfony_env)} environment" + task :clear do + invoke "symfony:console", "cache:clear" + end + + desc "Run app/console cache:warmup for the #{fetch(:symfony_env)} environment" + task :warmup do + invoke "symfony:console", "cache:warmup" + end + end + + namespace :assets do + desc "Install assets" + task :install do + invoke "symfony:console", "assets:install", fetch(:assets_install_path) + ' ' + fetch(:assets_install_flags) + end + end + + namespace :assetic do + desc "Dump assets with Assetic" + task :dump do + invoke "symfony:console", "assetic:dump", fetch(:assetic_dump_flags) + end end -end -namespace :deploy do desc "Create the cache directory" task :create_cache_dir do on release_roles :all do @@ -16,6 +62,15 @@ namespace :deploy do end end + desc "Create the cache directory" + task :set_permissions do + on release_roles :all do + if fetch(:use_set_permissions) + invoke "deploy:set_permissions:#{fetch(:permission_method).to_s}" + end + end + end + desc "Clear non production controllers" task :clear_controllers do next unless any? :controllers_to_clear @@ -26,28 +81,15 @@ namespace :deploy do end end + desc "Build the bootstrap file" task :build_bootstrap do on release_roles :all do within release_path do - # TODO: does this need to be configurable? execute :php, "./vendor/sensio/distribution-bundle/Sensio/Bundle/DistributionBundle/Resources/bin/build_bootstrap.php", fetch(:app_path) end end end - task :updating do - invoke "deploy:create_cache_dir" - - if fetch(:use_set_permissions) - invoke "deploy:set_permissions:#{fetch(:permission_method).to_s}" - end - end - - task :updated do - invoke "deploy:build_bootstrap" - invoke "symfony:cache:warmup" - end - - after "deploy:updated", "deploy:clear_controllers" - after "deploy:updated", "deploy:assets:install" end + +task :symfony => ["symfony:console"] diff --git a/lib/capistrano/tasks/symfony_console.rake b/lib/capistrano/tasks/symfony_console.rake deleted file mode 100644 index f0406a7..0000000 --- a/lib/capistrano/tasks/symfony_console.rake +++ /dev/null @@ -1,29 +0,0 @@ -namespace :symfony do - desc "Exceute a provided symfony command" - task :command, :command_name do |t, args| - # ask only runs if argument is not provided - ask(:cmd, "cache:clear") - command = args[:command_name] || fetch(:cmd) - command_args = args.extras - - on roles :app do - within release_path do - execute :php, fetch(:symfony_console_path), command, *command_args, fetch(:symfony_console_flags) - end - end - end - - namespace :cache do - desc "Run app/console cache:clear for the #{fetch(:symfony_env)} environment" - task :clear do - invoke "symfony:command", "cache:clear" - end - - desc "Run app/console cache:warmup for the #{fetch(:symfony_env)} environment" - task :warmup do - invoke "symfony:command", "cache:warmup" - end - end -end - -task :symfony => ["symfony:command"]