Zero time deployment process for Magento2

The Magento 2 production deployment flow helps a store reach maximum performance by minimizing downtime during deployment. The length of time your production site is in maintenance mode depends on the size of the site, the number of changes applied during the deployment, and the configuration for static content deployment. One of the challenges with automating deployment is the cut-over itself, taking software from the final stage of testing to live production. You usually need to do this quickly in order to minimize downtime. You need to find a proper solution to prevent downtime during deployment that may be lengthy in some cases. 

One of these solutions is Envoyer.

What is Envoyer?

Envoyer is a deployment tool used to deploy PHP applications. Envoyer allows us to deploy code changes quickly and without any downtime. The changes are made available once the build is complete, without impacting the active codebase. This means that your application and the customers using it are not even aware of the fact that a new version has been pushed. 

Envoyer works well with major repository management platforms including Bitbucket. Other benefits include unlimited deployments and team members. Since Magento 2 is a PHP-based application you can easily use Envoyer service.

How does it work?

Envoyer deploys your Bitbucket repository to a “releases” directory on your server. Each system of “releases” folders represents a single commit in your Bitbucket repo history. Every time the deploy system gets triggered for a build, it creates a new folder in “releases” and clones the repo just at that commit into that folder. The name of the folder is time-stamped with the time of the deployment to keep it unique (e.g. releases/20200414223645)

Then it runs your full deployment script in there. Envoyer works through its build commands such as running composer install, compile dependency injection, deploy static content, linking shared folders, etc. Also, you can add your own build commands. Once Envoyer is done, the “current” directory is symlinked over to the latest release folder which is named based on the timestamp. The public folder at any time is just a symlink to one of several available folders in releases.

Besides, to work properly you’ll need to set up the document root on your server to point to this “current” folder which will always reference the latest version of your codebase.

The standard structure of folders is:

Note that any files/folders that need to persist across releases need to exist at the root level and need to be symlinked into each release. 

For example, Magento 2 has such files as env.php and config.php. The env.php file includes database credentials, backend URL, cache types state, and other configuration information. The config.php file contains module information. These files are located in the app/etc/ directory and shouldn’t be versioned since they are specific to an environment. How to handle such files will be described below.

Connect your Bitbucket project Bitbucket repository

In order to start using Envoyer you have to create a repository with your project:

After signing up for Envoyer, you should add a project to your account. Projects are tied to a source control Bitbucket repository.

Add server access

After creating a project, you may add as many servers as you like to the project. Fill out all the required fields and

Continue reading

This post was originally published on this site