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.
- Client side: Google Cloud CLI, jq, curl, expect, ssh-keygen, ssh-keyscan
- Server side: Ghost v5 with CLI, Ubuntu 22.04 on Google Cloud (setup guide)
- Setup an SSH key for your
service account(with access to the private key on your client machine running the script)
- Added your
service accountSSH key to your VM
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.
- Checks for client side pre-requisites before running: Google Cloud CLI, jq, curl, expect, ssh-keygen, ssh-keyscan
- Lists your Google Cloud VMs if you have more than one.
- Offers to back up your Ghost instance to a machine image.
- Starts a new VM from the machine image named after the latest Ghost release.
- Temporarily stops Ghost on the new VM to free up RAM for ghost update.
- Updates Ghost on the new VM (afterwards starts Ghost.)
- 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
- Clone the repo or just copy/paste this script to a file called update.sh
- Then, run the script in your terminal:
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.
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
Machine Images – Before the update
Machine Images – After updating from 5.61.1 to 5.61.2