With the tool generation like composer for vendor management, an automated tool to deploy your Symfony applications was so useful.
I will show your that it's terribly simple to configure Capifony to deploy your application. Let's see!
Installation
Start by installing the Capifony gem using RubyGems :
gem install capifony
We now just need to write two little ruby files to define our deployment rules.
Configuration
The first one is the Capfile that will just permit to load the deploy.rb file that defines the deployment rules. Here is the file structure in your Symfony project:
|-- app
| |-- config
| | |-- deploy.rb # Project configuration file
|-- Capfile # Capistrano file loading the deploy.rb file
So here is the Capfile :
load 'deploy' if respond_to?(:namespace)
require 'capifony_symfony2'
load 'app/config/deploy'
Quite simple. Let's now write our deploy.rb file step by step:
# Application settings
set :application, "your application name"
set :domain, "domain.com"
set :app_path, "app"
set :web_path, "web"
set :repository, "your@server.com:/repository.git"
set :scm, :git
set :keep_releases, 3
set :use_sudo, false
# Be more or less verbose by commenting/uncommenting the following lines
#logger.level = Logger::IMPORTANT
#logger.level = Logger::INFO
#logger.level = Logger::DEBUG
#logger.level = Logger::TRACE
logger.level = Logger::MAX_LEVEL
Define your project main variables as the application name, domain name, directories and your repository URL.
You can specify the number of releases you want to keep when using the cap [stage] deploy:cleanup command and many other variables are available on the Capifony documentation.
Now, let's add a task that will be launched after the "deploy:setup" task and that will upload the correct parameters file determines on the stage name:
# Upload parameters file corresponding to environment stage
after "deploy:setup" do
run "if [ ! -d #{deploy_to}/shared/app/config ]; then mkdir -p #{deploy_to}/shared/app/config; fi"
upload(
'%s/parameters_%s.yml' % [File.dirname(__FILE__), fetch(:stage)],
'%s/shared/app/config/parameters.yml' % fetch(:deploy_to)
)
end
Define your environments
Finally, let's write a block similar to the block below for each environments you want to deploy on:
# Configure production instance
desc "Deploy to production instance"
task :production do
set :stage, "production"
set :branch, "master"
set :deploy_to, "/path/to/your/web/directory"
role :app, "user@domain.com", :promary => true
role :web, "user@domain.com"
end
Here we go, your application can now be deployed on each environments you defined. Do not hesitate to read full official documentations for more information about options available.