CLI і деплой

← CLI і деплой

Ashterix

feat(seo): og:image size for front matter images; short titles and explicit descriptions for From Magento to Symfony

uk/articles/magento-to-symfony/infrastructure/cli.md +2 −1

CLI і деплой

bin/magento побудований на Symfony Console, тож команди в bin/console пишуться майже так само. Нижче — відповідники команд і типовий деплой у prod.

bin/magento bin/console Примітка
cache:flush, cache:clean cache:clear; cache:pool:clear cache.app Системний кеш і дані — різні речі.
setup:upgrade doctrine:migrations:migrate Лише схема й дані з міграцій.
setup:db-declaration:generate-whitelist make:migration, doctrine:migrations:diff Генерує клас міграції.
setup:di:compile cache:warmup У prod виконується під час cache:clear.
deploy:mode:set production APP_ENV=prod, APP_DEBUG=0 Плюс composer dump-env prod.
module:enable / module:status config/bundles.php; about about показує версію, середовище, шляхи.
dev:di:info debug:container, debug:autowiring Плюс lint:container.
config:show debug:config, config:dump-reference Фактичні значення і всі можливі опції.
— debug:router, router:match Маршрути.
— debug:event-dispatcher Слухачі з пріоритетами.
queue:consumers:start messenger:consume async Після деплою: messenger:stop-workers.
cron:run messenger:consume scheduler_default Або системний cron.
indexer:reindex ваша команда Індексаторів немає.
admin:user:create ваша команда, fixtures Користувачі — ваша сутність.
— make:controller, make:entity, make:crud, make:command MakerBundle генерує заготовки.
— lint:yaml, lint:container, doctrine:schema:validate Варто запускати в CI.

Magento · команда

class ImportCommand extends Command
{
    protected function configure(): void
    {
        $this->setName('vendor:faq:import');
    }
    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        return Command::SUCCESS;
    }
}
// + реєстрація в di.xml у CommandList

Symfony · команда (той самий Console)

#[AsCommand(name: 'app:faq:import', description: 'Import FAQ from CSV')]
final class ImportCommand extends Command
{
    public function __construct(private Importer $importer)
    {
        parent::__construct();
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $io = new SymfonyStyle($input, $output);
        $io->success('Imported');
        return Command::SUCCESS;
    }
}
// реєстрації не треба: autoconfigure

Деплой у prod

Symfony · типова послідовність

composer install --no-dev --optimize-autoloader
composer dump-env prod
APP_ENV=prod bin/console cache:clear          # і прогріває кеш
bin/console doctrine:migrations:migrate --no-interaction
bin/console messenger:stop-workers             # supervisor підніме воркери з новим кодом