用于部署 Symfony 标准版的 Capistrano 任务
Symfony 4 specific tasks for Capistrano v3 (inspired by capifony).
It leverages the following capistrano tasks to deploy a Symfony app
This version is built for Symfony 2 and 3.
Go to Version 1 documentation.
This version is built for Symfony 4.
You are currently on the Version 2 branch.
Specify your dependencies:
# Gemfile
source 'https://rubygems.org'
gem 'capistrano', '~> 3.11'
gem 'capistrano-symfony', '~> 2.0.0'Install your dependencies:
bundle installWhen capistrano and capistrano-symfony is installed. Run the following command
to set up your local files:
cap installMake Capistrano aware of 'capistrano/symfony' by requiring capistrano-symfony in your
new Capfile after require "capistrano/deploy".
# Capfile
# ...
require "capistrano/symfony"If you use composer you might want this:
require "capistrano/composer"cap staging deploy
cap production deployIf you are using a standard Symfony Flex application that follows the best practises
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.
…capistrano-symfony hooks into the flow offered by capistrano. It adds to that flow like so
symfony:create_cache_dirsymfony:set_permissionssymfony:cache:warmupdeploy
|__ 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
| |__ symfony:make_console_executable
|__ deploy:updated
| |__ symfony:cache:warmup
|__ deploy:publishing
| |__ deploy:symlink:release
| |__ deploy:restart
|__ deploy:published
|__ deploy:finishing
| |__ deploy:cleanup
|__ deploy:finished
|__ deploy:log_revisionSet 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 public/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", "public/uploads"]Note: Using :acl requires that setfacl be available on your deployment target.
Note: If you are getting an error like setfacl: Option -m: Invalid argument near character 3,
it means that the users in file_permissions_users do not exist on your deployment
target.
See the symfony documentation and the file permission capistrano plugin for reference.
The following common tasks are available:
symfony:assets:installSo 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'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
endIf 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
endIf you use composer you can install capistrano/composer. Here are some short
instructions. Read more at capistrano/composer.
First run the following command to download the library:
gem install capistrano-composerThen make sure your Capfile includes the following:
require 'capistrano/composer'To download the composer.phar executable add the following to your deploy.rb:
# First define deploy target:
set :deploy_to, "/home/sites/com.example"
# Install composer if it does not exist
SSHKit.config.command_map[:composer] = "php #{shared_path.join("composer.phar")}"
namespace :deploy do
after :starting, 'composer:install_executable'
endgit checkout -b my-new-feature)git commit -am 'Add some feature')git push origin my-new-feature)暂无开放 Issues,或尚未同步最近议题。