diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..bb8ca2542 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +ansible.cfg diff --git a/CHANGELOG.md b/CHANGELOG.md index 3aa014475..d3250a02d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,14 @@ # Changelog +## v0.3 + +* working travis-ci tests +* datetime release dirs by default +* configurable migrations and schema update +* README update + ## v0.2 + * fixed merge errors * fixed deployment issues with config if already exists in project * fixed issue with missing SYMFONY_ENV while composer install @@ -10,4 +18,4 @@ ## v0.1 * structural refactoring (creating files, directories, ...) -* added cleanup-script to remove old releases \ No newline at end of file +* added cleanup-script to remove old releases diff --git a/README.md b/README.md index ca7f7a9d9..53c33ed1e 100644 --- a/README.md +++ b/README.md @@ -1,36 +1,71 @@ -Symfony2 -======== +# Symfony2 -Ansible role to easily deploy Symfony2 applications. It will clone a git repository, download and run composer install, and run assetic:dump when finished. The resulting directory structure is similar to what capifony creates: +Ansible role to easily deploy Symfony2 applications. +It will clone a git repository, a specific branch or a tag, download and run composer install, and run assetic:dump when finished. +The resulting directory structure is similar to what capifony creates: ``` project + composer.phar releases release shared - web/uploads - app/config - app/logs + web + uploads + app + config + logs current -> symlink to latest deployed release ``` -Requirements ------------- +It will also keep the ```releases``` directory clean and deletes all but your configured amount of releases. +You're also able to switch on/off whether ansible should execute doctrine migrations, or mongodb schema update, etc. -None +## Requirements + +Installed version of Ansible. -Installation ------------- +## Installation + +### Ansible galaxy ``` $ ansible-galaxy install servergrove.symfony2 ``` +### Usage + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + +```yaml +--- +- hosts: servers + roles: + - ansible-symfony2 + + vars: + symfony2_project_root: /test_app + symfony2_project_name: travis-test + symfony2_project_composer_path: /test_app/shared + symfony2_project_repo: https://github.com/symfony/symfony-standard.git + symfony2_project_branch: "2.6" + symfony2_project_php_path: php + symfony2_project_env: prod + symfony2_project_console_opts: '--no-debug' + symfony2_project_composer_opts: '--no-dev --optimize-autoloader' + symfony2_project_keep_releases: 5 + symfony2_project_clean_versioning: true +``` + + +## Role Variables -Role Variables --------------- +### Possible variables + +These are the possible role variables - you only need to have a small set defined, there are defaults. ```yaml +--- - vars: symfony2_project_root: Path where application will be deployed on server. symfony2_project_name: Name of project. @@ -44,30 +79,50 @@ Role Variables symfony2_project_composer_opts: '--no-dev --optimize-autoloader' symfony2_project_keep_releases: 5 symfony2_project_clean_versioning: true + symfony2_fire_schema_update: false # Runs doctrine:mongodb:schema:update + symfony2_fire_migrations: false # Runs doctrine migrations script ``` -Dependencies ------------- +### Role variable defaults + +As you can see, the release number default is the current date/time with seconds to allow for easy multiple releases per day. But you can always overwrite with ```--extra-vars=""``` option. + +```yaml +--- +- vars + symfony2_project_release: # internally replaced with YmdHis + symfony2_project_branch: master + symfony2_project_php_path: /usr/bin/php + symfony2_project_keep_releases: 5 + symfony2_project_clean_versioning: true + symfony2_project_console_opts: '' + symfony2_project_composer_opts: '--no-dev --optimize-autoloader' + symfony2_fire_schema_update: false + symfony2_fire_migrations: false +``` + +## Dependencies None -Example Playbook -------------------------- +## Testing -Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: +The deployment contains a basic test, executed by travis. If you want to locally test the role, have a look into ```.travis.yml``` for the exceution statements and (maybe) remove the ```geerlingguy.php ``` from ```tests/test.yml``` if you have a local php executable (needed for composer install and symfony console scripts). -```yaml -- hosts: servers - roles: - - { role: servergrove.symfony2, symfony2_project_root: /var/www/vhosts/example.com/, symfony2_project_name: demo, symfony2_project_branch: master, symfony2_project_release: 1 } +The test setup looks like this: + +``` +servergrove.symfony2 + tests + inventory # hosts information + test.yml # playbook + .travis.yml # travis config ``` -License -------- +## License -MIT +[MIT](LICENSE) license -Author Information ------------------- +### Author Information Contributions are welcome: https://github.com/servergrove/ansible-symfony2 diff --git a/defaults/main.yml b/defaults/main.yml index be0f16b2d..10a95711d 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,8 +1,12 @@ --- # defaults file for symfony2 -symfony2_project_release: 1 +symfony2_project_release: ~ symfony2_project_branch: master symfony2_project_php_path: php symfony2_project_keep_releases: 5 -symfony2_project_clean_versioning: true \ No newline at end of file +symfony2_project_clean_versioning: true +symfony2_project_console_opts: '' +symfony2_project_composer_opts: '--no-dev --optimize-autoloader' +symfony2_fire_schema_update: false +symfony2_fire_migrations: false diff --git a/tasks/main.yml b/tasks/main.yml index f68a8755d..5dc31b6e6 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,5 +1,8 @@ --- # tasks file for symfony2 +- set_fact: symfony2_project_release={{ lookup('pipe', 'date +%Y%m%d%H%M%S') }} + when: symfony2_project_release == None + - name: Create/prepare directories for release and shared data. file: state=directory path={{item.path}} with_items: @@ -61,7 +64,12 @@ shell: cd {{symfony2_project_root}}/releases/{{symfony2_project_release}} && {{symfony2_project_php_path}} app/console assetic:dump --env={{symfony2_project_env}} {{symfony2_project_console_opts}} - name: Run migrations. - shell: cd {{symfony2_project_root}}/releases/{{symfony2_project_release}} && if $(grep doctrine-migrations-bundle composer.json); then {{symfony2_project_php_path}} app/console doctrine:migrations:migrate -n; fi + shell: cd {{symfony2_project_root}}/releases/{{symfony2_project_release}}_{{symfony2_project_branch}} && if $(grep doctrine-migrations-bundle composer.json); then {{symfony2_project_php_path}} app/console doctrine:migrations:migrate -n; fi + when: symfony2_fire_migrations == true + +- name: Run mongodb schema update. + shell: cd {{symfony2_project_root}}/releases/{{symfony2_project_release}}_{{symfony2_project_branch}} && if $(grep mongodb-odm composer.json); then {{symfony2_project_php_path}} app/console doctrine:mongodb:schema:update --no-interaction; fi + when: symfony2_fire_schema_update == true - name: Create symlink. file: state=link src={{symfony2_project_root}}/releases/{{symfony2_project_release}} path={{symfony2_project_root}}/current diff --git a/tests/test.yml b/tests/test.yml index fc1814815..196ffb70d 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -6,15 +6,14 @@ - ansible-symfony2 vars: - symfony2_project_root: ~/test_app + symfony2_project_root: /test_app symfony2_project_name: travis-test - symfony2_project_composer_path: ~/test_app/shared + symfony2_project_composer_path: /test_app/shared symfony2_project_repo: https://github.com/symfony/symfony-standard.git - symfony2_project_release: 1 symfony2_project_branch: "2.6" symfony2_project_php_path: php symfony2_project_env: prod symfony2_project_console_opts: '--no-debug' symfony2_project_composer_opts: '--no-dev --optimize-autoloader' symfony2_project_keep_releases: 5 - symfony2_project_clean_versioning: true \ No newline at end of file + symfony2_project_clean_versioning: true