diff --git a/composer.json b/composer.json index 7adf3f22b..4a26ba956 100644 --- a/composer.json +++ b/composer.json @@ -48,6 +48,7 @@ "react/http": "^1.5", "symfony/console": "^5.4.9", "symfony/polyfill-php80": "^1.22", + "symfony/polyfill-php81": "^1.26", "symfony/process": "^5", "symfony/yaml": "^5" }, diff --git a/composer.lock b/composer.lock index db6d70ce2..3042e95e4 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "443f126c4b688aa349d3607009d03a20", + "content-hash": "2e4a876ba583ea7b5ddf4bebd46c0262", "packages": [ { "name": "evenement/evenement", @@ -1739,6 +1739,85 @@ ], "time": "2022-03-04T08:16:47+00:00" }, + { + "name": "symfony/polyfill-php81", + "version": "v1.26.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-php81.git", + "reference": "13f6d1271c663dc5ae9fb843a8f16521db7687a1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-php81/zipball/13f6d1271c663dc5ae9fb843a8f16521db7687a1", + "reference": "13f6d1271c663dc5ae9fb843a8f16521db7687a1", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.26-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ], + "psr-4": { + "Symfony\\Polyfill\\Php81\\": "" + }, + "classmap": [ + "Resources/stubs" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill backporting some PHP 8.1+ features to lower PHP versions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "polyfill", + "portable", + "shim" + ], + "support": { + "source": "https://github.com/symfony/polyfill-php81/tree/v1.26.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2022-05-24T11:49:31+00:00" + }, { "name": "symfony/process", "version": "v5.4.5", diff --git a/docs/recipe/magento2.md b/docs/recipe/magento2.md index 00d3f0972..5730f7864 100644 --- a/docs/recipe/magento2.md +++ b/docs/recipe/magento2.md @@ -127,10 +127,21 @@ in you deployer script. ### magento_themes -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L29) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L40) You can also set the themes to run against. By default it'll deploy all themes - `add('magento_themes', ['Magento/luma', 'Magento/backend']);` +If the themes are set as a simple list of strings, then all languages defined in [static_content_locales](/docs/recipe/magento2.md#static_content_locales) are +compiled for the given themes. +Alternatively The themes can be defined as an associative array, where the key represents the theme name and +the key contains the languages for the compilation (for this specific theme) +Example: +set('magento_themes', ['Magento/luma']); - Will compile this theme with every language from [static_content_locales](/docs/recipe/magento2.md#static_content_locales) +set('magento_themes', [ + 'Magento/luma' => null, - Will compile all languages from [static_content_locales](/docs/recipe/magento2.md#static_content_locales) for Magento/luma + 'Custom/theme' => 'en_US fr_FR' - Will compile only en_US and fr_FR for Custom/theme + 'Custom/another' => '[static_content_locales](/docs/recipe/magento2.md#static_content_locales) it_IT' - Will compile all languages from [static_content_locales](/docs/recipe/magento2.md#static_content_locales) + it_IT for Custom/another +]); - Will compile this theme with every language ```php title="Default value" [ @@ -139,8 +150,46 @@ all themes - `add('magento_themes', ['Magento/luma', 'Magento/backend']);` ``` +### static_deploy_options +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L45) + +Static content deployment options, e.g. '--no-parent' + + + +### split_static_deployment +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L48) + +Deploy frontend and adminhtml together as default + +```php title="Default value" +false +``` + + +### static_content_locales_backend +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L51) + +Use the default languages for the backend as default + +```php title="Default value" +'{{static_content_locales}}' +``` + + +### magento_themes_backend +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L55) + +backend themes to deploy. Only used if split_static_deployment=true +This setting supports the same options/structure as [magento_themes](/docs/recipe/magento2.md#magento_themes) + +```php title="Default value" +['Magento/backend' => null] +``` + + ### static_content_jobs -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L37) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L61) Also set the number of conccurent jobs to run. The default is 1 Update using: `set('static_content_jobs', '1');` @@ -151,7 +200,7 @@ Update using: `set('static_content_jobs', '1');` ### content_version -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L39) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L63) @@ -161,7 +210,7 @@ return time(); ### magento_dir -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L44) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L68) Magento directory relative to repository root. Use "." (default) if it is not located in a subdirectory @@ -171,7 +220,7 @@ Magento directory relative to repository root. Use "." (default) if it is not lo ### shared_files -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L47) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L71) Overrides [shared_files](/docs/recipe/deploy/shared.md#shared_files) from `recipe/deploy/shared.php`. @@ -186,7 +235,7 @@ Overrides [shared_files](/docs/recipe/deploy/shared.md#shared_files) from `recip ### shared_dirs -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L51) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L75) Overrides [shared_dirs](/docs/recipe/deploy/shared.md#shared_dirs) from `recipe/deploy/shared.php`. @@ -212,7 +261,7 @@ Overrides [shared_dirs](/docs/recipe/deploy/shared.md#shared_dirs) from `recipe/ ### writable_dirs -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L66) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L90) Overrides [writable_dirs](/docs/recipe/deploy/writable.md#writable_dirs) from `recipe/deploy/writable.php`. @@ -230,7 +279,7 @@ Overrides [writable_dirs](/docs/recipe/deploy/writable.md#writable_dirs) from `r ### clear_paths -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L73) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L97) Overrides [clear_paths](/docs/recipe/deploy/clear_paths.md#clear_paths) from `recipe/deploy/clear_paths.php`. @@ -249,7 +298,7 @@ Overrides [clear_paths](/docs/recipe/deploy/clear_paths.md#clear_paths) from `re ### bin/magento -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L82) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L106) @@ -259,7 +308,7 @@ Overrides [clear_paths](/docs/recipe/deploy/clear_paths.md#clear_paths) from `re ### magento_version -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L84) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L108) @@ -272,7 +321,7 @@ return $matches[0] ?? '2.0'; ### config_import_needed -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L91) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L115) :::info Autogenerated @@ -283,7 +332,7 @@ The value of this configuration is autogenerated on access. ### database_upgrade_needed -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L105) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L129) :::info Autogenerated @@ -294,7 +343,7 @@ The value of this configuration is autogenerated on access. ### enable_zerodowntime -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L120) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L144) Deploy without setting maintenance mode if possible @@ -304,7 +353,7 @@ true ### artifact_file -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L250) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L328) The file the artifact is saved to @@ -314,7 +363,7 @@ The file the artifact is saved to ### artifact_dir -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L253) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L331) The directory the artifact is saved in @@ -324,7 +373,7 @@ The directory the artifact is saved in ### artifact_excludes_file -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L257) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L335) Points to a file with a list of files to exclude from packaging. The format is as with the `tar --exclude-from=[file]` option @@ -335,7 +384,7 @@ The format is as with the `tar --exclude-from=[file]` option ### build_from_repo -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L260) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L338) If set to true, the artifact is built from a clean copy of the project repository instead of the current working directory @@ -345,7 +394,7 @@ false ### repository -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L263) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L341) Overrides [repository](/docs/recipe/common.md#repository) from `recipe/common.php`. @@ -357,7 +406,7 @@ null ### artifact_path -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L266) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L344) The relative path to the artifact file. If the directory does not exist, it will be created @@ -370,7 +419,7 @@ return get('artifact_dir') . '/' . get('artifact_file'); ### bin/tar -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L274) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L352) The location of the tar command. On MacOS you should have installed gtar, as it supports the required settings :::info Autogenerated @@ -381,14 +430,14 @@ The value of this configuration is autogenerated on access. ### additional_shared_files -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L346) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L424) Array of shared files that will be added to the default shared_files without overriding ### additional_shared_dirs -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L348) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L426) Array of shared directories that will be added to the default shared_dirs without overriding @@ -398,7 +447,7 @@ Array of shared directories that will be added to the default shared_dirs withou ## Tasks ### magento:compile -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L130) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L154) Compiles magento di. @@ -410,7 +459,7 @@ e.g. ### magento:deploy:assets -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L156) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L180) Deploys assets. @@ -436,8 +485,24 @@ in `app/etc/config.php`, e.g.: ``` +### magento:deploy:assets:adminhtml +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L194) + +Deploys assets for backend only. + + + + +### magento:deploy:assets:frontend +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L199) + +Deploys assets for frontend only. + + + + ### magento:sync:content_version -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L169) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L247) Syncs content version. @@ -445,7 +510,7 @@ Syncs content version. ### magento:maintenance:enable -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L179) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L257) Enables maintenance mode. @@ -453,7 +518,7 @@ Enables maintenance mode. ### magento:maintenance:disable -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L185) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L263) Disables maintenance mode. @@ -461,7 +526,7 @@ Disables maintenance mode. ### magento:maintenance:enable-if-needed -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L191) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L269) Set maintenance mode if needed. @@ -469,7 +534,7 @@ Set maintenance mode if needed. ### magento:config:import -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L198) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L276) Config Import. @@ -477,7 +542,7 @@ Config Import. ### magento:upgrade:db -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L207) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L285) Upgrades magento database. @@ -485,7 +550,7 @@ Upgrades magento database. ### magento:cache:flush -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L216) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L294) Flushes Magento Cache. @@ -493,7 +558,7 @@ Flushes Magento Cache. ### deploy:magento -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L221) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L299) Magento2 deployment operations. @@ -510,7 +575,7 @@ This task is group task which contains next tasks: ### magento:build -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L231) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L309) Magento2 build operations. @@ -523,7 +588,7 @@ This task is group task which contains next tasks: ### deploy -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L237) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L315) Deploys your project. @@ -539,7 +604,7 @@ This task is group task which contains next tasks: ### artifact:package -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L285) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L363) Packages all relevant files in an artifact. @@ -547,7 +612,7 @@ Packages all relevant files in an artifact. ### artifact:upload -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L295) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L373) Uploads artifact in release folder for extraction. @@ -555,7 +620,7 @@ Uploads artifact in release folder for extraction. ### artifact:extract -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L300) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L378) Extracts artifact in release path. @@ -563,7 +628,7 @@ Extracts artifact in release path. ### build:remove-generated -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L306) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L384) Clears generated files prior to building. @@ -571,7 +636,7 @@ Clears generated files prior to building. ### build:prepare -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L311) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L389) Prepare local artifact build. @@ -579,7 +644,7 @@ Prepare local artifact build. ### artifact:build -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L336) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L414) Builds an artifact. @@ -596,7 +661,7 @@ This task is group task which contains next tasks: ### deploy:additional-shared -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L352) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L430) Adds additional files and dirs to the list of shared files and dirs. @@ -604,7 +669,7 @@ Adds additional files and dirs to the list of shared files and dirs. ### artifact:prepare -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L359) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L437) Prepares an artifact on the target server. @@ -624,7 +689,7 @@ This task is group task which contains next tasks: ### artifact:finish -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L372) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L450) Executes the tasks after artifact is released. @@ -639,7 +704,7 @@ This task is group task which contains next tasks: ### artifact:deploy -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L380) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L458) Actually releases the artifact deployment. diff --git a/recipe/magento2.php b/recipe/magento2.php index 073abc628..cddace645 100644 --- a/recipe/magento2.php +++ b/recipe/magento2.php @@ -4,7 +4,7 @@ require_once __DIR__ . '/common.php'; require_once __DIR__ . '/../contrib/cachetool.php'; - +use Deployer\Exception\ConfigurationException; use Deployer\Exception\GracefulShutdownException; use Deployer\Exception\RunException; use Deployer\Host\Host; @@ -26,10 +26,34 @@ // You can also set the themes to run against. By default it'll deploy // all themes - `add('magento_themes', ['Magento/luma', 'Magento/backend']);` +// If the themes are set as a simple list of strings, then all languages defined in {{static_content_locales}} are +// compiled for the given themes. +// Alternatively The themes can be defined as an associative array, where the key represents the theme name and +// the key contains the languages for the compilation (for this specific theme) +// Example: +// set('magento_themes', ['Magento/luma']); - Will compile this theme with every language from {{static_content_locales}} +// set('magento_themes', [ +// 'Magento/luma' => null, - Will compile all languages from {{static_content_locales}} for Magento/luma +// 'Custom/theme' => 'en_US fr_FR' - Will compile only en_US and fr_FR for Custom/theme +// 'Custom/another' => '{{static_content_locales}} it_IT' - Will compile all languages from {{static_content_locales}} + it_IT for Custom/another +// ]); - Will compile this theme with every language set('magento_themes', [ ]); +// Static content deployment options, e.g. '--no-parent' +set('static_deploy_options', ''); + +// Deploy frontend and adminhtml together as default +set('split_static_deployment', false); + +// Use the default languages for the backend as default +set('static_content_locales_backend', '{{static_content_locales}}'); + +// backend themes to deploy. Only used if split_static_deployment=true +// This setting supports the same options/structure as {{magento_themes}} +set('magento_themes_backend', ['Magento/backend' => null]); + // Configuration // Also set the number of conccurent jobs to run. The default is 1 @@ -154,17 +178,71 @@ // ``` desc('Deploys assets'); task('magento:deploy:assets', function () { - $themesToCompile = ''; - if (count(get('magento_themes')) > 0) { + if (get('split_static_deployment')) { + invoke('magento:deploy:assets:adminhtml'); + invoke('magento:deploy:assets:frontend'); + } elseif (count(get('magento_themes')) > 0 ) { foreach (get('magento_themes') as $theme) { $themesToCompile .= ' -t ' . $theme; } + 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}}"); } +}); + +desc('Deploys assets for backend only'); +task('magento:deploy:assets:adminhtml', function () { + magentoDeployAssetsSplit('backend'); +}); - run("{{bin/php}} {{bin/magento}} setup:static-content:deploy --content-version={{content_version}} {{static_content_locales}} $themesToCompile -j {{static_content_jobs}}"); +desc('Deploys assets for frontend only'); +task('magento:deploy:assets:frontend', function () { + magentoDeployAssetsSplit('frontend'); }); +/** + * @phpstan-param 'frontend'|'backend' $area + * + * @throws ConfigurationException + */ +function magentoDeployAssetsSplit(string $area) +{ + if (!in_array($area, ['frontend', 'backend'], true)) { + throw new ConfigurationException("\$area must be either 'frontend' or 'backend', '$area' given"); + } + + $isFrontend = $area === 'frontend'; + $suffix = $isFrontend + ? '' + : '_backend'; + + $themesConfig = get("magento_themes$suffix"); + $defaultLanguages = get("static_content_locales$suffix"); + $useDefaultLanguages = array_is_list($themesConfig); + + /** @var list $themes */ + $themes = $useDefaultLanguages + ? array_values($themesConfig) + : array_keys($themesConfig); + + $staticContentArea = $isFrontend + ? 'frontend' + : 'adminhtml'; + + if ($useDefaultLanguages) { + $themes = '-t '.implode(' -t ', $themes); + + run("{{bin/php}} {{release_or_current_path}}/bin/magento setup:static-content:deploy -f --area=$staticContentArea --content-version={{content_version}} {{static_deploy_options}} $defaultLanguages $themes -j {{static_content_jobs}}"); + return; + } + + foreach ($themes as $theme) { + $languages = parse($themesConfig[$theme] ?? $defaultLanguages); + + run("{{bin/php}} {{release_or_current_path}}/bin/magento setup:static-content:deploy -f --area=$staticContentArea --content-version={{content_version}} {{static_deploy_options}} $languages -t $theme -j {{static_content_jobs}}"); + } +} + desc('Syncs content version'); task('magento:sync:content_version', function () { $timestamp = time();