Skip to content

Commit

Permalink
refactoring/cleanup of symfony-related recipes
Browse files Browse the repository at this point in the history
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
  • Loading branch information
robfrawley committed Jun 10, 2016
1 parent 31c9453 commit 9e08ae9
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 35 deletions.
29 changes: 23 additions & 6 deletions recipe/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand All @@ -44,6 +62,7 @@
return date('YmdHis');
}); // name of folder in releases


/**
* Custom bins.
*/
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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');


Expand Down
50 changes: 35 additions & 15 deletions recipe/symfony.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

require_once __DIR__ . '/common.php';


/**
* Symfony Configuration
*/
Expand All @@ -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
Expand Down Expand Up @@ -60,48 +73,53 @@
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');


/**
* 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');


/**
* 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');


/**
* 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');


Expand All @@ -116,11 +134,13 @@
'deploy:shared',
'deploy:assets',
'deploy:vendors',
'deploy:assets:install',
'deploy:assetic:dump',
'deploy:cache:warmup',
'deploy:writable',
'deploy:symlink',
'cleanup',
])->desc('Deploy your project');

// Display success message on completion
after('deploy', 'success');
15 changes: 1 addition & 14 deletions recipe/symfony3.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,13 @@
/**
* 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']);

// 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');

0 comments on commit 9e08ae9

Please sign in to comment.