deployphp / deployer

The PHP deployment tool with support for popular frameworks out of the box
https://deployer.org
MIT License
10.65k stars 1.49k forks source link

Magento 2, ofthen a second deploy needed to work without errors #3863

Closed Aquive closed 2 months ago

Aquive commented 4 months ago

Very often we need to do a second deploy to make magento 2 working again after a first "succesfull" deploy. (The deploy is succesfull but Magento throws an erros, see below). I am not exactly sure when this problem occurs but I think it happens when enabling a previously disabled module.

This time it was this error. The CSP module was disabled, and with this deploy it was being enabled.

There has been an error processing your request
Warning: Undefined array key "policy_id"
in /vendor/magento/module-csp/Model/Collector/ConfigCollector.php on line 111

Deploy.php

<?php
namespace Deployer;

require 'recipe/magento2.php';

// Config

set('repository', '<repo url>');
set('update_code_strategy', 'clone');
set('writable_mode', 'chmod');
set('keep_releases', 3);

add('shared_files', []);
add('shared_dirs', [
    'pub/feeds',
    'pub/blog',
    'pub/sitemaps'
]);
add('writable_dirs', []);

// Languages
set('static_content_locales', 'nl_NL');
set('magento_themes', [
    'Aqm/Luma',
    ]);
set('magento_themes_backend', ['Magento/backend']);
set('static_deploy_options', '--no-parent');
set('static_content_locales_backend', 'en_US nl_NL');
set('split_static_deployment', true);

// Hosts
host('production')
    ->set('hostname', '<host>')
    ->set('remote_user', 'app')
    ->set('deploy_path', '<path>');

// Hooks

after('deploy:failed', 'deploy:unlock');

Upvote & Fund

Fund with Polar

peterjaap commented 4 months ago

Is in this case the module already in config.php as enabled or isn't it in the config.php and enables setup:upgrade it on deploy?

Aquive commented 4 months ago

Hey @peterjaap thanks for your fast reply. It is deployed after running/testing/commiting everything locally. So the module is present in config.php with a 1 (enabled) like below.

'Magento_Csp' => 1,

This is just an example. We experience sometimes a second deploy is needed. I am not sure if it is allways when enabling a module. It might be the case in other situations too. I will pay attention and check it from now on.

LouisdeLooze commented 3 months ago

Hi @Aquive, No idea if you still have this issue, but I had similar issues (more specifically about missing classes). I fixed it by using rotating cache prefixes, as explained here. Hope this helps!

Aquive commented 2 months ago

I didn't came accross it too often lately, but it is good to know there is a possible solution. I will test it out when I encounter it again.

Btw, any idea why this is not default? Does it come at a cost?

github-actions[bot] commented 2 months ago

This issue has been automatically closed. Please, open a discussion for bug reports and feature requests.

Read more: [https://github.com/deployphp/deployer/discussions/3888]

github-actions[bot] commented 2 months ago

This issue has been automatically closed. Please, open a discussion for bug reports and feature requests.

Read more: [https://github.com/deployphp/deployer/discussions/3888]