Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring/Cleanup/Fixes for Symfony-related Recipes #688

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions recipe/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Copy link
Contributor Author

@robfrawley robfrawley Jun 10, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Elfet Is this acceptable?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still allow users to use update. And this is ban practice. @oanhnn what you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Crosses fingers... I understand your gut-reaction against running update ad-hoc, but it can be useful for automated deployments to dev server. compoaser_options already exists, so it's easy enough to overwrite the whole string, but this just pulls out composer_action. Give me a heads up if this is okay @oanhnn and @Elfet .

Copy link
Contributor

@oanhnn oanhnn Jun 12, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Elfet I think it is ok. Not break BC and users can customize composer_action easily.
I think in Deployer, composer_options will not include composer_action

Copy link
Contributor Author

@robfrawley robfrawley Jun 13, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oanhnn Is this what you mentioned breaking into a separate PR?



/**
* 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 = [];
Expand All @@ -44,6 +52,7 @@
return date('YmdHis');
}); // name of folder in releases


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


Expand Down
53 changes: 38 additions & 15 deletions recipe/symfony.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);

Expand All @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Old code

// Default true - BC for Symfony < 3.0
set('dump_assets', true);

Why do you change BC?

Copy link
Contributor Author

@robfrawley robfrawley Jun 11, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't assume asset compilation is desired b/c it isn't a core Symfony command and there is no reason to believe the user has it installed. It relies on https://github.com/symfony/assetic-bundle, which may (or may not) be installed.

Previous behavior:

  • For all Symfony versions: dump_assets = true.
  • Symfony == 2.8: break on deploy:assetic:dump (no assetic-bundle by default).
  • Symfony < 3: call app/console assetic:dump for task deploy:assetic:dump.
  • Symfony >= 3: call app/console assets:install via overridden deploy:assetic:dump task (this makes absolutely zero sense).

The above is inconsistent and incorrect behavior. New behavior:

  • For all versions dump_assets = false.
  • For all versions, call app/console assets:install for deploy:assets:install task.
  • For all versions, call app/console assetic:dump for task deploy:assetic:dump (if the user enables it via dump_assets = true).

Copy link
Contributor Author

@robfrawley robfrawley Jun 11, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The alternative to retain previous behavior and avoid a BC break is to define dump_assets = true in symfony.php and dump_assets = false in symfony3.php, but, this causes inconsistent behavior between the two recipes, which I assert is more confusing than fixing the inconsistency.

Also, while the above would avoid a BC break, it doesn't fix the bug for Symfony 2.8, which removed symfony/assetic-bundle from the default install and will break when including symfony.php during asset compilation.

@oanhnn Thoughts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about remove anything about assets from symfony recipe? This will break BC, but we can put in in v4.

Copy link
Contributor Author

@robfrawley robfrawley Jun 11, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is what I would do, actually. I don't think it should call deploy:assetic:dump. That would be a good move for v4 in my opinion.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, me neither. But a lot of people using it as it. Well be cool, to not break somethink for any guys :)

Copy link
Contributor Author

@robfrawley robfrawley Jun 11, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The one thing to keep in mind is the current solution is broken for Symfony 2.8. This solution makes the recipes compatible with all versions with the small tweak of people having to decide if they want assetic run via the bool env switch.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, may be fix it right in 3.x. Need to investigate a little. @oanhnn your thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@robfrawley I think you should split this problem to a PR, because it is break BC. We will discuss about it more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oanhnn Split what into a PR? There isn't really anything that can be separated from this PR. Can you elaborate?


// 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
Expand Down Expand Up @@ -60,48 +76,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 +137,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');