Skip to content

Commit

Permalink
Refactored structure.
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Laugueux committed May 14, 2014
1 parent d1fc3ed commit 8531db3
Show file tree
Hide file tree
Showing 11 changed files with 155 additions and 95 deletions.
92 changes: 61 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
```
Expand Down
5 changes: 2 additions & 3 deletions lib/capistrano/symfony.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 0 additions & 1 deletion lib/capistrano/symfony/assets.rb

This file was deleted.

1 change: 0 additions & 1 deletion lib/capistrano/symfony/console.rb

This file was deleted.

13 changes: 10 additions & 3 deletions lib/capistrano/symfony/defaults.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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))
1 change: 1 addition & 0 deletions lib/capistrano/symfony/deploy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
load File.expand_path("../../tasks/deploy.rake", __FILE__)
1 change: 1 addition & 0 deletions lib/capistrano/symfony/symfony.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
load File.expand_path("../../tasks/symfony.rake", __FILE__)
7 changes: 0 additions & 7 deletions lib/capistrano/tasks/assets.rake

This file was deleted.

18 changes: 18 additions & 0 deletions lib/capistrano/tasks/deploy.rake
Original file line number Diff line number Diff line change
@@ -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
82 changes: 62 additions & 20 deletions lib/capistrano/tasks/symfony.rake
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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"]
29 changes: 0 additions & 29 deletions lib/capistrano/tasks/symfony_console.rake

This file was deleted.

0 comments on commit 8531db3

Please sign in to comment.