deployphp / deployer

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

magento 2 recipe error on deploy assets #3650

Open ithuis opened 11 months ago

ithuis commented 11 months ago

Deployer version: 7.3.1 Deployment OS: linux

namespace Deployer;

require 'recipe/magento2.php';

// Config

set('repository', 'test');

add('shared_files', []);
add('shared_dirs', []);
add('writable_dirs', []);

set('static_content_locales', 'en_US nl_NL');

// Hosts
host('live')
    ->set('hostname', 'xxx.xxx.xxx.xxx')
    ->set('branch', 'test')
    ->set('remote_user', 'test')
    ->set('deploy_path', '/var/www/test');

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

this is my deployer for my new project running the latest magento 2. but during the deploy in the step magento:deploy:assets i get the error

[live]  error  in magento2.php on line 197:
[live] run /usr/bin/php /var/www/test/releases/7/bin/magento setup:static-content:deploy --content-version=1690207325  en_US  -j 1
[live] err Error happened during deploy process: Type Error occurred when creating object: Magento\Deploy\Source\SourcePool, Magento\Deploy\Source\SourcePool::__construct(): Argument #1 ($sources) must be of type array, null given, called in /var/www/test/releases/7/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php on line 121

Upvote & Fund

Fund with Polar

piotrkwiecinski commented 11 months ago

It fails because you're missing part of the required configuration on magento side. You have to run:

bin/magento app:config:dump scopes themes

This is going to add additional configuration to your app/etc/config.php which is required for static content deployment to work in a pipeline.

You may want to add this to app/etc/config.php too:

'system' => [
    'default' => [
        'dev' => [
            'js' => [
                'merge_files' => '1',
                'minify_files' => '1'
            ],
            'css' => [
                'merge_files' => '1',
                'minify_files' => '1'
            ],
            'template' => [
                'minify_html' => '1'
            ]
        ]
    ]

As referred in https://deployer.org/docs/7.x/recipe/magento2#magentodeployassets

piotrkwiecinski commented 11 months ago

You may also want to check this article https://www.michiel-gerritsen.com/deploying-magento-using-deployer-and-github-actions