Magento 2 introduces a special way of deployment process which is “Pipeline Deployment”. It recommends this process for any large sites that expect the least downtime during any deployment process. This process helps us to sustain consistent configurations for different environments.
Deploying Magento on a single machine and if you can tolerate some downtime during the process. So then carefully read the single machine deployment.
Magento 2: Single-machine deployment
This provides instructions for deploying updates if any to Magento 2 on a production server by using the command line. Also, this process applies to all technical users who are responsible for the store operation. It also helps running on a single machine having some themes and locales installed.
For business users, we recommend using the System Upgrade feature in the Admin.
- Magento installed using a Composer or a compressed archive.
- Updates are directly applying to the server.
Magento 2 Pipeline Deployment process steps
Log on to your production server or switch to the Magento file system service provider.
Change the directory to the Magento base directory
cd<Magento base directory>
Maintenance mode should be enabled using the command:
Apply any updates to Magento using the following command
composer require <package><version> --no-update
Package: The name of the package to be updated.
Version: The target version of the package if you want to update
Update Magento’s components with Composer:
Update the database schema and data
Compile the code:
Deploy static content:
Clean the cache:
Exit maintenance mode:
MAGENTO 2 Pipeline deployment: approaches AND PROCESS
Pipeline deployment in Magento 2 will minimize the downtime with static inputs and compile code on a machine. This particularly separates the inputs and code compilation from the production system. The production system needs limited downtime to move files from the build system to the production system.
Recommended Magento 2 pipeline deployment workflow:
The below diagram shows how to deploy on any system with managed configuration.
Advantages of Magento 2 Pipeline Deployment:
- Build step needs lesser use of database access
- compilation very fast and asset generation
- Compact web assets minimize bundle and exact time
- To implement this process we have to follow the below systems:
Developers can write codes, customizing third-party extensions, and push code into the repository on this machine.
Pull the latest code from the repository, deploy static assets, and also compile the code. If we build an asset on this, it will help us to minimize production downtime.
Staging System (Optional)
Staging systems are optional, and we can use this system for UAT which is identical to a production system.
The production system is the live system on which we may pull the latest code. All this code can be pulled from the repository and import all configuration changes.
Magento now stores all configuration details in separate files. Secondly, it helps us to do configuration consistent across the above systems. Magento can support three different types of configuration.
All these settings are to be consistent in both development and production environments. Magento will provide utility to dump all other configuration settings in app/etc/config.php. It may be pushed into the code repository and also shared between different systems.
System Specific Configuration
These are all settings that may not be pushed into the repository and be system-specific e.g. Third-party systems’ configuration.
All sensitive settings will go into app/etc/env.php and which may not be included in the code repository. Information like DB credentials, API keys, and identifiable information is environment-specific. And also different environments have different configuration settings.
A step-by-step guide to building a different system:
As we have created two different branches – master and develop, the reason is to maintain different gitignore settings on different systems.
Create one new folder in document root /var/www/HTML/magedev and also change directory to magedev
Pull the latest Magento code from the Magento repository
Composer create-project --repository-url=https://repo.magento.com/ Magento/project-community-edition.
It prompts you to enter public and also private keys.
Run composer install
A new database is to be created e.g. magedev
Run Magento setup, provide required details and make sure that it will run on development system http://localhost/magedev
Push the code into the develop branch and make sure that below is included in .gitignore and app/etc/config will be part of the code repository.
Vendor directory (and subdirectories) generated directory (and subdirectories) pub/static directory (and subdirectories) app/etc/env.php file
Do the needed settings in Magento back office and run the below command. Beyond all this to export the configuration settings and dump all of them into app/etc/config.php
php bin/Magento app:config:dump
Write or modify the code and run the below command to produce assets and be sure that changes are working as expected.
php bin/magento setup: upgrade php bin/Magento setup: static-content:deploy -f php bin/magento cache: flush
Push all the modified changes including config.php into the code repository.
The Build system need not have DB and Magento software installed.
Pull the latest code from the developing branch and also merge that into the master branch.
Change .gitignore and be sure that below is included in the code repository.
app/etc/config.php generated directory (and subdirectories) pub/media directory pub/media/wysiwyg directory (and subdirectories) pub/static directory (and subdirectories)
Run the composer and install and make sure vendor/ folder is up to date
Produce static assets and compile code using the below command
php bin/magento setup:di: compile php bin/magento setup: static-content:deploy -f
Now, push all the modified files from generated/ and pub/ folder in the master branch
Now ready for production deployment.
Follow the simple shell script below to execute commands in sequence.
php bin/Magento maintenance: enable git pull origin master php bin/Magento app:config: import php bin/Magento setup: upgrade --keep-generated php bin/Magento cache: flush php bin/Magento maintenance: disable
Once we execute the commands then don’t forget to restart the web server and varnish server (if it is configured)
Magento 2 regarding pipeline deployment: Assumption
System integrators must have an excellent knowledge of Magento configuration options. Hence, the integrator should have better experience in managing large Magento sites. It has the know-how of how to keep production site downtime to the least. So one should have a deep knowledge of PHP programming. Good experience with source control systems like Git.
We hope this blog puts down all your Magento 2 pipeline deployment assumptions and queries. Still, want to have clarification about Magento development or deployment?. Contact our Magento 2 expert developers today. Don’t hesitate to get in touch with us.