From ec3fb295625cadc17b057e9ef19938c6e0de70d8 Mon Sep 17 00:00:00 2001 From: Rob Frawley 2nd Date: Sun, 5 Jun 2016 12:58:34 -0400 Subject: [PATCH] refactoring/cleanup of symfony-related recipes fix double task removed composer.lock from commit fix for styleci fix for styleci fix for https://travis-ci.org/deployphp/deployer/builds/135430111 added option to allow composer update renamed env to build_env removed composer action logic moved env to only symfony-recepes removed allow update cleanup comment --- recipe/common.php | 19 +++++++++++----- recipe/symfony.php | 53 ++++++++++++++++++++++++++++++++------------- recipe/symfony3.php | 15 +------------ 3 files changed, 52 insertions(+), 35 deletions(-) diff --git a/recipe/common.php b/recipe/common.php index 75c13cdc5..14444f216 100644 --- a/recipe/common.php +++ b/recipe/common.php @@ -18,13 +18,21 @@ set('clear_paths', []); // Relative path from deploy_path set('clear_use_sudo', true); // Using sudo in clean commands? + +/** + * Composer options + */ +env('composer_action', 'install'); +env('composer_options', '{{composer_action}} --verbose --prefer-dist --no-progress --no-interaction --no-dev --optimize-autoloader'); + + /** * Environment vars */ env('timezone', 'UTC'); env('branch', ''); // Branch to deploy. -env('env_vars', ''); // For Composer installation. Like SYMFONY_ENV=prod -env('composer_options', 'install --no-dev --verbose --prefer-dist --optimize-autoloader --no-progress --no-interaction'); +env('env_vars', ''); // Variable assignment before cmds (for example, SYMFONY_ENV={{env}}) + env('git_cache', function () { //whether to use git cache - faster cloning by borrowing objects from existing clones. $gitVersion = run('{{bin/git}} version'); $regs = []; @@ -44,6 +52,7 @@ return date('YmdHis'); }); // name of folder in releases + /** * Custom bins. */ @@ -74,6 +83,7 @@ option('tag', null, \Symfony\Component\Console\Input\InputOption::VALUE_OPTIONAL, 'Tag to deploy.'); option('revision', null, \Symfony\Component\Console\Input\InputOption::VALUE_OPTIONAL, 'Revision to deploy.'); + /** * Rollback to previous release. */ @@ -336,10 +346,7 @@ * Installing vendors tasks. */ task('deploy:vendors', function () { - $composer = env('bin/composer'); - $envVars = env('env_vars') ? 'export ' . env('env_vars') . ' &&' : ''; - - run("cd {{release_path}} && $envVars $composer {{composer_options}}"); + run('cd {{release_path}} && {{env_vars}} {{bin/composer}} {{composer_options}}'); })->desc('Installing vendors'); diff --git a/recipe/symfony.php b/recipe/symfony.php index 622671ccd..b0e49eb66 100644 --- a/recipe/symfony.php +++ b/recipe/symfony.php @@ -7,10 +7,14 @@ require_once __DIR__ . '/common.php'; + /** * Symfony Configuration */ +// Symfony build env +env('env', 'prod'); + // Symfony shared dirs set('shared_dirs', ['app/logs']); @@ -22,17 +26,29 @@ // Assets set('assets', ['web/css', 'web/images', 'web/js']); -// Default true - BC for Symfony < 3.0 -set('dump_assets', true); + +// Requires non symfony-core package `kriswallsmith/assetic` to be installed +set('dump_assets', false); // Environment vars -env('env_vars', 'SYMFONY_ENV=prod'); -env('env', 'prod'); +env('env_vars', 'SYMFONY_ENV={{env}}'); // Adding support for the Symfony3 directory structure set('bin_dir', 'app'); set('var_dir', 'app'); +// Symfony console bin +env('bin/console', function () { + return sprintf('{{release_path}}/%s/console', trim(get('bin_dir'), '/')); +}); + +// Symfony console opts +env('console_options', function () { + $options = '--no-interaction --env={{env}}'; + + return env('env') !== 'prod' ? $options : sprintf('%s --no-debug', $options); +}); + /** * Create cache dir @@ -60,21 +76,25 @@ return "{{release_path}}/$asset"; }, get('assets'))); - $time = date('Ymdhi.s'); - - run("find $assets -exec touch -t $time {} ';' &> /dev/null || true"); + run(sprintf('find %s -exec touch -t %s {} \';\' &> /dev/null || true', $assets, date('Ymdhi.s'))); })->desc('Normalize asset timestamps'); +/** + * Install assets from public dir of bundles + */ +task('deploy:assets:install', function () { + run('{{env_vars}} {{bin/php}} {{bin/console}} assets:install {{console_options}} {{release_path}}/web'); +})->desc('Install bundle assets'); + + /** * Dump all assets to the filesystem */ task('deploy:assetic:dump', function () { - if (!get('dump_assets')) { - return; + if (get('dump_assets')) { + run('{{env_vars}} {{bin/php}} {{bin/console}} assetic:dump {{console_options}}'); } - - run('{{bin/php}} {{release_path}}/' . trim(get('bin_dir'), '/') . '/console assetic:dump --env={{env}} --no-debug'); })->desc('Dump assets'); @@ -82,7 +102,7 @@ * Warm up cache */ task('deploy:cache:warmup', function () { - run('{{bin/php}} {{release_path}}/' . trim(get('bin_dir'), '/') . '/console cache:warmup --env={{env}} --no-debug'); + run('{{env_vars}} {{bin/php}} {{bin/console}} cache:warmup {{console_options}}'); })->desc('Warm up cache'); @@ -90,7 +110,7 @@ * Migrate database */ task('database:migrate', function () { - run('{{bin/php}} {{release_path}}/' . trim(get('bin_dir'), '/') . '/console doctrine:migrations:migrate --env={{env}} --no-debug --no-interaction'); + run('{{env_vars}} {{bin/php}} {{bin/console}} doctrine:migrations:migrate {{console_options}}'); })->desc('Migrate database'); @@ -98,10 +118,11 @@ * Remove app_dev.php files */ task('deploy:clear_controllers', function () { - run("rm -f {{release_path}}/web/app_*.php"); - run("rm -f {{release_path}}/web/config.php"); + run('rm -f {{release_path}}/web/app_*.php'); + run('rm -f {{release_path}}/web/config.php'); })->setPrivate(); +// Run after code is checked out after('deploy:update_code', 'deploy:clear_controllers'); @@ -116,6 +137,7 @@ 'deploy:shared', 'deploy:assets', 'deploy:vendors', + 'deploy:assets:install', 'deploy:assetic:dump', 'deploy:cache:warmup', 'deploy:writable', @@ -123,4 +145,5 @@ 'cleanup', ])->desc('Deploy your project'); +// Display success message on completion after('deploy', 'success'); diff --git a/recipe/symfony3.php b/recipe/symfony3.php index d7eb57297..0773653f5 100644 --- a/recipe/symfony3.php +++ b/recipe/symfony3.php @@ -10,20 +10,6 @@ /** * Symfony 3 Configuration */ - -/** - * Dump all assets to the filesystem - * - * This overrides the Symfony 2 assetic:dump command - * in favor of the new assets:install command. - */ -task('deploy:assetic:dump', function () { - if (!get('dump_assets')) { - return; - } - - run('{{bin/php}} {{release_path}}/' . trim(get('bin_dir'), '/') . '/console assets:install --env={{env}} --no-debug {{release_path}}/web'); -})->desc('Dump assets'); // Symfony shared dirs set('shared_dirs', ['var/logs', 'var/sessions']); @@ -31,5 +17,6 @@ // Symfony writable dirs set('writable_dirs', ['var/cache', 'var/logs', 'var/sessions']); +// Symfony executable and variable directories set('bin_dir', 'bin'); set('var_dir', 'var');