GithubHelp home page GithubHelp logo

jbgomond / capistrano-symfony Goto Github PK

View Code? Open in Web Editor NEW

This project forked from capistrano/symfony

0.0 1.0 0.0 38 KB

Capistrano tasks for deploying the Symfony standard edition

License: MIT License

Ruby 100.00%

capistrano-symfony's Introduction

Capistrano::Symfony

Symfony 2 (standard edition) specific tasks for Capistrano v3 (inspired by capifony).

It leverages the following capistrano tasks to deploy a Symfony app

Installation

# Gemfile
gem 'capistrano',  '~> 3.4'
gem 'capistrano-symfony', '~> 1.0.0.rc1'

Usage

Require capistrano-symfony in your cap file

# Capfile
require 'capistrano/symfony'

Settings

If you are using an un-modified symfony-standard edition, version 3 then you do not need to change/add anything to your deploy.rb other than what is required from Capistrano.

We do however expose the following settings (shown with default evaluated values) that can be modified to suit your project. Please refer to lib/capistrano/symfony/defaults.rb to see exactly how the defaults are set up.

# Symfony console commands will use this environment for execution
set :symfony_env,  "prod"

# Set this to 2 for the old directory structure
set :symfony_directory_structure, 3
# Set this to 4 if using the older SensioDistributionBundle
set :sensio_distribution_version, 5

# symfony-standard edition directories
set :app_path, "app"
set :web_path, "web"
set :var_path, "var"
set :bin_path, "bin"

# The next 3 settings are lazily evaluated from the above values, so take care
# when modifying them
set :app_config_path, "app/config"
set :log_path, "var/logs"
set :cache_path, "var/cache"

set :symfony_console_path, "bin/console"
set :symfony_console_flags, "--no-debug"

# Remove app_dev.php during deployment, other files in web/ can be specified here
set :controllers_to_clear, ["app_*.php"]

# asset management
set :assets_install_path, "web"
set :assets_install_flags,  '--symlink'

# Share files/directories between releases
set :linked_files, []
set :linked_dirs, ["var/logs"]

# Set correct permissions between releases, this is turned off by default
set :file_permissions_paths, ["var"]
set :permission_method, false

Using this plugin with the old Symfony 2 directory structure and SensioDistributionBundle <= 4

Add the following to deploy.rb to use the old directory structure

# deploy.rb
set :symfony_directory_structure, 2
set :sensio_distribution_version, 4

If you are upgrading this gem and have modified linked_dirs or "advanced" variables such as log_path then you will need to update those accordingly

Flow

capistrano-symfony hooks into the flow 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
|   |__ 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

File permissions

Set the permission_method variable to one of :chmod, :acl, or :chgrp in your deploy.rb to handle the common scenario of a web user and the deploy user being different.

Both will need access to the files/directories such as var/cache and web/uploads (if you handle uploads). Set file_permissions_users to your webserver user

Example:

# deploy.rb

set :permission_method, :acl
set :file_permissions_users, ["nginx"]
set :file_permissions_paths, ["var", "web/uploads"]

Please note that :acl requires that setfacl be available on your deployment target

See the symfony documentation and the file permission capistrano plugin for reference

Integrated common tasks

The following common tasks are available:

  • symfony:assets:install
  • symfony:build_bootstrap - useful if you disable composer

So you can use them with hooks in your project's deploy.rb like this:

after 'deploy:updated', 'symfony:assets:install'
before 'deploy:updated', 'symfony:build_bootstrap'

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 in your project you may want to run migrations during a deploy.

namespace :deploy do
  task :migrate do
    symfony_console('doctrine:migrations:migrate', '--no-interaction')
  end
end

If you want to execute a command on a host with a given role you can use the Capistrano on DSL, additionally using within from Capistrano will change the directory

namespace :deploy do
  task :migrate do
    on roles(:db) do
      symfony_console('doctrine:migrations:migrate', '--no-interaction')
    end
  end
end

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.