• Stars
    star
    354
  • Rank 115,750 (Top 3 %)
  • Language
    Ruby
  • License
    MIT License
  • Created about 10 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Capistrano tasks for deploying the Symfony standard edition

Capistrano::Symfony

Symfony 4 specific tasks for Capistrano v3 (inspired by capifony).

It leverages the following capistrano tasks to deploy a Symfony app

Version information

Version 1.x

This version is built for Symfony 2 and 3.

Go to Version 1 documentation.

Version 2.x

This version is built for Symfony 4.

You are currently on the Version 2 branch.

Installation

Specify your dependencies:

# Gemfile
source 'https://rubygems.org'
gem 'capistrano',  '~> 3.11'
gem 'capistrano-symfony', '~> 2.0.0'

Install your dependencies:

bundle install

When capistrano and capistrano-symfony is installed. Run the following command to set up your local files:

cap install

Make 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"

Usage

cap staging deploy
cap production deploy

Settings

If 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.

# symfony-standard edition directories
set :bin_path, "bin"
set :config_path, "config"
set :var_path, "var"
set :web_path, "public"

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

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

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

# Share files/directories between releases
set :linked_dirs, ["var/log"]
set :linked_files, []
# To use a .env file:
#set :linked_files, [".env"]

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

# Role filtering
set :symfony_roles, :all
set :symfony_deploy_roles, :all

# Add extra environment variables: 
set :default_env, {
 'APP_ENV' => 'prod'
 'SECRET' => 'foobar'
}

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
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
|   |__ 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_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 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.

Integrated common tasks

The following common tasks are available:

  • symfony:assets:install

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

Using composer

If 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-composer

Then 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'
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

More Repositories

1

capistrano

A deployment automation tool built on Ruby, Rake, and SSH.
Ruby
12,631
star
2

sshkit

A toolkit for deploying code and assets to servers in a repeatable, testable, reliable way.
Ruby
1,110
star
3

rails

Official Ruby on Rails specific tasks for Capistrano
Ruby
858
star
4

laravel

Gem for deploying Laravel projects with capistrano v3.*
Ruby
220
star
5

bundler

Bundler support for Capistrano 3.x
Ruby
219
star
6

rbenv

Idiomatic rbenv support for Capistrano 3.x
Ruby
201
star
7

composer

Capistrano extension for Composer tasks
Ruby
183
star
8

npm

Capistrano extension for npm
Ruby
157
star
9

maintenance

Maintenance Page Support For Capistrano
Ruby
154
star
10

rvm

Ruby
139
star
11

passenger

Passenger support for Capistrano 3.x
Ruby
138
star
12

notification-center

Capistrano integration with macOS Notification Center
Ruby
88
star
13

documentation

CSS
81
star
14

file-permissions

File permissions handling for Capistrano v3.*
Ruby
46
star
15

drupal-deploy

Gem for deploying Drupal projects with capistrano 3
Ruby
40
star
16

github

Ruby
26
star
17

capistrano-2.x-docs

An archive of the now-defunct Capistrano 2.x wiki
24
star
18

copy-files

Capistrano v3.* extension for copying files between releases
Ruby
23
star
19

chruby

Ruby
23
star
20

stats

Capistrano statistics, gem, server, manifest and dashboard
Go
12
star
21

packer

Packer manifest to build a debian image for Vagrant which we can use to test against. (and, also for inducting people to the Capistrano way)
Shell
5
star
22

danger

Common Dangerfile for Capistrano projects
Ruby
3
star
23

capistrano-features

A place for discussions about possible Capistrano developments.
2
star
24

capistrano-sprockets

Rails Sprocket Support For Capistrano
2
star