Continuous Delivery for Magento with Fleet

By December 8, 2015 General

Continuous Delivery for your Magento store with Fleet

You may have heard of continuous delivery (CD) and continuous integration (CI) without giving either term much further thought. It’s not uncommon for e-commerce managers and even some developers to be confused about how CD and CI can improve your online e-commerce store.

Maybe you don’t see the commercial benefits. Maybe you don’t see the need to change your existing processes. Maybe the concept of pushing so many code changes into production every day sounds daunting.

So I’m going to explain why you should, you must, you need to understand CD and/or CI and how to apply the deployment process to your Magento website using Anchor’s Fleet platform.

The speed, method and frequency of your code deployments will each have a massive impact on the success of your e-commerce store. You can expect the following commercial benefits with continuous delivery/integration:

  • More performance: Testing each release on a ‘like-for-like’ production environment means each iteration of your store’s code will be optimised so that your application serves faster page load times.
  • More uptime: ‘Like-for-like’ environments also mean more accurate load or user acceptance testing, preventing more bugs creeping into your production store. Fewer bugs mean fewer performance issues (99.99% of outages are code related). Automation also boosts uptime and reliability by eliminating human error.
  • Rapid feature rollout: Push out new ecommerce and website features faster and more often, giving you a competitive advantage.
  • Stress-free deployments: With a rigid deployment process in place, if a bug does find its way into production you can rollback more easily.

DevOpsSo how do you implement a CI/CD workflow process for your Magento e-commerce store?

To implement continuous delivery, you’ll need to undertake the following:

  • Manage a library of code releases
  • Tie code releases to hosting infrastructure
  • Test deployments within ‘like-for-like’, on-demand production environments for load/user acceptance testing
  • Load code releases into identical environments for staging, UAT and production
  • Roll out or back without your store suffering any downtime

With Fleet, we’ve carefully designed and automated a continuous delivery process like the above for Magento.

If you’re managing your code base within a repository using GitHub or Bitbucket, you’re good to go! No need to download any software. Simply run an alias command within your terminal and the rest is a simple process.

Let’s dive into a live example of how this would work. Say we’re pushing out a new code release for our demo Magento store at http://www.prod.ancora.f.nchr.io. Once we’ve granted you access to push out a new feature you would:

1) Clone the repository onto your local machine.


$ git clone git@bitbucket.org:ancora/demo-magento-store.git .
 
Cloning into '.'... 
remote: Counting objects: 17167, done.
remote: Compressing objects: 100% (7862/7862), done. 
remote: Total 17167 (delta 7207), reused 17118 (delta 7179)
Receiving objects: 100% (17167/17167), 25.09 MiB | 2.11 MiB/s, done.
Resolving deltas: 100% (7207/7207), done.
Checking connectivity... done. Checking out files: 100% (12784/12784), done.

2) Activate Fleet by simply running the alias command within your terminal.

$ alias fleet='ssh -t -o LogLevel=QUIET deploy@aux.ancora.f.nchr.io --'

3) Now make a commit within your local working directory using GIT.


$ git commit -m 'New feature for my store.' . 
[new-feature (root-commit) 5ba7c4a] Added index.php 
 1 file changed, 0 insertions(+), 0 deletions(-) 
 create mode 100644 index.php

4) Push out new commit into your Fleet release library.


$ fleet create release 5ba7c4a 
Creating release 5ba7c4a 

$ fleet release list 
name      status      modified                    message                            environments
-------   ---------   -------------------------   --------------------------------   -------------- 
5ba7c4a   CREATING    2015-10-30 03:51:01+00:00   New feature for my store. 
981e813   AVAILABLE   2015-07-02 02:01:25+00:00   Latest stable release of store...  prod

5) Create an on-demand staging environment to test your new code release by replicating Production; you won’t need your database or Redis storage to be highly available, so pass the argument –no-ha.


$ fleet env create staging --no-ha 
Environment staging is now being created 

$ fleet env list 
name      status     release     releases     certificate     created                     updated 
-------   --------   ---------   ----------   -------------   -------------------------   -------------------------
staging   CREATING                        0   prod            2015-11-04 00:20:59+00:00   2015-11-04 00:21:01+00:00
prod      RUNNING    037205f              1   prod            2015-03-24 23:06:21+00:00   2015-10-13 03:16:29+00:00

When you create an environment on demand, Fleet will automatically copy the latest snapshot of your database across and run any SQL scripts you have loaded against it. In this case, we have the SQL script update-mage-base-url, which simply changes the Magento Base URLs:


# display SQL scripts
$ fleet config sql list
update-mage-base-url

# show this script
$ fleet config sql show update-mage-base-url
----------%<-----------
USE ancora;
UPDATE core_config_data SET value = 'http://{{environment}}.ancora.f.nchr.io/' WHERE path = 'web/unsecure/base_url'; 
UPDATE core_config_data SET value = 'https://{{environment}}.ancora.f.nchr.io/' WHERE path = 'web/secure/base_url'; 
UPDATE core_config_data SET value = 'https://admin.{{environment}}.ancora.f.nchr.io/' WHERE path = 'admin/url/custom'; 
---------->%-----------

6) Load and activate your new release into the newly created staging environment.


$ fleet env load staging 5ba7c4a
Release 5ba7c4a is now being loaded into environment staging

$ fleet env describe staging
----------------   -------------------------
name               staging
status             RUNNING
whitelist          allow-all
ssl certificate    prod
created            2015-11-04 00:20:59+00:00
updated            2015-11-04 00:21:01+00:00
recycling          ON
solr               OFF
maintenance mode   OFF
tracked branches   fleet-deploy
previous release
autoscaling        min 2
autoscaling        max 2
ha                 OFF
workers/instance   AUTO
----------------   -------------------------

Releases:
name      status     loaded                      updated                     frontends
-------   --------   -------------------------   -------------------------   -----------
8ef9d2f   CREATING   2015-11-04 00:39:04+00:00   2015-11-04 00:39:04+00:00             0

$ fleet env activate staging 5ba7c4a
Release 5ba7c4a is now being activated for environment staging

$ fleet env describe staging
----------------   -------------------------
name               staging
status             RUNNING
whitelist          allow-all 
ssl certificate    prod 
created            2015-11-04 00:20:59+00:00
updated            2015-11-04 00:55:41+00:00
recycling          ON 
solr               OFF
maintenance mode   OFF
tracked branches   fleet-deploy
previous release   None
autoscaling min    2 
autoscaling max    2 
ha                 OFF 
workers/instance   AUTO 
----------------   -------------------------

Releases:
name      status       loaded                      updated                     frontends
-------   ----------   -------------------------   -------------------------   -----------
8ef9d2f   * ACTIVE *   2015-11-04 00:39:04+00:00   2015-11-04 00:39:04+00:00             2

Endpoints:
--------   --------------------------------- 
admin      admin.staging.ancora.f.nchr.io 
adminssh   adminssh.staging.ancora.f.nchr.io
www        www.staging.ancora.f.nchr.io
--------   --------------------------------- 

Now that your release is * ACTIVE * you can access it via the URL endpoints provided:

  • admin : admin.staging.ancora.f.nchr.io
  • adminssh : adminssh.staging.ancora.f.nchr.io
  • www : www.staging.ancora.f.nchr.io

7) Conduct load/user acceptance testing and receive sign-off from the customer.

8) Once the customer has approved the new release, destroy the now unnecessary staging environment.


$ fleet env destroy staging
This will PERMANENTLY DESTROY environment staging! 

Please review the details below: 
----------------   -------------------------
name               staging
status             RUNNING
whitelist          allow-all
ssl certificate    prod
created            2015-11-04 00:20:59+00:00
updated            2015-11-04 00:55:41+00:00
recycling          ON 
solr               OFF
maintenance mode   OFF
tracked branches   fleet-deploy 
previous release   None
autoscaling min    2
autoscaling max    2
ha                 OFF 
workers/instance   AUTO
----------------   -------------------------

Releases: 
name      status       loaded                      updated                     frontends
-------   ----------   -------------------------   -------------------------   -----------
8ef9d2f   * ACTIVE *   2015-11-04 00:39:04+00:00   2015-11-04 00:39:04+00:00             2

Endpoints:
--------   ---------------------------------
admin      admin.staging.ancora.f.nchr.io 
adminssh   adminssh.staging.ancora.f.nchr.io
www        www.staging.ancora.f.nchr.io
--------   ---------------------------------

Enter the environment's name to proceed or anything else to abort
> staging
Environment staging is now being destroyed

9) Load and activate your new release into production without any downtime.


$ fleet env load prod 5ba7c4a 
Release 5ba7c4a is now being loaded into environment prod 

$ fleet env activate prod 5ba7c4a
Release 5ba7c4a is now being activated for environment prod 

$ fleet env describe prod 
----------------   -------------------------
name               prod
status             RUNNING
whitelist          allow-all 
ssl certificate    prod 
created            2015-03-24 23:06:21+00:00 
updated            2015-10-13 03:16:29+00:00 
recycling          ON 
solr               OFF 
maintenance mode   OFF 
tracked branches   fleet-deploy 
previous release    
autoscaling min    2 
autoscaling max    2 
ha                 ON 
workers/instance   AUTO 
----------------   -------------------------

Releases:
name      status       loaded                      updated                     frontends
-------   ----------   -------------------------   -------------------------   -----------
5ba7c4a   * ACTIVE *   2015-10-13 02:40:30+00:00   2015-10-30 04:11:01+00:00             2
981e813   RUNNING      2015-10-13 02:40:30+00:00   2015-10-13 02:40:30+00:00             2

Endpoints:
--------   ------------------------------
admin      admin.prod.ancora.f.nchr.io 
adminssh   adminssh.prod.ancora.f.nchr.io
www        www.prod.ancora.f.nchr.io
--------   ------------------------------

10) Seamlessly rollback, if required, without any downtime. If a bug does find its way into production, don’t stress! There’s no need for a hot fix. Simply reactivate the previous release and you’re done!


$ fleet env activate prod 981e813

And there you have it. A Continuous Delivery process using Fleet. Look out for my next article on how we integrated this process into Codeship along with some unit testing to create a Continuous Integration process, using Slack to alert users to new code release deployments.

Leave a Reply

This is Steve. One of the awesomely brilliant (and well-bearded) Anchorites.

Hosting and AWS management, support and advice from the Ops team behind GitHub.

And if you're on a DevOps journey, talk to us about getting a cloud infrastructure expert assigned to your Agile team.

Call us on +61 2 8296 5111 or send a note:

Name

Email

Your Message