Content
The Process of Magento Cloud Deployment
The performance of a website can be affected by many factors, including the deployment process, which is quite energy-intensive and can take a long time. The duration of the deployed website being in maintenance mode is affected by many factors, such as the configuration of the environment or the amount of content. However, there are ways to significantly raise the efficiency and optimize the Magento 2 deployment process. They vary depending on whether you are improving a finished website or working on testing one under development.
The best way to optimize is to upgrade to using ece-tools that provide a package of important features, such as backing up a database or checking the configuration of the environment. You can also optimize your Magento deploy by using different strategies. Having a deep expertise in both Magento development and DevOps, we are ready to share our view on the topic.
Magento 2 Deployment Architecture
A proper deployment of a website requires a full understanding not only of processes and strategies, but also of the website components, the well-established functioning of which ensures smooth performance. The Magento platform consists of core, optional or available only for Magento Commerce components.
The core components are:
- A web server which supports PHP-based applications;
- The database server MySQL.
The optional components are:
- A page caching tool;
- A session storage tool.
The optional components for Magento Commerce only are:
- A search tool;
- A message queueing tool;
- Multiple database servers.
The diagram below shows a sample architecture for Magento Open Source deployment.
Source cloud.google.com
As you can see, the architecture consists of a web server which can communicate with both session or page cache and a database server.
The diagram below shows a sample architecture for Magento Commerce deployment.
Source cloud.google.com
You can see the same elements as on the previous diagram, but also a search engine and a message queue.
3 Magento 2 Deployment Steps
Magento deployment prerequisites are an existing Magento project, a composer, Yarn or NPM and a Magento PWA Studio.
Magento cloud deployment process itself consists of three stages: build, deploy, and post-deploy. Every stage includes a specific set of actions with a limited number of resources.
1. Build phase
The first phase involves assembling containers for services that are enshrined in configuration files. Links and dependencies are also established on the foundation of the composer.lock file. The build keys written in the .magento.app.yaml file are triggered. The build phase is characterized by a lack of connectivity to services or databases and is entirely dependent on resources that are limited by the environment
2. Deploy phase
At the second phase, incoming requests go into temporary retention mode, while the website itself is transferred to maintenance mode. This phase is characterized by new container usage and a file system installation, after which network connections are opened, services from the .magento.app.yaml file relationship section are activated, and deploy hooks written in the .magento.app.yaml file are triggered. Content is only available for reading, except for the directories that the .magento.app.yaml file defines. The standard mounts property consists of such directories:
- app/etc – the env.php and config.php configuration files;
- pub/media – all content data (Magento categories or products);
- pub/static – generated static content;
- var – temporary files generated when Magento was running
Other directories are only available for reading. At the end of this phase, when the website is out of maintenance mode, it becomes active. As a result of this process, previously temporarily withheld incoming requests become available.
3. Post-deploy phase
At the third phase, there is a post-deployment of previously defined hooks. Any actions that are taken can have a significant impact on the performance of the website. The WARM_UP_PAGES environment variable should be used to fill in the cache if necessary.
Magento Deployment Strategy
Source www.simicart.com
This consists of several important steps.
1. Optimize the static content deployment
Static content deployment (SCD) significantly influences the deployment process, because it depends on the amount of content you need to create (images, themes, scripts, web pages) and the time span set to create it. The standard strategy means that static content is being generated when the website is transferred into maintenance mode. Obviously, it takes a certain amount of time for the content to be written in the pub/static directory installed for that purpose. Based on our experience, we can offer you a few simple but effective steps to help you significantly optimize your deployment process.
- Minify JavaScript and HTML content
SCD download time will be reduced if you skip filling static view files in the var/view_preprocessed directory and create minified HTML on demand.
It's also possible to save time and storage space by reducing the number of unimportant theme files. For instance, you can use the SCD_MATRIX environment variable to deploy the backend thread in English, and the custom theme in any other language.
Read our guide on Magento performance testing to make sure your store is well optimized.
- Choose a Magento 2 deployment strategy for optimization
The difference between deployment strategies is that their choice depends on having to create static content at any stage in the deployment process or on demand. The diagram below shows that the best solution is to choose the deploy phase for SC generation. Even if HTML is minified, it can take a long time to copy each content file into a specific ~/pub/static directory. Creating static on-demand content looks like a great option, but its downside is that if you don't have a content file in the cache, it will be created at the time of the request, which will affect the download time.
Source devdocs.magento.com
2. Reduce the downtime
During the second stage of deployment, the platform transfers into maintenance mode. As a result, your website goes offline until the process is complete. The time a website spends in this mode depends on its size, the amount of changes you’ve made during the deployment process, and the configuration for the SCD. However, the project can be configured in such a way that the downtime effect will be equal to zero.
Here are some tips to reduce the time it takes for your website to deploy an update to Production:
- Update your ece-tools or install them;
- Set up SCD. If your deploy phase isn’t going well, the site may not exit maintenance mode, but if the mistake appeared during the first phase, there would be no outage. So, the optimal setup for deployment with no downtime is generating the SC with minified HTML during the second phase;
- Set up the post-deploy hook. By default, the cache is cleared during the second phase, but it is worth moving this process to the third phase – the cache will remain in real time until the deployment phase ends, and then it will be securely cleared. The WARM_UP_PAGES environment variable will help you list the pages for pre-loading cache;
- Reduce theme files. You can reduce the number of theme files with the SCD_MATRIX environment variable;
- Accelerate the SC deployment. To do this, update the SCD_THREADS environment variable. It will increase the number of threads to deploy.
Magento 2 Pipeline Deployment
Magento offers a special way to deploy for any large websites that want to minimize the downtime. The point of it is that the deployment processes are performed in different systems.
Deployment systems:
- Development system. This is where the code is being written and updated and third-party extensions are added;
- Build system. This is where static assets are deployed and code is compiled;
- Staging system. It is an optional system for final code testing. Staging system is similar to production system (but it doesn’t process orders);
- Production system. It is your actual website. You should try to avoid making configurations there.
Synchronizing your system configuration:
- Shared Configuration. Consistent settings for the development and production environment. Magento has developed a utility to reset configuration settings that can be shared between systems;
- Specific Configuration. All settings that are different in different systems.
- Sensitive configuration. Sensitive settings cannot be pushed in the code repository – it is personally-identified information which is specific for every environment.
Using Magento pipeline deployment requires a perfect knowledge of the platform’s features, PHP programming and a successful work experience with large Magento-based stores.
Magento Deployment: AWS vs Azure
Source medium.com
Magento is a huge e-commerce platform, the installation of which is a complicated and impossible-looking task for many people. AWS and Azure are popular cloud providers that try to meet the needs of Magento’s growing customer base. Jean-Luc Dubouchet, a Junior Full-Stack Tech Engineer at Hidora, compared Magento installation processes on top of AWS and Azure. Here are the results of his short investigation:
- Amazon Web Services (AWS) has been one of the biggest players on the cloud services stage for more than 10 years. AWS provides users with a large range of features, which requires manual configuration. You must book a server example before using this service. Magento deployment on AWS takes 4 minutes
- Microsoft Azure appeared on the market in 2010. Magento installation is done within a specific marketplace, Azure App Services. While testing this app, you can see that the preparation of the application is quite complicated and the whole Magento Azure deployment takes more than 11 minutes.
Given the received numbers, we can state that Magento deployment best practices are better performed while using AWS.
Conclusion
While the process of deploying a project looks intimidating to an unprepared person, there's really nothing complicated or confusing about it. The Magento platform provides all the necessary services and tools to ensure that the deployment is as quick and painless as possible for the site to operate. However, if lines of code make you want to tear your hair out, and the view of the endless command line is already causing you a nervous tick (or if you do not want to contact the coding staff in advance), you can ask us for help. Our experienced developers will choose and in the shortest time implement an optimal deployment strategy, saving you from unnecessary work and showing an excellent result.
Let professionals meet your challenge
Our certified specialists will find the most optimal solution for your business.