3 min read

Updating Ghost on a Google Cloud Micro Instance

I am running Ghost on a Google Cloud always free-tier e2-micro instance. Given that this VM has a max of 1GB RAM it has some limitations. For instance, when I want to run ghost update I need to stop the Ghost server to free up enough RAM to run the update process. Since the updater has been prone to issues I created this bash script to help me automate the update process and minimize downtime.

Screen Recording of Ghost 5.61.1 being updated to 5.61.2 using gCloud Ghost Updater


What gCloud-Ghost-Updater does

tl;dr Clones your active Ghost instance, updates Ghost on it and then offers to move your static IP from your old VM to your new VM so you can cut over to it with minimal downtime.

  1. Checks for client side pre-requisites before running: Google Cloud CLI, jq, curl, expect, ssh-keygen, ssh-keyscan
  2. Lists your Google Cloud VMs if you have more than one.
  3. Offers to back up your Ghost instance to a machine image.
  4. Starts a new VM from the machine image named after the latest Ghost release.
  5. Temporarily stops Ghost on the new VM to free up RAM for ghost update.
  6. Updates Ghost on the new VM (afterwards starts Ghost.)
  7. If successful, the script will prompt if you want to reassign your free static IP to the new VM. If you opt to do this it will shutdown the old VM, and once it's stopped it will reassign the standard static IP to your new VM.

What gCloud-Ghost-Updater does not do

  • It does not run Ghost backup since this backs up the entire instance.
  • It does not delete any VMs or Machine Images. You'll need to check your Google Cloud console to clean up anything you no longer want such as terminated VMs or machine image backups.
  • It does not support multi-server setups with a load balancer.

How to run gCloud-Ghost-Updater

Potential future ideas

  • Refactor the code to be modular.
  • Make it easy to run only certain commands with parameters (eg backup image, update ghost, reassign IP, etc.)
  • Enable running the script without the few interactive prompts.
  • Cron that can check latest ghost release and offer to auto-update.
  • Enable checking for client side pre-requisites.
  • Offer to cleanup machine image backups and terminated VMs.
  • Offer to setup service_account SSH keys.

Final Note

The script was written quickly and has not been tested by anyone else. While I took precautions to generalize the script and avoid data loss I'd advise that you still use it at your own risk.

Google Cloud Console Screenshots

VMs – Before the update

VMs – After updating from 5.61.1 to 5.61.2

After updating from Ghost 5.61.1 to 5.61.2 "danielraffel-ghost-v5-61-1" instance was stopped, "danielraffel-ghost-v5-61-2" was started and the standard static IP address assigned to the DNS for danielraffel.me was reassigned to the running instance.

Machine Images – Before the update

Machine Images – After updating from 5.61.1 to 5.61.2

Before updating from Ghost 5.61.1 to 5.61.2 the "backup-danielraffel-ghost-v5-61-1" was created from "danielraffel-ghost-v5-61-1" instance.