diff --git a/recipe/common.php b/recipe/common.php index 75c13cdc5..239f34c6c 100644 --- a/recipe/common.php +++ b/recipe/common.php @@ -17,14 +17,32 @@ set('http_user', null); set('clear_paths', []); // Relative path from deploy_path set('clear_use_sudo', true); // Using sudo in clean commands? +set('composer_allow_update', false); + + +/** + * Composer options + */ +env('composer_action', 'install'); +env('composer_options', function () { + $options = '{{composer_action}} --verbose --prefer-dist --no-progress --no-interaction'; + + if (env('build_env') !== 'dev') { + $options .= ' --no-dev --optimize-autoloader'; + } + + return $options; +}); + /** * 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('build_env', 'prod'); +env('env_vars', ''); // Variable assignment before cmds (for example, SYMFONY_ENV={{build_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 +62,7 @@ return date('YmdHis'); }); // name of folder in releases + /** * Custom bins. */ @@ -74,6 +93,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 +356,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..247974e78 100644 --- a/recipe/symfony.php +++ b/recipe/symfony.php @@ -7,6 +7,7 @@ require_once __DIR__ . '/common.php'; + /** * Symfony Configuration */ @@ -22,17 +23,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={{build_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={{build_env}}'; + + return env('build_env') !== 'prod' ? $options : sprintf('%s --no-debug', $options); +}); + /** * Create cache dir @@ -60,21 +73,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 +99,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 +107,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 +115,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 +134,7 @@ 'deploy:shared', 'deploy:assets', 'deploy:vendors', + 'deploy:assets:install', 'deploy:assetic:dump', 'deploy:cache:warmup', 'deploy:writable', @@ -123,4 +142,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');