deployer/recipe/symfony.php
Tobias Schultze 239b817540
Fix symfony cache:clear running twice on deployment (#2602)
* Fix symfony cache:clear running twice on deployment

Any standard symfony app is running cache:clear on composer install ever since.
I.e. in composer.json

```
"scripts": {
    "auto-scripts": {
      "cache:clear": "symfony-cmd",
      "assets:install %PUBLIC_DIR%": "symfony-cmd"
    },
    "post-install-cmd": [
      "@auto-scripts"
    ],
    "post-update-cmd": [
      "@auto-scripts"
    ]
  },
```

This prevents cache clearing being run twice for no reason.

* regenerate doc
2021-07-15 23:20:44 +03:00

61 lines
1.4 KiB
PHP

<?php
namespace Deployer;
require_once __DIR__ . '/common.php';
add('recipes', ['symfony']);
set('symfony_version', function () {
$result = run('{{bin/console}} --version');
preg_match_all('/(\d+\.?)+/', $result, $matches);
return $matches[0][0] ?? 5.0;
});
set('shared_dirs', [
'var/log',
'var/sessions'
]);
set('shared_files', [
'.env.local'
]);
set('writable_dirs', [
'var'
]);
set('migrations_config', '');
set('bin/console', '{{bin/php}} {{release_or_current_path}}/bin/console');
set('console_options', function () {
return '--no-interaction';
});
desc('Migrate database');
task('database:migrate', function () {
$options = '--allow-no-migration';
if (get('migrations_config') !== '') {
$options = "$options --configuration={{release_or_current_path}}/{{migrations_config}}";
}
run("cd {{release_or_current_path}} && {{bin/console}} doctrine:migrations:migrate $options {{console_options}}");
});
desc('Clear cache');
task('deploy:cache:clear', function () {
// composer install scripts usually clear and warmup symfony cache
// so we only need to do it if composer install was run with --no-scripts
if (false !== strpos(get('composer_options', ''), '--no-scripts')) {
run('{{bin/console}} cache:clear {{console_options}}');
}
});
desc('Deploy project');
task('deploy', [
'deploy:prepare',
'deploy:vendors',
'deploy:cache:clear',
'deploy:publish',
]);