Scaling Magento 2 on multiple containers in production with generated code The Next CEO of Stack OverflowMagento 2 docker image“Invalid Factory for nonexistent class” (setup:di:compile error)Magento2 Correct Sequence to flush all Caches/Static filesMagento 2 DevBox Beta CachingMagento 2: Getting “Warning: getimagesize(): Filename cannot be empty” after switching to a new empty theme with no parentMagento2 unit tests doesn't run using vendor/bin/phpunit or vendor/phpunit/phpunit/phpunitNot able to set Magento 2.2.2 to production modeMagento2 | Docker files permissions on Windows volumeMagento2: Missing commands on build serverDebugging “Invalid return type” in generated code?

How to count occurrences of text in a file?

Failed to fetch jessie backports repository

What happens if you roll doubles 3 times then land on "Go to jail?"

Is HostGator storing my password in plaintext?

How easy is it to start Magic from scratch?

I believe this to be a fraud - hired, then asked to cash check and send cash as Bitcoin

How do scammers retract money, while you can’t?

What does "Its cash flow is deeply negative" mean?

When airplanes disconnect from a tanker during air to air refueling, why do they bank so sharply to the right?

Natural language into sentence logic

What is the point of a new vote on May's deal when the indicative votes suggest she will not win?

Can a single photon have an energy density?

Describing a person. What needs to be mentioned?

How to make a software documentation "officially" citable?

Implement the Thanos sorting algorithm

Can the Reverse Gravity spell affect the Meteor Swarm spell?

Would this house-rule that treats advantage as a +1 to the roll instead (and disadvantage as -1) and allows them to stack be balanced?

Are there languages with no euphemisms?

Customer Requests (Sometimes) Drive Me Bonkers!

How to understand which control sequence in undefined in "Undefined control sequence." message?

How long to clear the 'suck zone' of a turbofan after start is initiated?

The King's new dress

Was a professor correct to chastise me for writing "Prof. X" rather than "Professor X"?

Which organization defines CJK Unified Ideographs?



Scaling Magento 2 on multiple containers in production with generated code



The Next CEO of Stack OverflowMagento 2 docker image“Invalid Factory for nonexistent class” (setup:di:compile error)Magento2 Correct Sequence to flush all Caches/Static filesMagento 2 DevBox Beta CachingMagento 2: Getting “Warning: getimagesize(): Filename cannot be empty” after switching to a new empty theme with no parentMagento2 unit tests doesn't run using vendor/bin/phpunit or vendor/phpunit/phpunit/phpunitNot able to set Magento 2.2.2 to production modeMagento2 | Docker files permissions on Windows volumeMagento2: Missing commands on build serverDebugging “Invalid return type” in generated code?










0















I'm working on some auto-scaling Kubernetes infrastructure to run Magento 2, and I noticed that when I start new containers, I can't have the generated/ directory automatically compiled as part of the container image build—it seems like it needs a working Magento installation (which I'm not guaranteed to have when building the container) to compile.



So currently what I'm doing is, when a new container starts up (e.g. when autoscaling, or when updating code, and new containers are replacing old ones):



  • Check if Magento is installed.

  • If it is installed, run:

    • bin/magento module:enable --all

    • bin/magento setup:di:compile


This seems to work okay, and the new container works just like the old/existing ones—if I don't do the compilation step, I just get lots of fatal exceptions until I do the compilation.



But my question is this: is there some other/better way of handling the generated/ directory when you want to run Magento on multiple hosts/containers?



Should I share the generated/ directory via NFS like I do for var/? It seems that reading code out of that directory would be a lot slower with NFS... and maybe the extra minute or so it takes to start a new container is worth the tradeoff to have each container compile/optimize it's own DI code (vs. sharing the directory with other existing containers).










share|improve this question


























    0















    I'm working on some auto-scaling Kubernetes infrastructure to run Magento 2, and I noticed that when I start new containers, I can't have the generated/ directory automatically compiled as part of the container image build—it seems like it needs a working Magento installation (which I'm not guaranteed to have when building the container) to compile.



    So currently what I'm doing is, when a new container starts up (e.g. when autoscaling, or when updating code, and new containers are replacing old ones):



    • Check if Magento is installed.

    • If it is installed, run:

      • bin/magento module:enable --all

      • bin/magento setup:di:compile


    This seems to work okay, and the new container works just like the old/existing ones—if I don't do the compilation step, I just get lots of fatal exceptions until I do the compilation.



    But my question is this: is there some other/better way of handling the generated/ directory when you want to run Magento on multiple hosts/containers?



    Should I share the generated/ directory via NFS like I do for var/? It seems that reading code out of that directory would be a lot slower with NFS... and maybe the extra minute or so it takes to start a new container is worth the tradeoff to have each container compile/optimize it's own DI code (vs. sharing the directory with other existing containers).










    share|improve this question
























      0












      0








      0








      I'm working on some auto-scaling Kubernetes infrastructure to run Magento 2, and I noticed that when I start new containers, I can't have the generated/ directory automatically compiled as part of the container image build—it seems like it needs a working Magento installation (which I'm not guaranteed to have when building the container) to compile.



      So currently what I'm doing is, when a new container starts up (e.g. when autoscaling, or when updating code, and new containers are replacing old ones):



      • Check if Magento is installed.

      • If it is installed, run:

        • bin/magento module:enable --all

        • bin/magento setup:di:compile


      This seems to work okay, and the new container works just like the old/existing ones—if I don't do the compilation step, I just get lots of fatal exceptions until I do the compilation.



      But my question is this: is there some other/better way of handling the generated/ directory when you want to run Magento on multiple hosts/containers?



      Should I share the generated/ directory via NFS like I do for var/? It seems that reading code out of that directory would be a lot slower with NFS... and maybe the extra minute or so it takes to start a new container is worth the tradeoff to have each container compile/optimize it's own DI code (vs. sharing the directory with other existing containers).










      share|improve this question














      I'm working on some auto-scaling Kubernetes infrastructure to run Magento 2, and I noticed that when I start new containers, I can't have the generated/ directory automatically compiled as part of the container image build—it seems like it needs a working Magento installation (which I'm not guaranteed to have when building the container) to compile.



      So currently what I'm doing is, when a new container starts up (e.g. when autoscaling, or when updating code, and new containers are replacing old ones):



      • Check if Magento is installed.

      • If it is installed, run:

        • bin/magento module:enable --all

        • bin/magento setup:di:compile


      This seems to work okay, and the new container works just like the old/existing ones—if I don't do the compilation step, I just get lots of fatal exceptions until I do the compilation.



      But my question is this: is there some other/better way of handling the generated/ directory when you want to run Magento on multiple hosts/containers?



      Should I share the generated/ directory via NFS like I do for var/? It seems that reading code out of that directory would be a lot slower with NFS... and maybe the extra minute or so it takes to start a new container is worth the tradeoff to have each container compile/optimize it's own DI code (vs. sharing the directory with other existing containers).







      magento2.2.2 code-generation docker containers






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 13 '18 at 21:17









      geerlingguygeerlingguy

      1145




      1145




















          1 Answer
          1






          active

          oldest

          votes


















          1














          Not sure why this question got downvoted; looking around the Internet there is precious little information about how people should run Magento 2 (Open Source or Enterprise) in a scalable, production, container environment, and there are a lot of little things that are a pain in the butt to handle.



          Relating to my question above, I am now compiling the code in the container build process, which seems to work okay; in the Dockerfile, after I've copied or cloned my Magento codebase into the container image:



          # Compile code.
          RUN magento module:enable --all
          && magento setup:di:compile


          That way I don't have to do that in an entrypoint script.



          However, I do still have to run something like the following in my entrypoint—at least after a fresh installation (and maybe also after new deployments):



          echo "Setting MAGE_MODE"
          magento deploy:mode:set $ENV_MODE --skip-compilation

          echo "Cleaning Magento Cache"
          magento cache:flush
          magento cache:clean

          echo "Ensuring permissions are correct on Magento folders - post install."
          CHOWN_PATHS_POST_INSTALL="app/etc generated pub/media pub/static var"
          chown -R www-data:www-data $CHOWN_PATHS_POST_INSTALL

          if [ "$ENV_MODE" = "production" ]; then
          echo "Compiling static assets."
          su -s /bin/bash -c "magento setup:static-content:deploy --jobs 4" www-data
          fi


          I'm still trying to figure out some other things, but I'm to the point where new containers can start in just a few seconds (still have to do things like chown -R www-data:www-data paths like app/etc and generated after the container starts, and copy/insert a templated app/etc/env.php file into place (to make sure all my site's settings are accounted for and can be driven by environment variables in the container so it's a true 12 factor app deployment).






          share|improve this answer























            Your Answer








            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "479"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f249917%2fscaling-magento-2-on-multiple-containers-in-production-with-generated-code%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            Not sure why this question got downvoted; looking around the Internet there is precious little information about how people should run Magento 2 (Open Source or Enterprise) in a scalable, production, container environment, and there are a lot of little things that are a pain in the butt to handle.



            Relating to my question above, I am now compiling the code in the container build process, which seems to work okay; in the Dockerfile, after I've copied or cloned my Magento codebase into the container image:



            # Compile code.
            RUN magento module:enable --all
            && magento setup:di:compile


            That way I don't have to do that in an entrypoint script.



            However, I do still have to run something like the following in my entrypoint—at least after a fresh installation (and maybe also after new deployments):



            echo "Setting MAGE_MODE"
            magento deploy:mode:set $ENV_MODE --skip-compilation

            echo "Cleaning Magento Cache"
            magento cache:flush
            magento cache:clean

            echo "Ensuring permissions are correct on Magento folders - post install."
            CHOWN_PATHS_POST_INSTALL="app/etc generated pub/media pub/static var"
            chown -R www-data:www-data $CHOWN_PATHS_POST_INSTALL

            if [ "$ENV_MODE" = "production" ]; then
            echo "Compiling static assets."
            su -s /bin/bash -c "magento setup:static-content:deploy --jobs 4" www-data
            fi


            I'm still trying to figure out some other things, but I'm to the point where new containers can start in just a few seconds (still have to do things like chown -R www-data:www-data paths like app/etc and generated after the container starts, and copy/insert a templated app/etc/env.php file into place (to make sure all my site's settings are accounted for and can be driven by environment variables in the container so it's a true 12 factor app deployment).






            share|improve this answer



























              1














              Not sure why this question got downvoted; looking around the Internet there is precious little information about how people should run Magento 2 (Open Source or Enterprise) in a scalable, production, container environment, and there are a lot of little things that are a pain in the butt to handle.



              Relating to my question above, I am now compiling the code in the container build process, which seems to work okay; in the Dockerfile, after I've copied or cloned my Magento codebase into the container image:



              # Compile code.
              RUN magento module:enable --all
              && magento setup:di:compile


              That way I don't have to do that in an entrypoint script.



              However, I do still have to run something like the following in my entrypoint—at least after a fresh installation (and maybe also after new deployments):



              echo "Setting MAGE_MODE"
              magento deploy:mode:set $ENV_MODE --skip-compilation

              echo "Cleaning Magento Cache"
              magento cache:flush
              magento cache:clean

              echo "Ensuring permissions are correct on Magento folders - post install."
              CHOWN_PATHS_POST_INSTALL="app/etc generated pub/media pub/static var"
              chown -R www-data:www-data $CHOWN_PATHS_POST_INSTALL

              if [ "$ENV_MODE" = "production" ]; then
              echo "Compiling static assets."
              su -s /bin/bash -c "magento setup:static-content:deploy --jobs 4" www-data
              fi


              I'm still trying to figure out some other things, but I'm to the point where new containers can start in just a few seconds (still have to do things like chown -R www-data:www-data paths like app/etc and generated after the container starts, and copy/insert a templated app/etc/env.php file into place (to make sure all my site's settings are accounted for and can be driven by environment variables in the container so it's a true 12 factor app deployment).






              share|improve this answer

























                1












                1








                1







                Not sure why this question got downvoted; looking around the Internet there is precious little information about how people should run Magento 2 (Open Source or Enterprise) in a scalable, production, container environment, and there are a lot of little things that are a pain in the butt to handle.



                Relating to my question above, I am now compiling the code in the container build process, which seems to work okay; in the Dockerfile, after I've copied or cloned my Magento codebase into the container image:



                # Compile code.
                RUN magento module:enable --all
                && magento setup:di:compile


                That way I don't have to do that in an entrypoint script.



                However, I do still have to run something like the following in my entrypoint—at least after a fresh installation (and maybe also after new deployments):



                echo "Setting MAGE_MODE"
                magento deploy:mode:set $ENV_MODE --skip-compilation

                echo "Cleaning Magento Cache"
                magento cache:flush
                magento cache:clean

                echo "Ensuring permissions are correct on Magento folders - post install."
                CHOWN_PATHS_POST_INSTALL="app/etc generated pub/media pub/static var"
                chown -R www-data:www-data $CHOWN_PATHS_POST_INSTALL

                if [ "$ENV_MODE" = "production" ]; then
                echo "Compiling static assets."
                su -s /bin/bash -c "magento setup:static-content:deploy --jobs 4" www-data
                fi


                I'm still trying to figure out some other things, but I'm to the point where new containers can start in just a few seconds (still have to do things like chown -R www-data:www-data paths like app/etc and generated after the container starts, and copy/insert a templated app/etc/env.php file into place (to make sure all my site's settings are accounted for and can be driven by environment variables in the container so it's a true 12 factor app deployment).






                share|improve this answer













                Not sure why this question got downvoted; looking around the Internet there is precious little information about how people should run Magento 2 (Open Source or Enterprise) in a scalable, production, container environment, and there are a lot of little things that are a pain in the butt to handle.



                Relating to my question above, I am now compiling the code in the container build process, which seems to work okay; in the Dockerfile, after I've copied or cloned my Magento codebase into the container image:



                # Compile code.
                RUN magento module:enable --all
                && magento setup:di:compile


                That way I don't have to do that in an entrypoint script.



                However, I do still have to run something like the following in my entrypoint—at least after a fresh installation (and maybe also after new deployments):



                echo "Setting MAGE_MODE"
                magento deploy:mode:set $ENV_MODE --skip-compilation

                echo "Cleaning Magento Cache"
                magento cache:flush
                magento cache:clean

                echo "Ensuring permissions are correct on Magento folders - post install."
                CHOWN_PATHS_POST_INSTALL="app/etc generated pub/media pub/static var"
                chown -R www-data:www-data $CHOWN_PATHS_POST_INSTALL

                if [ "$ENV_MODE" = "production" ]; then
                echo "Compiling static assets."
                su -s /bin/bash -c "magento setup:static-content:deploy --jobs 4" www-data
                fi


                I'm still trying to figure out some other things, but I'm to the point where new containers can start in just a few seconds (still have to do things like chown -R www-data:www-data paths like app/etc and generated after the container starts, and copy/insert a templated app/etc/env.php file into place (to make sure all my site's settings are accounted for and can be driven by environment variables in the container so it's a true 12 factor app deployment).







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 24 at 17:43









                geerlingguygeerlingguy

                1145




                1145



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Magento Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f249917%2fscaling-magento-2-on-multiple-containers-in-production-with-generated-code%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Sum ergo cogito? 1 nng

                    419 nièngy_Soadمي 19bal1.5o_g

                    Queiggey Chernihivv 9NnOo i Zw X QqKk LpB