Skip to content

Latest commit

 

History

History
134 lines (91 loc) · 5.74 KB

README.md

File metadata and controls

134 lines (91 loc) · 5.74 KB

ansistrano-symfony-deploy

Build Status

A set of Ansible tasks for deploying PHP applications developed using the Symfony framework (incl. flex) onto *nix servers in a "Capistrano" fashion (releases, shared, current->releases/X).

This role is more or less just a collection of the most common post-installation setup tasks (i.e. getting a Composer executable, installing dependencies and autoloader, perform cache warming, deploy migrations etc). It does not itself deal with setting up the directory structures or getting files onto your servers - that part is handled by the more generic ansistrano-deploy role.

The way this is implemented is by defining a couple of the ansistrano_(before|after)_X vars (see the ansistrano docs for details).

Requirements

Due to shortcomings in the current version of Ansible, it is a requirement that the ansistrano-symfony-deploy and ansistrano-deploy share the same parent directory. This will be the normal case so shouldn't be an issue as long as you install via ansible-galaxy.

The tasks will probably not work for Windows target hosts (untested).

Role Variables

The defaults vars declared in this module:

symfony_env: prod
symfony_php_path: php # The PHP executable to use for all command line tasks

symfony_console_path: 'app/console' # If using Symfony 3+ this should be 'bin/console'

symfony_run_composer: true
symfony_composer_path: "{{ ansistrano_deploy_to }}/composer.phar"
symfony_composer_options: '--no-dev --optimize-autoloader --no-interaction'
symfony_composer_self_update: true # Always attempt a composer self-update
symfony_composer_version: 1.10.1 # Install specific composer version. If this variable is not set the latest stable version is installed
symfony_composer_channel: 2.2 # (mutually exclusive to symfony_composer_version) Use the latest composer version from a specific release channel - see https://getcomposer.org/download/#download-channels for specifics

symfony_run_assets_install: true
symfony_assets_options: '--no-interaction'

symfony_run_assetic_dump: true
symfony_assetic_options: '--no-interaction'

symfony_run_cache_clear_and_warmup: true
symfony_cache_options: ''

###############################################################################
symfony_run_doctrine_migrations: false
symfony_doctrine_options: '--no-interaction'

symfony_run_mongodb_schema_update: false
symfony_mongodb_options: ''

Hooks

This role supports ansistrano like hooks before and after every task

ansistrano_symfony_before_composer_tasks_file
ansistrano_symfony_after_composer_tasks_file

ansistrano_symfony_before_assets_tasks_file
ansistrano_symfony_after_assets_tasks_file

ansistrano_symfony_before_assetic_tasks_file
ansistrano_symfony_after_assetic_tasks_file

ansistrano_symfony_before_cache_tasks_file
ansistrano_symfony_after_cache_tasks_file

ansistrano_symfony_before_doctrine_tasks_file
ansistrano_symfony_after_doctrine_tasks_file

ansistrano_symfony_before_mongodb_tasks_file
ansistrano_symfony_after_mongodb_tasks_file

In addition to this, please also refer to the list of variables used by ansistrano.

Note about ORM/ODM schema migrations

Database schema migrations can generally NOT be run in parallel across multiple hosts! For this reason, the symfony_run_doctrine_migrations and symfony_run_mongodb_schema_update options both come turned off by default.

In order to get around the parallel exection, you can do the following:

  1. Specify your own ansistrano_before_symlink_tasks_file, perhaps with the one in this project as a template (look in cbrunnkvist.ansistrano-symfony-deploy/config/steps/).
  2. Pick one of the following approaches:
  • (a) Organize hosts into groups such that the task will run on only the first host in some group: when: groups['www-production'][0] == inventory_hostname
  • (b) Use the run_once: true perhaps with delegate_to: some_primary_host (Docs: Playbook delegation)

Dependencies

Installing from the command line via ansible-galaxy install cbrunnkvist.ansistrano-symfony-deploy should pull down the external role as a dependency, so no extra step neccessary.

Example playbook

As a bare minimum, you probably need to declare the ansistrano_deploy_from and ansistrano_deploy_to variables in your play. Ansistrano defaults to using rsync from a local directory (again, see the ansistrano docs).

Let's assume there is a my-app-infrastructure/deploy.yml:

---
- hosts: all
  gather_facts: false
  vars:
    ansistrano_deploy_from: ../my-project-checkout
    ansistrano_deploy_to: /home/app-user/my-project-deploy/
    ansistrano_before_symlink_tasks_file: "{{playbook_dir}}/config/app_specific_setup.yml"
  roles:
    - cbrunnkvist.ansistrano-symfony-deploy

This playbook should be executed like any other, i.e. ansible-playbook -i some_hosts_file deploy.yml.

It probably makes sense to keep your one-off system prep tasks in a separate playbook, e.g. my-app-infrastructure/setup.yml.

License

MIT

Author Information

  • ansistrano-symfony-deploy, written by Conny Brunnkvist [email protected]
  • The underlying role is maintained by the ansistrano-deploy team
  • Some code was taken from/inspiried by the symfony2-deploy role by the Servergrove team