MAD-I-T / magento-actions

Github deployment actions for Magento 2
MIT License
99 stars 35 forks source link

Build static content for languages other than en_US in AdminHTML #31

Closed Stevie-Ray closed 1 year ago

Stevie-Ray commented 1 year ago

I've read the article on and this works fine for my frontend but how do you achieve this for the Magento Admin?

'stores' => [
            'admin' => [
                'general' => [
                    'locale' => [
                        'code' => 'nl_NL'
                    ]
                ]
            ],
            'theme' => [
                'general' => [
                    'locale' => [
                        'code' => 'nl_NL'
                    ]
                ]
            ]
        ]
seyuf commented 1 year ago

Hi there,

Not sure i understood correctly your question but try putting this in your config.php ?

<?php
return [
   modules' => [
    //your modules
   ],
   'system' => [
        'stores' => [
            'default' => [
                'general' => [
                    'locale' => [
                        'code' => 'nl_NL'
                    ]
                ]
            ]
        ]
    ]

Or as marked in the post bin/magento config:set --lock-config --scope=stores --scope-code=default general/locale/code "nl_NL"

This will allow build for the frontend and the admin.

Stevie-Ray commented 1 year ago

Hi @seyuf,

My setup is configured not on a store level but in the default scope:

    'system' => [
        'default' => [
              'general' => [
                    'locale' => [
                        'code' => 'nl_NL'
                    ]
                ]

it doesn't seem to be looking at the default level, because my build only generates a en_US folder.. so i've added it to the store scope like the example (admin instead of default in my case) but without any luck.

seyuf commented 1 year ago

Just to make sure is your config as stated working on the local env? If so, are you committing the config.php file ? Also please provide the version of the magento-actions you're using as well as your magento version. Thanks

Stevie-Ray commented 1 year ago

Hi @seyuf ,

Here is the full config.php and main,yml that I use in my deployment process. Yes, it worked previously when I used Magento 2 Deployer Plus. I'm working with the latest v3.15 and Magento 2.4.5-p1

<?php
return [
    'modules' => [
        'Magento_Store' => 1,
        'Magento_AdminAnalytics' => 1,
        'Magento_AdminNotification' => 1,
        'Magento_AdobeIms' => 1,
        'Magento_AdobeImsApi' => 1,
        'Magento_AdobeStockAdminUi' => 1,
        'Magento_MediaGallery' => 1,
        'Magento_AdobeStockAssetApi' => 1,
        'Magento_AdobeStockClient' => 1,
        'Magento_AdobeStockClientApi' => 1,
        'Magento_AdobeStockImage' => 1,
        'Magento_Directory' => 1,
        'Magento_AdobeStockImageApi' => 1,
        'Magento_AdvancedPricingImportExport' => 1,
        'Magento_Theme' => 1,
        'Magento_Amqp' => 1,
        'Magento_Config' => 1,
        'Magento_Backend' => 1,
        'Magento_Authorization' => 1,
        'Magento_Eav' => 1,
        'Magento_Customer' => 1,
        'Magento_User' => 1,
        'Magento_Backup' => 1,
        'Magento_Indexer' => 1,
        'Magento_GraphQl' => 1,
        'Magento_BundleImportExport' => 1,
        'Magento_CacheInvalidate' => 1,
        'Magento_Variable' => 1,
        'Magento_Cms' => 1,
        'Magento_Rule' => 1,
        'Magento_Security' => 1,
        'Magento_CmsGraphQl' => 1,
        'Magento_EavGraphQl' => 1,
        'Magento_Search' => 1,
        'Magento_CatalogImportExport' => 1,
        'Magento_Catalog' => 1,
        'Magento_CatalogInventory' => 1,
        'Magento_CatalogPageBuilderAnalytics' => 1,
        'Magento_CatalogRule' => 1,
        'Magento_Msrp' => 1,
        'Magento_CatalogRuleGraphQl' => 1,
        'Magento_CatalogSearch' => 1,
        'Magento_CatalogUrlRewrite' => 1,
        'Magento_StoreGraphQl' => 1,
        'Magento_MediaStorage' => 1,
        'Magento_Quote' => 1,
        'Magento_SalesSequence' => 1,
        'Magento_CheckoutAgreementsGraphQl' => 1,
        'Magento_MediaGalleryUi' => 1,
        'Magento_CatalogGraphQl' => 1,
        'Magento_CmsPageBuilderAnalytics' => 1,
        'Magento_CmsUrlRewrite' => 1,
        'Magento_CmsUrlRewriteGraphQl' => 1,
        'Magento_CompareListGraphQl' => 1,
        'Magento_Integration' => 1,
        'Magento_Payment' => 1,
        'Magento_Sales' => 1,
        'Magento_QuoteGraphQl' => 1,
        'Magento_Checkout' => 1,
        'Magento_Contact' => 1,
        'Magento_Cookie' => 1,
        'Magento_Cron' => 1,
        'Magento_Csp' => 1,
        'Magento_Widget' => 1,
        'Magento_Robots' => 1,
        'Magento_Analytics' => 1,
        'Magento_Downloadable' => 1,
        'Magento_CustomerGraphQl' => 1,
        'Magento_CustomerImportExport' => 1,
        'Magento_Deploy' => 1,
        'Magento_Developer' => 1,
        'Magento_Dhl' => 1,
        'Magento_AdvancedSearch' => 1,
        'Magento_DirectoryGraphQl' => 1,
        'Magento_DownloadableGraphQl' => 1,
        'Magento_CustomerDownloadableGraphQl' => 1,
        'Magento_ImportExport' => 1,
        'Magento_Bundle' => 1,
        'Magento_CatalogCustomerGraphQl' => 1,
        'Magento_Elasticsearch' => 1,
        'Magento_Elasticsearch6' => 1,
        'Magento_Elasticsearch7' => 1,
        'Magento_Email' => 1,
        'Magento_EncryptionKey' => 1,
        'Magento_Fedex' => 1,
        'Magento_GiftMessage' => 1,
        'Magento_GiftMessageGraphQl' => 1,
        'Magento_GoogleAdwords' => 1,
        'Magento_GoogleAnalytics' => 1,
        'Magento_GoogleGtag' => 1,
        'Magento_Ui' => 1,
        'Magento_GoogleShoppingAds' => 1,
        'Magento_BundleGraphQl' => 1,
        'Magento_PageCache' => 1,
        'Magento_GroupedProduct' => 1,
        'Magento_GroupedImportExport' => 1,
        'Magento_GroupedCatalogInventory' => 1,
        'Magento_GroupedProductGraphQl' => 1,
        'Magento_DownloadableImportExport' => 1,
        'Magento_Captcha' => 1,
        'Magento_InstantPurchase' => 1,
        'Magento_CatalogAnalytics' => 1,
        'Magento_JwtFrameworkAdapter' => 1,
        'Magento_JwtUserToken' => 1,
        'Magento_LayeredNavigation' => 1,
        'Magento_LoginAsCustomer' => 1,
        'Magento_LoginAsCustomerAdminUi' => 1,
        'Magento_LoginAsCustomerApi' => 1,
        'Magento_LoginAsCustomerAssistance' => 1,
        'Magento_LoginAsCustomerFrontendUi' => 1,
        'Magento_LoginAsCustomerGraphQl' => 1,
        'Magento_LoginAsCustomerLog' => 1,
        'Magento_LoginAsCustomerPageCache' => 1,
        'Magento_LoginAsCustomerQuote' => 1,
        'Magento_LoginAsCustomerSales' => 1,
        'Magento_Marketplace' => 1,
        'Magento_MediaContent' => 1,
        'Magento_MediaContentApi' => 1,
        'Magento_MediaContentCatalog' => 1,
        'Magento_MediaContentCms' => 1,
        'Magento_MediaContentSynchronization' => 1,
        'Magento_MediaContentSynchronizationApi' => 1,
        'Magento_MediaContentSynchronizationCatalog' => 1,
        'Magento_MediaContentSynchronizationCms' => 1,
        'Magento_AdobeStockAsset' => 1,
        'Magento_MediaGalleryApi' => 1,
        'Magento_MediaGalleryCatalog' => 1,
        'Magento_MediaGalleryCatalogIntegration' => 1,
        'Magento_MediaGalleryCatalogUi' => 1,
        'Magento_MediaGalleryCmsUi' => 1,
        'Magento_MediaGalleryIntegration' => 1,
        'Magento_MediaGalleryMetadata' => 1,
        'Magento_MediaGalleryMetadataApi' => 1,
        'Magento_MediaGalleryRenditions' => 1,
        'Magento_MediaGalleryRenditionsApi' => 1,
        'Magento_MediaGallerySynchronization' => 1,
        'Magento_MediaGallerySynchronizationApi' => 1,
        'Magento_MediaGallerySynchronizationMetadata' => 1,
        'Magento_AdobeStockImageAdminUi' => 1,
        'Magento_MediaGalleryUiApi' => 1,
        'Magento_CatalogWidget' => 1,
        'Magento_MessageQueue' => 1,
        'Magento_ConfigurableProduct' => 1,
        'Magento_MsrpConfigurableProduct' => 1,
        'Magento_MsrpGroupedProduct' => 1,
        'Magento_Multishipping' => 1,
        'Magento_MysqlMq' => 1,
        'Magento_NewRelicReporting' => 1,
        'Magento_Newsletter' => 1,
        'Magento_NewsletterGraphQl' => 1,
        'Magento_OfflinePayments' => 1,
        'Magento_SalesRule' => 1,
        'Magento_Sitemap' => 1,
        'Magento_PageBuilder' => 1,
        'Magento_PageBuilderAnalytics' => 1,
        'Magento_GraphQlCache' => 1,
        'Magento_CardinalCommerce' => 1,
        'Magento_PaymentGraphQl' => 1,
        'Magento_Vault' => 1,
        'Magento_Paypal' => 1,
        'Magento_PaypalGraphQl' => 1,
        'Magento_Persistent' => 1,
        'Magento_ProductAlert' => 1,
        'Magento_ProductVideo' => 1,
        'Magento_CheckoutAgreements' => 1,
        'Magento_QuoteAnalytics' => 1,
        'Magento_QuoteBundleOptions' => 1,
        'Magento_QuoteConfigurableOptions' => 1,
        'Magento_QuoteDownloadableLinks' => 1,
        'Magento_ConfigurableProductGraphQl' => 1,
        'Magento_ReCaptchaAdminUi' => 1,
        'Magento_ReCaptchaCheckout' => 1,
        'Magento_ReCaptchaCheckoutSalesRule' => 1,
        'Magento_ReCaptchaContact' => 1,
        'Magento_ReCaptchaCustomer' => 1,
        'Magento_ReCaptchaFrontendUi' => 1,
        'Magento_ReCaptchaMigration' => 1,
        'Magento_ReCaptchaNewsletter' => 1,
        'Magento_ReCaptchaPaypal' => 1,
        'Magento_ReCaptchaReview' => 1,
        'Magento_ReCaptchaSendFriend' => 1,
        'Magento_ReCaptchaStorePickup' => 1,
        'Magento_ReCaptchaUi' => 1,
        'Magento_ReCaptchaUser' => 1,
        'Magento_ReCaptchaValidation' => 1,
        'Magento_ReCaptchaValidationApi' => 1,
        'Magento_ReCaptchaVersion2Checkbox' => 1,
        'Magento_ReCaptchaVersion2Invisible' => 1,
        'Magento_ReCaptchaVersion3Invisible' => 1,
        'Magento_ReCaptchaWebapiApi' => 1,
        'Magento_ReCaptchaWebapiGraphQl' => 1,
        'Magento_ReCaptchaWebapiRest' => 1,
        'Magento_ReCaptchaWebapiUi' => 1,
        'Magento_RelatedProductGraphQl' => 1,
        'Magento_ReleaseNotification' => 1,
        'Magento_RemoteStorage' => 1,
        'Magento_Reports' => 1,
        'Magento_RequireJs' => 1,
        'Magento_Review' => 1,
        'Magento_ReviewAnalytics' => 1,
        'Magento_ReviewGraphQl' => 1,
        'Magento_AwsS3' => 1,
        'Magento_Rss' => 1,
        'Magento_PageBuilderAdminAnalytics' => 1,
        'Magento_CatalogRuleConfigurable' => 1,
        'Magento_SalesAnalytics' => 1,
        'Magento_SalesGraphQl' => 1,
        'Magento_SalesInventory' => 1,
        'Magento_OfflineShipping' => 1,
        'Magento_ConfigurableProductSales' => 1,
        'Magento_UrlRewriteGraphQl' => 1,
        'Magento_CustomerAnalytics' => 1,
        'Magento_Securitytxt' => 1,
        'Magento_SendFriend' => 1,
        'Magento_SendFriendGraphQl' => 1,
        'Magento_Shipping' => 1,
        'Magento_AwsS3PageBuilder' => 1,
        'Magento_CatalogInventoryGraphQl' => 1,
        'Magento_CatalogCmsGraphQl' => 1,
        'Magento_Webapi' => 1,
        'Magento_SwaggerWebapi' => 1,
        'Magento_SwaggerWebapiAsync' => 1,
        'Magento_Swatches' => 1,
        'Magento_SwatchesGraphQl' => 1,
        'Magento_SwatchesLayeredNavigation' => 1,
        'Magento_Tax' => 1,
        'Magento_TaxGraphQl' => 1,
        'Magento_TaxImportExport' => 1,
        'Magento_AsynchronousOperations' => 1,
        'Magento_ThemeGraphQl' => 1,
        'Magento_Translation' => 1,
        'Magento_TwoFactorAuth' => 1,
        'Magento_GoogleOptimizer' => 1,
        'Magento_Ups' => 1,
        'Magento_UrlRewrite' => 1,
        'Magento_CatalogUrlRewriteGraphQl' => 1,
        'Magento_AdminAdobeIms' => 1,
        'Magento_Usps' => 1,
        'Magento_ConfigurableImportExport' => 1,
        'Magento_PaypalCaptcha' => 1,
        'Magento_VaultGraphQl' => 1,
        'Magento_Version' => 1,
        'Magento_Swagger' => 1,
        'Magento_WebapiAsync' => 1,
        'Magento_WebapiSecurity' => 1,
        'Magento_Weee' => 1,
        'Magento_WeeeGraphQl' => 1,
        'Magento_CurrencySymbol' => 1,
        'Magento_Wishlist' => 1,
        'Magento_WishlistAnalytics' => 1,
        'Magento_WishlistGraphQl' => 1
    ],
    'system' => [
        'default' => [
            'dev' => [
                'debug' => [
                    'debug_logging' => '0'
                ],
                'js' => [
                    'merge_files' => '1',
                    'minify_files' => '1',
                    'enable_js_bundling' => '0',
                    'enable_magepack_js_bundling' => '1'
                ],
                'css' => [
                    'minify_files' => '1',
                    'merge_css_files' => '1'
                ]
            ]
        ],
        'stores' => [
            'admin' => [
                'general' => [
                    'locale' => [
                        'code' => 'nl_NL'
                    ]
                ]
            ],
            'theme' => [
                'general' => [
                    'locale' => [
                        'code' => 'nl_NL'
                    ]
                ]
            ]
        ]
    ]
];

and main.yml

name: m2-actions-test

on: [push]

jobs:
  magento2-build:
    runs-on: ubuntu-latest
    name: 'm2 tests & build'
    services:
      mysql:
        image: docker://mysql:8.0
        env:
          MYSQL_ROOT_PASSWORD: magento
          MYSQL_DATABASE: magento
        ports:
          - 3306:3306
        options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
      elasticsearch:
        image: docker://elasticsearch:7.17.0
        ports:
          - 9200:9200
        options: -e="discovery.type=single-node" --health-cmd="curl http://localhost:9200/_cluster/health" --health-interval=10s --health-timeout=5s --health-retries=10
    steps:
    - uses: actions/checkout@v2

#    - name: 'this step starts static testing the code'
#      if: always()
#      uses: MAD-I-T/magento-actions@v3.15
#      env:
#        COMPOSER_AUTH: ${{secrets.COMPOSER_AUTH}}
#      with:
#        process: 'unit-test'
#        elasticsearch: 1
#
#    - name: 'launch magento2 static test'
#      if: always()
#      uses: MAD-I-T/magento-actions@v3.15
#      env:
#        COMPOSER_AUTH: ${{secrets.COMPOSER_AUTH}}
#      with:
#        process: 'static-test'
#        elasticsearch: 1

    - name: 'launch magento2 build'
      if: always()
      id: build
      uses: MAD-I-T/magento-actions@v3.15
      env:
        COMPOSER_AUTH: ${{secrets.COMPOSER_AUTH}}
      with:
        process: 'build'
        elasticsearch: 1

    - name: 'launch magento2 zero downtime deploy with no permission check'
      if: steps.build.outcome == 'success'
      uses: MAD-I-T/magento-actions@v3.15
      env:
        COMPOSER_AUTH: ${{secrets.COMPOSER_AUTH}}
        BUCKET_COMMIT: bucket-commit-${{github.sha}}.tar.gz
        MYSQL_ROOT_PASSWORD: magento
        MYSQL_DATABASE: magento
        HOST_DEPLOY_PATH: ${{secrets.STAGE_HOST_DEPLOY_PATH}}
        HOST_DEPLOY_PATH_BUCKET: ${{secrets.STAGE_HOST_DEPLOY_PATH}}/bucket
        SSH_PRIVATE_KEY: ${{secrets.STAGE_SSH_PRIVATE_KEY}}
        SSH_CONFIG: ${{secrets.STAGE_SSH_CONFIG}}
        WRITE_USE_SUDO: false
      with:
        deployer: 'no-permission-check'
        process: 'deploy-staging'

    - name: 'unlock deployer if fails'
      if: failure() || cancelled()
      uses: MAD-I-T/magento-actions@v3.15
      env:
        COMPOSER_AUTH: ${{secrets.COMPOSER_AUTH}}
        BUCKET_COMMIT: bucket-commit-${{github.sha}}.tar.gz
        MYSQL_ROOT_PASSWORD: magento
        MYSQL_DATABASE: magento
        HOST_DEPLOY_PATH: ${{secrets.STAGE_HOST_DEPLOY_PATH}}
        HOST_DEPLOY_PATH_BUCKET: ${{secrets.STAGE_HOST_DEPLOY_PATH}}/bucket
        SSH_PRIVATE_KEY: ${{secrets.STAGE_SSH_PRIVATE_KEY}}
        SSH_CONFIG: ${{secrets.STAGE_SSH_CONFIG}}
        WRITE_USE_SUDO: false
      with:
        process: 'cleanup-staging'

sidenote: Also, I had to remove the themes and scopes from the config.php because it breaks deployment

'themes' => [
    'frontend/Magento/blank' => [
        'parent_id' => null,
        'theme_path' => 'Magento/blank',
        'theme_title' => 'Magento Blank',
        'is_featured' => '0',
        'area' => 'frontend',
        'type' => '0',
        'code' => 'Magento/blank',
    ],
    'frontend/Magento/luma' => [
        'parent_id' => 'Magento/blank',
        'theme_path' => 'Magento/luma',
        'theme_title' => 'Magento Luma',
        'is_featured' => '0',
        'area' => 'frontend',
        'type' => '0',
        'code' => 'Magento/luma',
    ],
    'adminhtml/Magento/backend' => [
        'parent_id' => null,
        'theme_path' => 'Magento/backend',
        'theme_title' => 'Magento 2 backend',
        'is_featured' => '0',
        'area' => 'adminhtml',
        'type' => '0',
        'code' => 'Magento/backend',
    ],
    'frontend/Stevie/theme' => [
        'theme_path' => 'Stevie/theme',
        'theme_title' => 'Stevie Theme',
        'is_featured' => '0',
        'area' => 'frontend',
        'type' => '0',
        'code' => 'Stevie/theme',
    ],
],
'scopes' => [
    'websites' => [
        'admin' => [
            'website_id' => '0',
            'code' => 'admin',
            'name' => 'Admin',
            'sort_order' => '0',
            'default_group_id' => '0',
            'is_default' => '0',
        ],
        'base' => [
            'website_id' => '1',
            'code' => 'base',
            'name' => 'Stevie-Ray',
            'sort_order' => '0',
            'default_group_id' => '1',
            'is_default' => '1',
        ],
    ],
    'groups' => [
        0 => [
            'group_id' => '0',
            'website_id' => '0',
            'code' => 'default',
            'name' => 'Default',
            'root_category_id' => '0',
            'default_store_id' => '0',
        ],
        1 => [
            'group_id' => '1',
            'website_id' => '1',
            'code' => 'store',
            'name' => 'Stevie-Ray',
            'root_category_id' => '2',
            'default_store_id' => '2',
        ],
    ],
    'stores' => [
        'admin' => [
            'store_id' => '0',
            'code' => 'admin',
            'website_id' => '0',
            'group_id' => '0',
            'name' => 'Admin',
            'sort_order' => '0',
            'is_active' => '1',
        ],
        'theme' => [
            'store_id' => '2',
            'code' => 'theme',
            'website_id' => '1',
            'group_id' => '1',
            'name' => 'theme',
            'sort_order' => '0',
            'is_active' => '1',
        ],
    ],
]

Reason:

Processing configurations data from configuration file...
These Websites will be updated: Stevie-Ray
These Groups will be updated: Stevie-Ray
These Stores will be deleted: Default Store View
These Stores will be created: theme
Do you want to continue [yes/no]?
Import failed: Aborted.
seyuf commented 1 year ago

I was asking on the local machine, as i am not familiar with deployer plus, they may very well do some melding before the build & deploying. Our action follows native magento build process. In any case can you replace the stores part in your config by what i said? Just for testing. Cause i'm pretty sure there's an issue with what you're doing there as the admin is not a store per se unless (which seems to be the case) you've created a store called admin? In any case please replace:

'stores' => [
            'admin' => [
                'general' => [
                    'locale' => [
                        'code' => 'nl_NL'
                    ]
                ]
            ],
            'theme' => [
                'general' => [
                    'locale' => [
                        'code' => 'nl_NL'
                    ]
                ]
            ]
        ]

by

'stores' => [
            'default' => [
                'general' => [
                    'locale' => [
                        'code' => 'nl_NL'
                    ]
                ]
            ]
        ]

If this is still not working. I'll try it myself on a fresh 2.4.5-p1 and eventually update the actions in order to simplify the static build per multi language process.

Stevie-Ray commented 1 year ago

This is on my local machine, running: php bin/magento config:set --lock-config --scope=stores --scope-code=default general/locale/code "nl_NL" Will result in: The "default" value doesn't exist. Enter another value and try again.

Which makes sense as I renamed default to admin in the stores scope. I know my 'admin' store is store and the real adminhtml is not working this way. Fr now i "solved" the issue by not using the "default" scope only do this configuration in the "stores" scope which makes my admin (login page) switch back to en_US.

Screenshot 2022-10-22 at 11 18 42 Screenshot 2022-10-22 at 11 20 17
seyuf commented 1 year ago

I think your issue is deeper that it seems... In any case, i just updated the actions you can now proceed as follows to build multiple locales :

  - name: 'launch magento2 build'
      if: always()
      id: build
      uses: MAD-I-T/magento-actions@master
      env:
        COMPOSER_AUTH: ${{secrets.COMPOSER_AUTH}}
      with:
        process: 'build'
        elasticsearch: 1
        langs: 'nl_NL,en_US'

The above will build and deploy static files for both en and nl locales. Also if you just want to build nl locale, you can just remove the en part. Tell me is that works for you?

Stevie-Ray commented 1 year ago

@seyuf This is great! Keeping the build config outside of the Magento store and in the build process sounds way easier. Combining it with the stores method this will allow for a Magento Admin to build in lets say 'fr_FR,en_US' and a front-end as configured in config.php with even more languages.

I was also wondering if keep_releases in config/php-deployer/deploy.php can be a variable like {{ deploy_keep_builds }} and can be set as an ENV: KEEP_BUILDS which has a fallback to 3.. anyway this more of a feature request than an issue

Thanks again

seyuf commented 1 year ago

@Stevie-Ray i do agree, i had the same idea (shared internally)... Feel free to open an issue on the enhancement, i shall implement it soon enough. I plan to review the php-deploy recipe anyway.

Best