From 86069b4780bce7951c4324a6312b1d99b37fa6e8 Mon Sep 17 00:00:00 2001 From: Marc Aschmann Date: Thu, 16 Apr 2015 12:17:12 +0200 Subject: [PATCH] Cleanup main task with iterator, improvements to git and composer handling Cleaned up composer handling: Now checks if composer is already there and updates if needed. Made main task more readable. Introduced iterator for path/symlink creation. Added optional .git dir removal for releases - keeps disk usage lower for large repos. --- README.md | 1 + defaults/main.yml | 1 + tasks/main.yml | 67 +++++++++++++++++++++++++++++++---------------- 3 files changed, 46 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 2f11b0d4f..300d8dcd1 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,7 @@ Role Variables symfony2_project_env: prod symfony2_project_console_opts: '' symfony2_project_composer_opts: '--no-dev --optimize-autoloader' + symfony2_project_clean_versioning: true ``` Dependencies diff --git a/defaults/main.yml b/defaults/main.yml index 40bbbc3bc..2dcc7e924 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -4,3 +4,4 @@ symfony2_project_release: 1 symfony2_project_branch: master symfony2_project_php_path: php +symfony2_project_clean_versioning: true diff --git a/tasks/main.yml b/tasks/main.yml index 67d1cc565..4433be0c6 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,34 +1,55 @@ --- # tasks file for symfony2 -- name: Create the release {{symfony2_project_release}} directory. - file: state=directory path={{symfony2_project_root}}/releases/{{symfony2_project_release}} -- name: Create the shared directory. - file: state=directory path={{symfony2_project_root}}/shared -- name: Create the shared/app/config directory. - file: state=directory path={{symfony2_project_root}}/shared/app/config -- name: Create the shared/web/uploads directory. - file: state=directory path={{symfony2_project_root}}/shared/web/uploads -- name: Create the shared/app/logs directory. - file: state=directory path={{symfony2_project_root}}/shared/app/logs +- name: Create/prepare directories for release and shared data. + file: state=directory path={{item.path}} + with_items: + - { path: "{{symfony2_project_root}}/releases/{{symfony2_project_release}}" } + - { path: "{{symfony2_project_root}}/shared" } + - { path: "{{symfony2_project_root}}/shared/app/config" } + - { path: "{{symfony2_project_root}}/shared/app/uploads" } + - { path: "{{symfony2_project_root}}/shared/app/logs" } + - name: Pull sources from the repository. - git: repo={{symfony2_project_repo}} dest={{symfony2_project_root}}/releases/{{symfony2_project_release}} version={{symfony2_project_branch}} -- name: Check if shared/app/config/parameters.ini exists + git: repo={{symfony2_project_repo}} dest={{symfony2_project_root}}/releases/{{symfony2_project_release}} version={{symfony2_project_branch}} accept_hostkey=yes + +- name: Clean out versioning. + file: state=absent path={{symfony2_project_root}}/releases/{{symfony2_project_release}}/.git + when: symfony2_project_clean_versioning == true + +- name: Create symlinks to shared directories. + file: state=link src={{item.src}} path={{item.path}} + with_items: + - { src: "{{symfony2_project_root}}/shared/web/uploads", path: "{{symfony2_project_root}}/releases/{{symfony2_project_release}}/uploads" } + - { src: "{{symfony2_project_root}}/shared/app/logs", path: "{{symfony2_project_root}}/releases/{{symfony2_project_release}}/logs" } + +- name: Check if shared/app/config/parameters.ini exists. stat: path={{symfony2_project_root}}/shared/app/config/parameters.ini register: parameters_ini -- name: Create symlink for app/config/parameters.ini from shared directory + +- name: Create symlink for app/config/parameters.ini from shared directory. shell: ln -s {{symfony2_project_root}}/shared/app/config/parameters.ini {{symfony2_project_root}}/releases/{{symfony2_project_release}}/app/config/parameters.ini creates={{symfony2_project_root}}/releases/{{symfony2_project_release}}/app/config/parameters.ini when: parameters_ini.stat.exists -- name: Create app/logs symlink - file: state=link src={{symfony2_project_root}}/shared/app/logs path={{symfony2_project_root}}/releases/{{symfony2_project_release}}/app/logs -- name: Create web/uploads symlink - file: state=link src={{symfony2_project_root}}/shared/web/uploads path={{symfony2_project_root}}/releases/{{symfony2_project_release}}/web/uploads -- name: Install composer - get_url: url=https://getcomposer.org/composer.phar dest={{symfony2_project_root}}/composer.phar mode=0755 validate_certs=no -- name: Run composer install + +- name: Check if composer exists. + stat: path={{symfony2_project_composer_path}} + register: composer_file + +- name: Install composer. + get_url: url=https://getcomposer.org/composer.phar dest={{symfony2_project_composer_path}} mode=0755 validate_certs=no + when: composer_file.stat.exists == false + +- name: Update composer if already exists. + shell: "{{symfony2_project_composer_path}} selfupdate" + when: composer_file.stat.exists == true + +- name: Run composer install. shell: cd {{symfony2_project_root}}/releases/{{symfony2_project_release}} && {{symfony2_project_php_path}} {{symfony2_project_root}}/composer.phar install {{symfony2_project_composer_opts}} -- name: Dump assets + +- name: Dump assets. 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 + +- 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 -- name: Create symlink + +- name: Create symlink. file: state=link src={{symfony2_project_root}}/releases/{{symfony2_project_release}} path={{symfony2_project_root}}/current