jalogut / magento2-deployer-plus

Tool based on deployer.org to perform zero downtime deployments of Magento 2 projects
GNU General Public License v3.0
200 stars 60 forks source link

Artifact symlinks and deploy mode #50

Closed stu177 closed 4 years ago

stu177 commented 4 years ago

Something I've noticed when building an artifact locally is if you're in developer mode, the artifact is built using the symlinks of your local environment. This casuses broken symlinks to be pushed to the remote.

I've been doing this to get around this issue:

// Put into production mode for artifact generation
task('mode:production', '{{bin/php}} {{current_path}}/{{magento_bin}} deploy:mode:set production -s')->once();
before('deploy:vendors', 'mode:production');

// Back to developer mode after artifact generation
task('mode:developer', '{{bin/php}} {{current_path}}/{{magento_bin}} deploy:mode:set developer -s')->once();
after('artifact:package', 'mode:developer');

Symlinks are set by the value for view_preprocessed in app/etc/di.xml:

<virtualType name="developerMaterialization" type="Magento\Framework\App\View\Asset\MaterializationStrategy\Factory">
    <arguments>
        <argument name="strategiesList" xsi:type="array">
            <item name="view_preprocessed" xsi:type="object">Magento\Framework\App\View\Asset\MaterializationStrategy\Symlink</item>
            <item name="default" xsi:type="object">Magento\Framework\App\View\Asset\MaterializationStrategy\Copy</item>
        </argument>
    </arguments>
</virtualType>

Which causes files in pub/static/adminhtml/Magento/backend/en_GB to be symlinks. I'm guessing symlinks are used in other places but this was the main issue for as it was breaking assets for the admin area.

Not sure if anyone else has had this issue and have any other solutions?

PauloPhagula commented 4 years ago

I used to have these too. In fact its not this packages fault. It is just how Magento works. In developer mode it uses symlinks for static assets. So if you create an artifact while in developer mode, when the package is "untared" elsewhere it will have invalid symlinks. The solution is just something in the lines of what the OP posted: get your site in production before deploy-artifacts.

osrecio commented 4 years ago

Thanks @dareenzo.

@stu177 you should have your local copy in production mode.

I recommend that you have a separate folder that is a copy of your project and that it is in production mode.

This way you will deploy from your new folder.