Skip to content

Commit 61deda4

Browse files
committed
Initial commit
0 parents  commit 61deda4

14 files changed

+387
-0
lines changed

.gitignore

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
*.gem
2+
*.rbc
3+
.bundle
4+
.config
5+
.yardoc
6+
Gemfile.lock
7+
InstalledFiles
8+
_yardoc
9+
coverage
10+
doc/
11+
lib/bundler/man
12+
pkg
13+
rdoc
14+
spec/reports
15+
test/tmp
16+
test/version_tmp
17+
tmp

LICENCE.txt

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Copyright (c) 2014 Peter Mitchell
2+
3+
MIT License
4+
5+
Permission is hereby granted, free of charge, to any person obtaining
6+
a copy of this software and associated documentation files (the
7+
"Software"), to deal in the Software without restriction, including
8+
without limitation the rights to use, copy, modify, merge, publish,
9+
distribute, sublicense, and/or sell copies of the Software, and to
10+
permit persons to whom the Software is furnished to do so, subject to
11+
the following conditions:
12+
13+
The above copyright notice and this permission notice shall be
14+
included in all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

+141
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
# Capistrano::Symfony
2+
3+
Symfony 2 (standard edition) specific tasks for Capistrano v3
4+
(inspired by [capifony][2])
5+
6+
It leverages the following capistrano tasks to deploy a Symfony app
7+
8+
* https://github.com/capistrano/composer
9+
* https://github.com/capistrano/file-permissions
10+
11+
## Installation
12+
13+
```
14+
# Gemfile
15+
gem 'capistrano', '~> 3.1'
16+
gem 'capistrano-symfony', '~> 0.1'
17+
```
18+
19+
## Usage
20+
21+
Require capistrano-symfony in your cap file
22+
23+
```
24+
# Capfile
25+
require 'capistrano/symfony'
26+
```
27+
28+
### Settings
29+
30+
capistrano-symfony exposes the following settings (displayed with defaults):
31+
32+
```ruby
33+
# Symfony environment
34+
set :symfony_env_prod, "prod"
35+
36+
# Symfony application path
37+
set :app_path, "app"
38+
39+
# Symfony web path
40+
set :web_path, "web"
41+
42+
# Symfony log path
43+
set :log_path, fetch(:app_path) + "/logs"
44+
45+
# Symfony cache path
46+
set :cache_path, fetch(:app_path) + "/cache"
47+
48+
# Symfony config file path
49+
set :app_config_path, fetch(:app_path) + "/config"
50+
51+
# Controllers to clear
52+
set :controllers_to_clear, ["app_*.php"]
53+
54+
# Files that need to remain the same between deploys
55+
set :linked_files, []
56+
57+
# Dirs that need to remain the same between deploys (shared dirs)
58+
set :linked_dirs, [fetch(:log_path), fetch(:web_path) + "/uploads"]
59+
60+
# Dirs that need to be writable by the HTTP Server (i.e. cache, log dirs)
61+
set :file_permissions_paths, [fetch(:log_path), fetch(:cache_path)]
62+
63+
# Name used by the Web Server (i.e. www-data for Apache)
64+
set :webserver_user, "www-data"
65+
66+
# Method used to set permissions (:chmod, :acl, or :chown)
67+
set :permission_method, false
68+
69+
# Execute set permissions
70+
set :use_set_permissions, false
71+
72+
set :composer_install_flags, "--no-dev --no-scripts --verbose --prefer-dist --optimize-autoloader --no-progress"
73+
74+
set :symfony_console_path, fetch(:app_path) + "/console"
75+
set :symfony_console_flags, "--no-debug"
76+
77+
# Assets install
78+
set :assets_install_path, fetch(:web_path)
79+
```
80+
81+
### Flow
82+
83+
capistrano-symfony hooks into the [flow][1] offered by capistrano. It adds
84+
to that flow like so
85+
86+
```
87+
deploy
88+
deploy:starting
89+
[before]
90+
deploy:ensure_stage
91+
deploy:set_shared_assets
92+
deploy:check
93+
deploy:started
94+
deploy:updating
95+
git:create_release
96+
deploy:symlink:shared
97+
deploy:create_cache_dir
98+
deploy:set_permissions:(acl|chmod|chgrp) # optional
99+
deploy:updated
100+
deploy:build_bootstrap
101+
symfony:cache:warmup
102+
[after]
103+
deploy:clear_controllers
104+
deploy:assets:install
105+
deploy:publishing
106+
deploy:symlink:release
107+
deploy:restart
108+
deploy:published
109+
deploy:finishing
110+
deploy:cleanup
111+
deploy:finished
112+
deploy:log_revision
113+
```
114+
115+
### Using the Symfony console
116+
117+
A task wrapping the symfony console is provided, making it easy to create tasks
118+
that call console methods.
119+
120+
For example if you have installed the [DoctrineMigrationsBundle][3] in your
121+
project you may want to run migrations during a deploy.
122+
123+
```ruby
124+
namespace :deploy do
125+
task :migrate do
126+
invoke 'symfony:command', 'doctrine:migrations:migrate', '--no-interaction'
127+
end
128+
end
129+
```
130+
131+
[1]: http://capistranorb.com/documentation/getting-started/flow/
132+
[2]: http://capifony.org/
133+
[3]: http://symfony.com/doc/current/bundles/DoctrineMigrationsBundle/index.html
134+
135+
## Contributing
136+
137+
1. Fork it
138+
2. Create your feature branch (`git checkout -b my-new-feature`)
139+
3. Commit your changes (`git commit -am 'Add some feature'`)
140+
4. Push to the branch (`git push origin my-new-feature`)
141+
5. Create new Pull Request

capistrano-symfony.gemspec

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# -*- encoding: utf-8 -*-
2+
lib = File.expand_path('../lib', __FILE__)
3+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4+
5+
Gem::Specification.new do |gem|
6+
gem.name = "capistrano-symfony"
7+
gem.version = '0.1.0'
8+
gem.authors = ["Peter Mitchell"]
9+
gem.email = ["[email protected]"]
10+
gem.description = %q{Symfony specific Capistrano tasks}
11+
gem.summary = %q{Capistrano Symfony - Easy deployment of Symfony 2 apps with Ruby over SSH}
12+
gem.homepage = "http://github.com/peterjmit/capistrano-symfony"
13+
14+
gem.files = `git ls-files`.split($/)
15+
# no tests as of yet
16+
# gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17+
gem.require_paths = ["lib"]
18+
19+
gem.licenses = ['MIT']
20+
21+
gem.add_dependency 'capistrano', '~> 3.1'
22+
gem.add_dependency 'capistrano-composer', '~> 0.0.3'
23+
gem.add_dependency 'capistrano-file-permissions', '~> 0.0.1'
24+
end

lib/capistrano-symfony.rb

Whitespace-only changes.

lib/capistrano/symfony.rb

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
require "capistrano/file-permissions"
2+
require "capistrano/composer"
3+
require "capistrano/symfony/dsl"
4+
require "capistrano/symfony/console"
5+
require "capistrano/symfony/assets"
6+
7+
# Core tasks for deploying symfony
8+
load File.expand_path("../tasks/symfony.rake", __FILE__)
9+
10+
namespace :load do
11+
task :defaults do
12+
load "capistrano/symfony/defaults.rb"
13+
end
14+
end

lib/capistrano/symfony/assets.rb

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
load File.expand_path("../../tasks/assets.rake", __FILE__)

lib/capistrano/symfony/console.rb

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
load File.expand_path("../../tasks/symfony_console.rake", __FILE__)

lib/capistrano/symfony/defaults.rb

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Symfony environment
2+
set :symfony_env_prod, "prod"
3+
4+
# Symfony application path
5+
set :app_path, "app"
6+
7+
# Symfony web path
8+
set :web_path, "web"
9+
10+
# Symfony log path
11+
set :log_path, fetch(:app_path) + "/logs"
12+
13+
# Symfony cache path
14+
set :cache_path, fetch(:app_path) + "/cache"
15+
16+
# Symfony config file path
17+
set :app_config_path, fetch(:app_path) + "/config"
18+
19+
# Controllers to clear
20+
set :controllers_to_clear, ["app_*.php"]
21+
22+
# Files that need to remain the same between deploys
23+
set :linked_files, []
24+
25+
# Dirs that need to remain the same between deploys (shared dirs)
26+
set :linked_dirs, [fetch(:log_path), fetch(:web_path) + "/uploads"]
27+
28+
# Dirs that need to be writable by the HTTP Server (i.e. cache, log dirs)
29+
set :file_permissions_paths, [fetch(:log_path), fetch(:cache_path)]
30+
31+
# Name used by the Web Server (i.e. www-data for Apache)
32+
set :webserver_user, "www-data"
33+
34+
# Method used to set permissions (:chmod, :acl, or :chown)
35+
set :permission_method, false
36+
37+
# Execute set permissions
38+
set :use_set_permissions, false
39+
40+
set :composer_install_flags, "--no-dev --no-scripts --verbose --prefer-dist --optimize-autoloader --no-progress"
41+
42+
set :symfony_console_path, fetch(:app_path) + "/console"
43+
set :symfony_console_flags, "--no-debug"
44+
45+
# Assets install
46+
set :assets_install_path, fetch(:web_path)
47+
48+
fetch(:default_env).merge!(symfony_env: fetch(:symfony_env_prod))

lib/capistrano/symfony/dsl.rb

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require 'capistrano/symfony/dsl/paths'

lib/capistrano/symfony/dsl/paths.rb

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
require "capistrano/dsl/paths"
2+
3+
module Capistrano
4+
module DSL
5+
module Paths
6+
7+
def symfony_app_path
8+
release_path.join(fetch(:app_path))
9+
end
10+
11+
def symfony_web_path
12+
release_path.join(fetch(:web_path))
13+
end
14+
15+
def symfony_log_path
16+
release_path.join(fetch(:log_path))
17+
end
18+
19+
def symfony_cache_path
20+
release_path.join(fetch(:cache_path))
21+
end
22+
23+
def symfony_config_path
24+
release_path.join(fetch(:app_config_path))
25+
end
26+
27+
end
28+
end
29+
end

lib/capistrano/tasks/assets.rake

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace :deploy do
2+
namespace :assets do
3+
task :install do
4+
invoke "symfony:command", "assets:install", fetch(:assets_install_path)
5+
end
6+
end
7+
end

lib/capistrano/tasks/symfony.rake

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
module Capistrano
2+
class FileNotFound < StandardError
3+
end
4+
end
5+
6+
namespace :deploy do
7+
desc "Create the cache directory"
8+
task :create_cache_dir do
9+
on roles :app do
10+
within release_path do
11+
if test "[ -d #{symfony_cache_path} ]"
12+
execute :rm, "-rf", symfony_cache_path
13+
end
14+
execute :mkdir, "-pv", fetch(:cache_path)
15+
end
16+
end
17+
end
18+
19+
desc "Clear non production controllers"
20+
task :clear_controllers do
21+
next unless any? :controllers_to_clear
22+
on roles :app do
23+
within symfony_web_path do
24+
execute :rm, "-f", *fetch(:controllers_to_clear)
25+
end
26+
end
27+
end
28+
29+
task :build_bootstrap do
30+
on roles :app do
31+
within release_path do
32+
# TODO: does this need to be configurable?
33+
execute "./vendor/sensio/distribution-bundle/Sensio/Bundle/DistributionBundle/Resources/bin/build_bootstrap.php"
34+
end
35+
end
36+
end
37+
38+
task :updating do
39+
invoke "deploy:create_cache_dir"
40+
41+
if fetch(:use_set_permissions)
42+
invoke "deploy:set_permissions:#{fetch(:permission_method).to_s}"
43+
end
44+
end
45+
46+
task :updated do
47+
invoke "deploy:build_bootstrap"
48+
invoke "symfony:cache:warmup"
49+
end
50+
51+
after "deploy:updated", "deploy:clear_controllers"
52+
after "deploy:updated", "deploy:assets:install"
53+
end
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
namespace :symfony do
2+
desc "Exceute a provided symfony command"
3+
task :command, :command_name do |t, args|
4+
# ask only runs if argument is not provided
5+
ask(:cmd, "cache:clear")
6+
command = args[:command_name] || fetch(:cmd)
7+
command_args = args.extras
8+
9+
on roles :app do
10+
within release_path do
11+
execute :php, fetch(:symfony_console_path), command, *command_args, fetch(:symfony_console_flags)
12+
end
13+
end
14+
end
15+
16+
namespace :cache do
17+
desc "Run app/console cache:clear for the #{fetch(:symfony_env_prod)} environment"
18+
task :clear do
19+
invoke "symfony:command", "cache:clear"
20+
end
21+
22+
desc "Run app/console cache:warmup for the #{fetch(:symfony_env_prod)} environment"
23+
task :warmup do
24+
invoke "symfony:command", "cache:warmup"
25+
end
26+
end
27+
end
28+
29+
task :symfony => ["symfony:command"]

0 commit comments

Comments
 (0)