dastergon / symfony-project-cookbook

Resources and providers for deploying/interacting with Symfony applications

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build Status

Description

This cookbook provides an easy way to deploy a Symfony2 application, as well as run console commands on it.

Requirements

  • activelamp_composer cookbook

You might also need to install this on your node(s):

  • acl package to support the use of Chef::Provider::SymfonyPermission::Setfacl. You might have to use this if your nodes does not support the chmod +a ... command. You can install this using your platform's package manager (.i.e., apt)

Installing PHP and other packages is outside the scope of this cookbook.

Platforms:

  • Tested on Ubuntu/Debian only, but the deploy actions should work with any platform. However, there is no provider to handle :set_permissions on Windows at the moment.

Attributes

NA

Resources / Providers

symfony_project

This resource simply extends the built-in deploy resource, but provides sensible defaults that are relevant to most Symfony projects. For example, a symlink is automatically created for app/logs into the shared folder so that they persist between deploys. web/uploads is also automatically symlinked. You can override these links by specifying the shared_dirs option in the resource.

Actions

  • All actions supported by the deploy resource.
  • :set_permissions - Sets the permissions of app/logs, app/cache, web/uploads and any other directories you specified under world_writable_dirs

Examples

#Deploy a Symfony project
symfony_project "/path/to/project" do
    repo 'git@github.com:foo_organization/bar_application.git'
    revision 'v1.2'
    git_ssh_wrapper '/tmp/ssh-wrapper.sh'
    action [:deploy, :set_permissions]
    composer_options({
        :dev => true,
        :quiet => false,
        :verbosity => 2
    })
    parameters({
        :database_user => 'root',
        :database_password => node[:mysql][:server_root_password]
    })
end

Attributes

All options for the deploy resource is applicable here. However here are additional options that are symfony_project-specific:

Name Default Description
shared_dirs {'logs' => 'app/logs','cache' => 'app/cache','uploads' => 'web/media/uploads','vendor' => 'vendor'} The directories to create under the shared directory and symlinked into every deployment.
world_writable_dirs ['app/logs', 'app/cache', 'web/uploads'] Directories that should be world writeable.
permission_provider Chef::Provider::SymfonyPermission::Chmod The provider that handles the setting of the appropriate permissions on the directories listed under world_writable_dirs. Only relevant on :set_permissions. You can also substitute this for Chef::Provider::SymfonyPermission::Setfacl if your prefer to use setfacl to set the permissions.
web_user "www-data" The user to whom permission will be granted/umasked. Only relevant on :set_permissions
parameters {} Parameters overrides.
parameters_file app/config/parameters.yml Path to the parameters file
parameters_dist_file app/config/parameters.yml.dist Path to the parameters file distributable.
parameters_file_template parameters.yml.erb The ERB template for the parameters file. Parameter overriding is disabled if this is set to nil.
parameters_file_template_cookbook nil The cookbook where the prefered template is located. This will default to the current cookbook. Specify :activelamp_symfony if you wish to use the built-in one. Use @parameters to access the container parameters which are merged from the contents of the distributable and the values in parameters.
composer_options { :action => [:download_phar, :install], :lock_file_only => true, :dev => false, :prefer_dist => true, :prefer_source => false, :optimize_autoloader => true} The options used when the composer resource is called internally during migrate. Refer to the activelamp_composer cookbook for available options.

app_console

You can use this resource to interact with your Symfony application via the Symfony Console.

Actions

  • :run (default) - Runs the command
  • :nothing

Examples

#Run a Symfony Console command
app_console "/path/to/project/current" do
    command 'assetic:dump --force'
    environment 'prod'
    quiet false
    verbosity 3
    user node[:user]
    group node[:group]
end

Attributes

Attribute Default Description
app The name attribute The project root of the Symfony application.
command nil The command to execute
environment :prod The environment to run the command in. Used in the --env flag
quiet true If true, adds the --quiet flag
verbosity 1 Value for the --verbose flag.
user nil The user to execute the command as.
group nil The group to execute the command as.
console php app/console The Symfony Console command to use.

An example on using symfony_project and app_console together during deploys:

symfony_project "/path/to/project" do
    repo 'git@github.com:foo_organization/bar_application.git'
    revision 'v1.2'
    git_ssh_wrapper '/tmp/ssh-wrapper.sh'
    parameters({
        :database_user => 'root',
        :database_password => node[:mysql][:server_root_password],
        :database_host => 'localhost'
    })
    user node[:deploy_user]
    group node[:deploy_group]
    permission_provider Chef::Provider::SymfonyPermission::Setfacl
    world_writable_dirs.push('web/media/thumbnails')
    action [:deploy, :set_permissions]
    notifies :run, 'app_console[assetic-dump]'
end

app_console "assetic-dump" doo
   app '/path/to/project/current'
   command 'assetic:dump --force'
   console 'php bin/console' # If you are using Symfony 3.0 directory structure.
   user node[:deploy_user]
   group node[:deploy_group]
   action :nothing
end

License and Authors

Author: Bez Hermoso bez@activelamp.com

Author: ActiveLAMP

Copyright: 2012-2014, ActiveLAMP

Apache 2.0 License

About

Resources and providers for deploying/interacting with Symfony applications


Languages

Language:Ruby 99.6%Language:HTML 0.4%