Ghost blog on Docker and Terraform at minimal cost

If you don't like DIY, Infrastructure as a Code (IaaC) and not interested in running our own newsletter at lowest possible cost, you can stop reading here.

This is an experimental to run production grade Ghost blog & newsletter at minimal cost in cloud, using Docker Compose, maintaining infrastructure with Terraform and custom CLI.

GitHub - belashou/ghost-docker-terraform: An experimental low-end project to run production grade Ghost blog using Docker Compose, maintaining infrastructure with Terraform
An experimental low-end project to run production grade Ghost blog using Docker Compose, maintaining infrastructure with Terraform - GitHub - belashou/ghost-docker-terraform: An experimental low-en…

Objectives

  1. Upper limit for infrastructure costs is $5 per month in total (excluding domain name fee).
  2. Production grade security.
  3. Low response time (500ms on average).
  4. Low maintenance effort and infrastructure automatization though IaaC and CLI.

We can achieve it by the following technology stack.

Stack

  1. Hetzner Cloud (this is a referral link with bonus for you and me) as a cloud provider. It offers very democratic prices and decent performance. A special point of interest is Ampere Altra (arm64) platform. Such compute instances are twice cheaper than usual x86 instances.
  2. Terraform and Ansible to build, run and maintain the infrastructure as a code.
  3. Custom CLI implemented with Docker and Shell to automate deployment and maintain the project with short console commands. Backup/restore and complete deployment will take ~2 minutes, which is a great metric for such price. You don't need to install development tools like Terraform locally, as CLI image already contains it.
  4. Docker on a single cloud node to run the following containers with Docker Compose:
    1. Ghost as a popular lightweight blog and newsletter platform.
    2. MySQL as a required DB for Ghost.
    3. Nginx to proxy and cache data.
    4. Kopia as an automatic backup system with nice UI.
  5. Cloudflare to manage DNS, provide CDN and DDOS protections. We use three more services:
    1. Zero Trust to handle secure connection with cloud and internet. It automatically manages SSL connection, allows keeping node ports closed and renders SSH console in the browser.
    2. Access to manage access to internal tools (like backup system or SSH console).
    3. R2 is S3-like storage with zero egress fee for data and backups.
  6. Mailgun to send emails reliably (as a part of the newsletter feature).

Sidenote

It might seem counterintuitive to run the production system on a single node due to reliability issues, however, the main objective is cost. IaaC and CLI allow redeploying the stack in a few minutes (in case of a complete rundown). Backup and restore systems takes care of data persistence. Moreover, from the business perspective, any newsletter system should send emails reliably. All the content will be available in your mailbox.

Living example

This blog is run with this stack.

Ready to dive deep?

Check the repository and follow the README for detailed architecture description, prerequisites, installation and operation instructions.

GitHub - belashou/ghost-docker-terraform: An experimental low-end project to run production grade Ghost blog using Docker Compose, maintaining infrastructure with Terraform
An experimental low-end project to run production grade Ghost blog using Docker Compose, maintaining infrastructure with Terraform - GitHub - belashou/ghost-docker-terraform: An experimental low-en…

Subscribe to In Short,

Sign up now to get access to the library of members-only issues.
Jamie Larson
Subscribe