Magento 2 Pipeline Deployment process: Here’s what you need to know

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 any 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.

Assumptions

  • Magento installed using a Composer or a compressed archive.
  • Updates are directly applying to the server.

Read: 3 Ways to Upgrade Magento 2 Installation

Deployment steps

Step 1

Log on your production server or switch to the Magento file system service provider.

Step 2 

Change the directory to the Magento base directory

cd<Magento base directory>
Step 3

Maintenance mode should be enabled using the command:

bin/magento maintenance:enable
Step 4

Apply any updates to Magento using the following command

composer require <package><version> --no-update

Package: The name of the package to be updated.

Magento/product-community-edition

Magento/product-enterprise-edition

Version: The target version of the package if you want to update

Step 5

Update Magento’s components with Composer:

composer update
Step 6

Update the database schema and data

bin/magento setup:upgrade
Step 7

Compile the code:

bin/magento setup:di:compile
Step 8

Deploy static content:

bin/magento setup:static-content:deploy
Step 9

Clean the cache:

bin/magento cache:clean
Step 10

Exit maintenance mode:

bin/Magento maintenance:disable

MAGENTO 2 Pipeline deployment: approaches AND PROCESS

Magento 2 pipeline deployment

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:

Development System

Developers can write codes, customizing third-party extensions, and push code into the repository on this machine.

Build System

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.

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.

Configuration Management

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.

Shared 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.

Sensitive 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.

Read: Magento 2 optimization: Tips and tricks for better performance

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.

Development System

Step 1

Create one new folder in  document root /var/www/HTML/magedev and also change directory to magedev

Step 2

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.

Step 3

Run composer install

Step 4

A new database is to be created  e.g. magedev

Step 5

Run Magento setup, provide required details and make sure that it will run on development system http://localhost/magedev

Step 6

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
Step 7

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
Step 8

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
Step 9

Push all the modified changes including config.php into the code repository.

Read: Magento 2 migration – The development process

Build System

The Build system need not have DB and Magento software installed.

Step 1

Pull the latest code from the developing branch and also merge that into the master branch.

Step 2

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)
Step 3

Run the composer and install and make sure vendor/ folder is up to date

Step 4

Produce static assets and compile code using the below command

php bin/magento setup:di:
compile

php bin/magento setup:
static-content:deploy -f
Step 5 

Now, push all the modified files from generated/ and pub/ folder in the master branch

Now ready for production deployment.

Read: What are the benefits of Magento 2 marketplace solution?

Production System

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 web server and varnish server (if it is configured)

Magento 2 regarding pipeline deployment: ASSUMPTIONS

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.

CONCLUSION

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Facebook
Twitter
INSTAGRAM
LinkedIn