deployer icon indicating copy to clipboard operation
deployer copied to clipboard

Magento 2 deploy not working with custom magento_dir

Open yuriy-boyko opened this issue 1 year ago • 0 comments
trafficstars

  • Deployer version: 7.4.0
  • Deployment OS: Ubuntu 22
<?php
namespace Deployer;

require 'recipe/magento2.php';

set('magento_dir', 'src');
set('repository', '[email protected]: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

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar

yuriy-boyko avatar May 30 '24 09:05 yuriy-boyko