|
106 | 106 | '{{magento_dir}}/var/view_preprocessed/*', |
107 | 107 | ]); |
108 | 108 |
|
| 109 | +// WARNING: Do not use {{bin/magento}} in deploy:failed handlers - release_or_current_path points to the failed |
| 110 | +// release during failure, not the live one. Use {{current_path}} explicitly instead. |
| 111 | +// See: config_import_needed_on_current, magento:config:import:on-current, magento:maintenance:enable/disable. |
109 | 112 | set('bin/magento', '{{release_or_current_path}}/{{magento_dir}}/bin/magento'); |
110 | 113 |
|
111 | 114 | set('magento_version', function () { |
|
129 | 132 | return false; |
130 | 133 | }); |
131 | 134 |
|
| 135 | +set('config_import_needed_on_current', function () { |
| 136 | + // detect if app:config:import is needed on the current (live) release |
| 137 | + // do not use {{bin/magento}} as it resolves via release_or_current_path which is unreliable in failure scenarios |
| 138 | + try { |
| 139 | + run('{{bin/php}} {{current_path}}/{{magento_dir}}/bin/magento app:config:status'); |
| 140 | + } catch (RunException $e) { |
| 141 | + if ($e->getExitCode() == CONFIG_IMPORT_NEEDED_EXIT_CODE) { |
| 142 | + return true; |
| 143 | + } |
| 144 | + |
| 145 | + throw $e; |
| 146 | + } |
| 147 | + return false; |
| 148 | +}); |
| 149 | + |
132 | 150 | set('database_upgrade_needed', function () { |
133 | 151 | // detect if db upgrade is needed |
134 | 152 | try { |
@@ -318,6 +336,16 @@ function magentoDeployAssetsSplit(string $area) |
318 | 336 | } |
319 | 337 | }); |
320 | 338 |
|
| 339 | +desc('Config Import on current release'); |
| 340 | +task('magento:config:import:on-current', function () { |
| 341 | + if (get('config_import_needed_on_current')) { |
| 342 | + // do not use {{bin/magento}} as it must run on the current (last successful) release in failure scenarios |
| 343 | + run('{{bin/php}} {{current_path}}/{{magento_dir}}/bin/magento app:config:import --no-interaction'); |
| 344 | + } else { |
| 345 | + writeln('App config is up to date => import skipped'); |
| 346 | + } |
| 347 | +}); |
| 348 | + |
321 | 349 | desc('Upgrades magento database'); |
322 | 350 | task('magento:upgrade:db', function () { |
323 | 351 | if (get('database_upgrade_needed')) { |
@@ -374,7 +402,7 @@ function magentoDeployAssetsSplit(string $area) |
374 | 402 |
|
375 | 403 | desc('Run magento post deployment failure tasks.'); |
376 | 404 | task('deploy:magento:failed', [ |
377 | | - 'magento:config:import', |
| 405 | + 'magento:config:import:on-current', |
378 | 406 | 'magento:maintenance:disable', |
379 | 407 | ]); |
380 | 408 |
|
|
0 commit comments