cbrunnkvist.ansistrano-symfony-deploy

ansistrano-symfony-deploy

Build Status

A collection of Ansible tasks for deploying PHP applications using the Symfony framework (including flex) on *nix servers in a "Capistrano" style (releases, shared, current->releases/X).

This role mainly includes the most typical post-installation tasks such as getting a Composer executable, installing dependencies and autoloaders, warming the cache, and deploying migrations. It doesn't set up the directory structures or transfer files to your servers—those tasks are managed by the more general ansistrano-deploy role.

The implementation involves defining some ansistrano_(before|after)_X variables (see the ansistrano docs for more details).

Requirements

Due to limitations in the current version of Ansible, it is necessary for ansistrano-symfony-deploy and ansistrano-deploy to be in the same parent directory. This is usually the case, especially if you install it using ansible-galaxy.

These tasks probably will not work for Windows target hosts (not tested).

Role Variables

The following defaults variables are declared in this module:

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

symfony_console_path: 'app/console' # For Symfony 3+, use '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 try to update Composer
symfony_composer_version: 1.10.1 # Specify the Composer version to install. If not set, the latest stable version will be used

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 hooks that run before and after each 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

For more variables, please check the list of variables used by ansistrano.

Note about ORM/ODM Schema Migrations

Database schema migrations typically cannot be run in parallel on multiple hosts! Therefore, both symfony_run_doctrine_migrations and symfony_run_mongodb_schema_update are turned off by default.

To manage parallel execution, you can:

  1. Create your own ansistrano_before_symlink_tasks_file, perhaps using one from this project as a template (look in cbrunnkvist.ansistrano-symfony-deploy/config/steps/).
  2. Choose one of these approaches:
    • (a) Group hosts so that the task runs only on the first host in each group: when: groups['www-production'][0] == inventory_hostname
    • (b) Use run_once: true, possibly with delegate_to: some_primary_host (Docs: Playbook delegation)

Dependencies

Installing with ansible-galaxy install cbrunnkvist.ansistrano-symfony-deploy should automatically get the external role as a dependency, so no extra steps are needed.

Example Playbook

At a minimum, you likely need to declare the ansistrano_deploy_from and ansistrano_deploy_to variables. By default, Ansistrano uses rsync from a local directory (see the ansistrano docs).

Assuming you have a my-app-infrastructure/deploy.yml file:

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

You can run this playbook like any other: ansible-playbook -i some_hosts_file deploy.yml.

It may be better to keep one-off system preparation tasks in a different playbook, like my-app-infrastructure/setup.yml.

License

MIT

Author Information

  • ansistrano-symfony-deploy was written by Conny Brunnkvist cbrunnkvist@gmail.com
  • The underlying role is maintained by the ansistrano-deploy team
  • Some code ideas are inspired by the symfony2-deploy role by the Servergrove team.
Informazioni sul progetto

Common post-deploy tasks for Symfony projects

Installa
ansible-galaxy install cbrunnkvist.ansistrano-symfony-deploy
Licenza
mit
Download
43.6k
Proprietario