Upgrade Ghost using Blue-Green deployments & Amazon Lightsail

Ghost is a powerful blogging platform with a promising roadmap of features, however updating to major releases can be problematic. The Ghost CLI sets out to solve this problem, but is not yet mature enough to trust updating releases on production servers.

The objective of the Ghost CLI project is to make setting up and maintaining a Ghost site as straight forward as possible

Blue-Green Deployments

An alternative approach to updating Ghost would be to use 'Blue-Green' deployments, for a more in-depth description check out Martin fowler's article on the subject. In essence, you have a duplicate setup, Blue(e.g. Live) and Green(New Ghost version). Once updated Green is ready to deploy, you cut-over all traffic from Blue to Green. This has a number of advantages, most notably:

  • Reduced/No downtime
  • Increased confidence and testing in production like environment
  • Ability to rollback easily

Performing Blue-Green with Amazon Lightsail

Amazon Lightsail offers a cheap and easy means to standup virtual servers with a simplified management interface. Although this article focuses on AWS, you could apply the same practice to Digital Ocean or other providers.  

The prerequisites for setup are: AWS account, AWS static IP, and DNS configured (Cloudflare). all of which will be covered.

A core tenant of Dev-Ops is to treat servers as 'Cattle, not Cats', which is to say, it should be simple to standup and terminate servers with minimal system administration. In the case of Ghost you may want to speed up Green environment configuration by putting the setup into source control, but that will create it's own overhead as major releases will likely change this process.  

Creating your Green instance

Let's imagine you have a live v1 ghost blog served from AWS. You now want to upgrade to v2. From the AWS management console select Instances > Create instance and select the ubuntu configuration as defined by the Ghost stack guide. This will take a few moments to startup. You should have instances as follows where blue is live and green is your new candidate:

blue-green-instances

You can now setup your new instance following the Ghost how to guide. This should mean you are running the latest version of Ghost. Once done, you will want to use the Ghost admin console > Labs export/import feature to move across your old posts and metadata to the new Green instance. Finally you may want to upload your new vX compliant theme into the Green Ghost instance. You can check that your theme meets the version requirements using the gscan tool. Please note: Once setup is complete, to have a true production environment you may need to re-run the ghost-setup command with your live blog domain name to ensure NGINX correctly maps HTTP requests on startup.

Setup a Static IP Address with Lightsail

In the Lightsail console navigate to Networking > Create Static IP here we you will be asked to specify your availability region and an identifiable name for the IP address. Please note static IP addresses are only retained as long as they are attached to a specific instance, essentially a 'use it or loose it' policy. So be sure to attach to your Blue instance at this point. The IP address console should now display like so:

blue-static-ip

Routing Traffic to between Blue-Green

The domain name for your Ghost blog will point to your Blue(live) setup. Cloudflare offer free SSL that allows you to specify the static IP address to route all traffic to, meaning you can attach the static IP you created to either instance. If things go wrong and you need to rollback a straightforward re-attachment of the static IP to your Blue instance will reset you to your previous version. The console will show which instance has the static IP, in this example Green is now live:

green deployed live

Blue Green Considerations

Blue Green deployments are not a silver bullet, they come with their own tradeoffs, depending on the size and complexity of a service the cost overheads may be harder to justify. In the case of this example you could think of this as a transient event, where ghost-v1-blue is decommissioned, or you could use more general naming and keep both running so you can quickly and confidently keep pace with new updates without risking any production downtime.

Further reading:

If you are interesting in learning more about Blue-Green deployments and Dev-Ops best practices here is some recommended reading: