deployer
deployer copied to clipboard
Add another check for setup:upgrade
I have added another check if the setup:upgrade command is needed to be run.
As stated on the command class module:config:status if it fails you have to run the setup:upgrade command.
@peterjaap could you please take a look at this?
@peterjaap @lamasfoker is this still required ?
This exception is thrown also on the latest magento 2 version, so yes.
@lamasfoker thanks for your contribution ! Can you update the doc through a new commit ? Looks like that's blocking the pull request checks
Done
Since this change is included, we're facing issues with modules, which are only a dev requirement in the composer.json file.
I debugged that in \Magento\Setup\Console\Command\ModuleConfigStatusCommand::execute and found out, that these modules are somehow included in the $currentModuleConfig, but not in $correctModuleConfig.
This way, setup:upgrade is run in every deployment, which leads to unneeded downtimes.
Does someone see a good way of fixing that?
@norgeindian I do not have this issue. Do you have any examples of magento modules required only on dev? Perhaps you are running composer install without --no-dev parameter on your CI/CD?
@lamasfoker, we have a few modules, which we only use locally.
So for example https://github.com/ho-nl/magento2-Ho_Templatehints.
This is definitely something you only want locally and don't need on a live server.
That means, that we have an entry in the config.php like this:
'Ho_Templatehints' => 1
As soon as we deploy, Magento sees, that this module is in the config.php, but it's not used in the code.
In earlier times, we used https://github.com/jalogut/magento2-deployer-plus/blob/a8c4432a68a4ac442541f250577e6049abaed52b/recipe/magento_2_2/config.php#L43, where the modules were removed one by one, but until now, this was not needed anymore.
How do you maintain your config.php?
To reproduce my issue, please include the module I mentioned above in your require-dev section of your composer.json, run setup:upgrade to make sure, that it is locally added to the config.php file and try to deploy.
Then you should face the same issue as we do. The check always returns the information, that maintenance should be enabled and setup:upgrade should be run.
I already tried your --no-dev approach, but that did not help, as the problematic point is the config.php. The modules are correctly not installed, like I expect it to be.
@lamasfoker , were you able to reproduce this issue on your end the way I wrote or is it actually something else, which is related to our project setup?
Sorry for the late replay.
How do you maintain your config.php?
We add app/etc/config.php as shared_files and we do not include it in GIT. I pasted below our recipe from one of our magento 2 installation. The deployer version is 7.3.0 so without this PR that was released with 7.4.0
<?php
namespace Deployer;
use Deployer\Exception\RunException;
const CONFIG_PHP_UPDATE_NEEDED_EXIT_CODE = 1;
require 'recipe/magento2.php';
set('clear_paths', [
'{{magento_dir}}/pub/static/_cache/*',
'{{magento_dir}}/var/generation/*',
'{{magento_dir}}/var/cache/*',
'{{magento_dir}}/var/page_cache/*',
'{{magento_dir}}/var/view_preprocessed/*'
]);
set('keep_releases', 5);
add('shared_files', ['pub/.htaccess', 'pub/.htusers', 'pub/robots.txt', 'app/etc/env.php', 'var/.maintenance.ip', '.env.local', 'app/etc/config.php']);
add('shared_dirs', ['bash/bin/logs', 'pub/ariap-downloads']);
set('artifact_file', 'artifact.tar.gz');
set('artifact_dir', '.');
set('cachetool_url', 'https://github.com/gordalina/cachetool/releases/download/9.0.0/cachetool.phar');
desc('Remove jobs of bin/magento queue:consumers:start');
task('magento:remove-append-consumers', function () {
run("ps -ef | grep 'bin/magento queue:consumers:start' | grep -v grep | awk '{print $2}' | xargs -r kill -9");
});
desc('Kill running magento cron job');
task('magento:kill-running-cron-job', function () {
run("ps -ef | grep 'bin/magento cron:run' | grep -v grep | awk '{print $2}' | xargs -r kill -9");
run("ps -ef | grep 'bin/magento ariap:erp:customer:sync --all' | grep -v grep | awk '{print $2}' | xargs -r kill -9");
});
desc('Switch magento cron');
task('magento:switch-cron', function () {
run('{{release_path}}/cronjob_switcher.sh');
});
set('database_upgrade_needed', function () {
// detect if setup:upgrade is needed
try {
run('{{bin/php}} {{bin/magento}} setup:db:status');
} catch (RunException $e) {
if ($e->getExitCode() == DB_UPDATE_NEEDED_EXIT_CODE) {
return true;
}
throw $e;
}
try {
run('{{bin/php}} {{bin/magento}} module:config:status');
} catch (RunException $e) {
if ($e->getExitCode() == CONFIG_PHP_UPDATE_NEEDED_EXIT_CODE) {
return true;
}
throw $e;
}
return false;
});
desc('Deploy your project');
task('deploy', [
'deploy:info',
'deploy:setup',
'deploy:lock',
'deploy:release',
'artifact:upload',
'artifact:extract',
'deploy:shared',
'deploy:clear_paths',
'magento:switch-cron',
'magento:kill-running-cron-job',
'magento:maintenance:enable-if-needed',
'magento:upgrade:db',
'magento:maintenance:disable',
'deploy:symlink',
'magento:switch-cron',
'magento:remove-append-consumers',
'magento:cache:flush',
'cachetool:clear:opcache',
'deploy:cleanup',
'deploy:unlock',
'deploy:success',
]);
after('deploy:failed', 'deploy:unlock');