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 deploy not working with custom magento_dir #3843

Closed yuriy-boyko closed 2 months ago

yuriy-boyko commented 6 months ago
<?php
namespace Deployer;

require 'recipe/magento2.php';

set('magento_dir', 'src');
set('repository', 'git@github.com:example.git');

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

host('dev')
    ->set('hostname', '127.0.0.1')
    ->set('port', 22)
    ->set('remote_user', 'deployer')
    ->set('deploy_path', '~/www');

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


Task deploy:vendors and magento:deploy:assets fails.

The problem:

Task magento:deploy:assets is like this

run("{{bin/php}} {{release_or_current_path}}/bin/magento setup:static-content:deploy --content-version={{content_version}} {{static_deploy_options}} {{static_content_locales}} $themesToCompile -j {{static_content_jobs}}");

Should include somehow magento_dir if set:

run("{{bin/php}} {{release_or_current_path}}/{{magento_dir}}/bin/magento setup:static-content:deploy --content-version={{content_version}} {{static_deploy_options}} {{static_content_locales}} $themesToCompile -j {{static_content_jobs}}");

Same goes for deploy:vendors, the original is:

run('cd {{release_or_current_path}} && {{bin/composer}} {{composer_action}} {{composer_options}} 2>&1');

Correct one should include somehow magento_dir if set:

run('cd {{release_or_current_path}}/{{magento_dir}} && {{bin/composer}} {{composer_action}} {{composer_options}} 2>&1');



To make the deploy.php work anyway, my file starts like this:

<?php
namespace Deployer;

require 'recipe/magento2.php';
//https://deployer.org/docs/7.x/recipe/magento2#repository
// Config

set('magento_dir', 'src');

desc('Installs vendors');
task('deploy:vendors', function () {
    if (!commandExist('unzip')) {
        warning('To speed up composer installation setup "unzip" command with PHP zip extension.');
    }
    run('cd {{release_or_current_path}}/{{magento_dir}} && {{bin/composer}} {{composer_action}} {{composer_options}} 2>&1');
});

desc('Deploys assets');
task('magento:deploy:assets', function () {
    $themesToCompile = '';
    if (get('split_static_deployment')) {
        invoke('magento:deploy:assets:adminhtml');
        invoke('magento:deploy:assets:frontend');
    } else {
        if (count(get('magento_themes')) > 0 ) {
            foreach (get('magento_themes') as $theme) {
                $themesToCompile .= ' -t ' . $theme;
            }
        }
        run("{{bin/php}} {{release_or_current_path}}/{{magento_dir}}/bin/magento setup:static-content:deploy --content-version={{content_version}} {{static_deploy_options}} {{static_content_locales}} $themesToCompile -j {{static_content_jobs}}");
    }
});

Upvote & Fund

Fund with Polar

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]