Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit 61deda4fbab0eead609352a4938115adffa49bb5 @peterjmit peterjmit committed Feb 27, 2014
@@ -0,0 +1,17 @@
+*.gem
+*.rbc
+.bundle
+.config
+.yardoc
+Gemfile.lock
+InstalledFiles
+_yardoc
+coverage
+doc/
+lib/bundler/man
+pkg
+rdoc
+spec/reports
+test/tmp
+test/version_tmp
+tmp
@@ -0,0 +1,22 @@
+Copyright (c) 2014 Peter Mitchell
+
+MIT License
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,141 @@
+# Capistrano::Symfony
+
+Symfony 2 (standard edition) specific tasks for Capistrano v3
+(inspired by [capifony][2])
+
+It leverages the following capistrano tasks to deploy a Symfony app
+
+* https://github.com/capistrano/composer
+* https://github.com/capistrano/file-permissions
+
+## Installation
+
+```
+# Gemfile
+gem 'capistrano', '~> 3.1'
+gem 'capistrano-symfony', '~> 0.1'
+```
+
+## Usage
+
+Require capistrano-symfony in your cap file
+
+```
+# Capfile
+require 'capistrano/symfony'
+```
+
+### Settings
+
+capistrano-symfony exposes the following settings (displayed with defaults):
+
+```ruby
+# Symfony environment
+set :symfony_env_prod, "prod"
+
+# Symfony application path
+set :app_path, "app"
+
+# Symfony web path
+set :web_path, "web"
+
+# Symfony log path
+set :log_path, fetch(:app_path) + "/logs"
+
+# Symfony cache path
+set :cache_path, fetch(:app_path) + "/cache"
+
+# Symfony config file path
+set :app_config_path, fetch(:app_path) + "/config"
+
+# Controllers to clear
+set :controllers_to_clear, ["app_*.php"]
+
+# Files that need to remain the same between deploys
+set :linked_files, []
+
+# Dirs that need to remain the same between deploys (shared dirs)
+set :linked_dirs, [fetch(:log_path), fetch(:web_path) + "/uploads"]
+
+# Dirs that need to be writable by the HTTP Server (i.e. cache, log dirs)
+set :file_permissions_paths, [fetch(:log_path), fetch(:cache_path)]
+
+# Name used by the Web Server (i.e. www-data for Apache)
+set :webserver_user, "www-data"
+
+# Method used to set permissions (:chmod, :acl, or :chown)
+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"
+
+set :symfony_console_path, fetch(:app_path) + "/console"
+set :symfony_console_flags, "--no-debug"
+
+# Assets install
+set :assets_install_path, fetch(:web_path)
+```
+
+### Flow
+
+capistrano-symfony hooks into the [flow][1] offered by capistrano. It adds
+to that flow like so
+
+```
+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
+```
+
+### Using the Symfony console
+
+A task wrapping the symfony console is provided, making it easy to create tasks
+that call console methods.
+
+For example if you have installed the [DoctrineMigrationsBundle][3] in your
+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'
+ end
+end
+```
+
+[1]: http://capistranorb.com/documentation/getting-started/flow/
+[2]: http://capifony.org/
+[3]: http://symfony.com/doc/current/bundles/DoctrineMigrationsBundle/index.html
+
+## Contributing
+
+1. Fork it
+2. Create your feature branch (`git checkout -b my-new-feature`)
+3. Commit your changes (`git commit -am 'Add some feature'`)
+4. Push to the branch (`git push origin my-new-feature`)
+5. Create new Pull Request
@@ -0,0 +1,24 @@
+# -*- encoding: utf-8 -*-
+lib = File.expand_path('../lib', __FILE__)
+$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
+
+Gem::Specification.new do |gem|
+ gem.name = "capistrano-symfony"
+ gem.version = '0.1.0'
+ gem.authors = ["Peter Mitchell"]
+ gem.email = ["pete@peterjmit.com"]
+ gem.description = %q{Symfony specific Capistrano tasks}
+ gem.summary = %q{Capistrano Symfony - Easy deployment of Symfony 2 apps with Ruby over SSH}
+ gem.homepage = "http://github.com/peterjmit/capistrano-symfony"
+
+ gem.files = `git ls-files`.split($/)
+ # no tests as of yet
+ # gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
+ gem.require_paths = ["lib"]
+
+ gem.licenses = ['MIT']
+
+ gem.add_dependency 'capistrano', '~> 3.1'
+ gem.add_dependency 'capistrano-composer', '~> 0.0.3'
+ gem.add_dependency 'capistrano-file-permissions', '~> 0.0.1'
+end
No changes.
@@ -0,0 +1,14 @@
+require "capistrano/file-permissions"
+require "capistrano/composer"
+require "capistrano/symfony/dsl"
+require "capistrano/symfony/console"
+require "capistrano/symfony/assets"
+
+# Core tasks for deploying symfony
+load File.expand_path("../tasks/symfony.rake", __FILE__)
+
+namespace :load do
+ task :defaults do
+ load "capistrano/symfony/defaults.rb"
+ end
+end
@@ -0,0 +1 @@
+load File.expand_path("../../tasks/assets.rake", __FILE__)
@@ -0,0 +1 @@
+load File.expand_path("../../tasks/symfony_console.rake", __FILE__)
@@ -0,0 +1,48 @@
+# Symfony environment
+set :symfony_env_prod, "prod"
+
+# Symfony application path
+set :app_path, "app"
+
+# Symfony web path
+set :web_path, "web"
+
+# Symfony log path
+set :log_path, fetch(:app_path) + "/logs"
+
+# Symfony cache path
+set :cache_path, fetch(:app_path) + "/cache"
+
+# Symfony config file path
+set :app_config_path, fetch(:app_path) + "/config"
+
+# Controllers to clear
+set :controllers_to_clear, ["app_*.php"]
+
+# Files that need to remain the same between deploys
+set :linked_files, []
+
+# Dirs that need to remain the same between deploys (shared dirs)
+set :linked_dirs, [fetch(:log_path), fetch(:web_path) + "/uploads"]
+
+# Dirs that need to be writable by the HTTP Server (i.e. cache, log dirs)
+set :file_permissions_paths, [fetch(:log_path), fetch(:cache_path)]
+
+# Name used by the Web Server (i.e. www-data for Apache)
+set :webserver_user, "www-data"
+
+# Method used to set permissions (:chmod, :acl, or :chown)
+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"
+
+set :symfony_console_path, fetch(:app_path) + "/console"
+set :symfony_console_flags, "--no-debug"
+
+# Assets install
+set :assets_install_path, fetch(:web_path)
+
+fetch(:default_env).merge!(symfony_env: fetch(:symfony_env_prod))
@@ -0,0 +1 @@
+require 'capistrano/symfony/dsl/paths'
@@ -0,0 +1,29 @@
+require "capistrano/dsl/paths"
+
+module Capistrano
+ module DSL
+ module Paths
+
+ def symfony_app_path
+ release_path.join(fetch(:app_path))
+ end
+
+ def symfony_web_path
+ release_path.join(fetch(:web_path))
+ end
+
+ def symfony_log_path
+ release_path.join(fetch(:log_path))
+ end
+
+ def symfony_cache_path
+ release_path.join(fetch(:cache_path))
+ end
+
+ def symfony_config_path
+ release_path.join(fetch(:app_config_path))
+ end
+
+ end
+ end
+end
@@ -0,0 +1,7 @@
+namespace :deploy do
+ namespace :assets do
+ task :install do
+ invoke "symfony:command", "assets:install", fetch(:assets_install_path)
+ end
+ end
+end
@@ -0,0 +1,53 @@
+module Capistrano
+ class FileNotFound < StandardError
+ end
+end
+
+namespace :deploy do
+ desc "Create the cache directory"
+ task :create_cache_dir do
+ on roles :app do
+ within release_path do
+ if test "[ -d #{symfony_cache_path} ]"
+ execute :rm, "-rf", symfony_cache_path
+ end
+ execute :mkdir, "-pv", fetch(:cache_path)
+ end
+ end
+ end
+
+ desc "Clear non production controllers"
+ task :clear_controllers do
+ next unless any? :controllers_to_clear
+ on roles :app do
+ within symfony_web_path do
+ execute :rm, "-f", *fetch(:controllers_to_clear)
+ end
+ end
+ end
+
+ task :build_bootstrap do
+ on roles :app do
+ within release_path do
+ # TODO: does this need to be configurable?
+ execute "./vendor/sensio/distribution-bundle/Sensio/Bundle/DistributionBundle/Resources/bin/build_bootstrap.php"
+ 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
@@ -0,0 +1,29 @@
+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_prod)} environment"
+ task :clear do
+ invoke "symfony:command", "cache:clear"
+ end
+
+ desc "Run app/console cache:warmup for the #{fetch(:symfony_env_prod)} environment"
+ task :warmup do
+ invoke "symfony:command", "cache:warmup"
+ end
+ end
+end
+
+task :symfony => ["symfony:command"]

0 comments on commit 61deda4

Please sign in to comment.