Magento 2 Recipe: Fix import needed after deployment failure during upgrade #4180#4181
Magento 2 Recipe: Fix import needed after deployment failure during upgrade #4180#4181carlos-reynosa wants to merge 4 commits intodeployphp:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a dedicated Magento 2 post-failure hook so that additional recovery steps (config import + maintenance disable) run when a deployment fails—intended to keep Magento configuration consistent after a failed upgrade/deploy attempt.
Changes:
- Replaces the direct
magento:maintenance:disablefailure hook with a new grouped taskdeploy:magento:failed. - Adds
deploy:magento:failedtask to runmagento:config:importand then disable maintenance mode. - Regenerates Magento 2 recipe documentation to include the new task and updated source line references.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
recipe/magento2.php |
Introduces deploy:magento:failed and wires it to deploy:failed for Magento-specific recovery steps. |
docs/recipe/magento2.md |
Updates autogenerated docs to reflect the new task and shifted source line numbers. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| task('deploy:magento:failed', [ | ||
| 'magento:config:import', | ||
| 'magento:maintenance:disable', | ||
| ]); | ||
|
|
There was a problem hiding this comment.
deploy:magento:failed runs magento:config:import, but that task resolves {{bin/magento}} via {{release_or_current_path}}. On failures that occur before deploy:symlink, the {{deploy_path}}/release symlink still exists and points to the new/failed release (see recipe/deploy/release.php + recipe/deploy/symlink.php), so the config status/import will run against the failed release instead of the still-active current release—this doesn’t restore configuration after a failed upgrade.
Consider making the failure path explicitly run config status/import against {{current_path}} (or otherwise ensure release_or_current_path resolves to current_path here) and guard it so the deploy:failed hook remains best-effort even if Magento isn’t runnable in the release directory.
| task('deploy:magento:failed', [ | |
| 'magento:config:import', | |
| 'magento:maintenance:disable', | |
| ]); | |
| task('deploy:magento:failed', function () { | |
| $hadReleaseOrCurrentPath = false; | |
| $originalReleaseOrCurrentPath = null; | |
| if (has('release_or_current_path')) { | |
| $hadReleaseOrCurrentPath = true; | |
| $originalReleaseOrCurrentPath = get('release_or_current_path'); | |
| } | |
| // Ensure that config import on failure is run against the active current release, | |
| // not the (possibly broken) new release. | |
| set('release_or_current_path', '{{current_path}}'); | |
| try { | |
| invoke('magento:config:import'); | |
| } catch (RunException $exception) { | |
| // Best-effort: ignore failures during rollback config import. | |
| } catch (GracefulShutdownException $exception) { | |
| // Best-effort: ignore failures during rollback config import. | |
| } | |
| // Restore original release_or_current_path configuration if it existed before. | |
| if ($hadReleaseOrCurrentPath) { | |
| set('release_or_current_path', $originalReleaseOrCurrentPath); | |
| } | |
| try { | |
| invoke('magento:maintenance:disable'); | |
| } catch (RunException $exception) { | |
| // Best-effort: ignore failures when disabling maintenance mode on failure. | |
| } catch (GracefulShutdownException $exception) { | |
| // Best-effort: ignore failures when disabling maintenance mode on failure. | |
| } | |
| }); |
| after('deploy:failed', 'deploy:magento:failed'); | ||
|
|
||
| //Run Magento Deployment Failure Tasks | ||
| desc('Run magento post deployment failure tasks.'); |
There was a problem hiding this comment.
Minor grammar/style: desc('Run magento post deployment failure tasks.') reads a bit awkwardly and uses inconsistent capitalization vs other Magento task descriptions in this recipe. Consider rephrasing (e.g., “Run Magento post-deployment failure tasks”) so the generated docs/help text is polished.
| desc('Run magento post deployment failure tasks.'); | |
| desc('Run Magento post-deployment failure tasks'); |
| after('deploy:failed', 'magento:maintenance:disable'); | ||
| after('deploy:failed', 'deploy:magento:failed'); | ||
|
|
||
| //Run Magento Deployment Failure Tasks |
There was a problem hiding this comment.
The inline //Run Magento Deployment Failure Tasks comment is being pulled into the autogenerated docs as a separate paragraph (see the new “Run Magento Deployment Failure Tasks” line in docs/recipe/magento2.md), which makes the docs a bit redundant/noisy. Consider either removing this comment or converting it into a clearer desc(...)/documentation text so docgen output stays clean.
| //Run Magento Deployment Failure Tasks |
Pull request to ensure that if the magento deployment fails and the release is reverted the configuration is properly imported. Deployments mail fail during upgrade and after new configuration has been imported.
Fixes #4180