Self-Hosting Ghost on GCP
Redesigning My Blog with Ghost, Cloud Run, and Cloud SQL
ers seem to get an itch to completely rebuild their personal blogs or websites. This time, I decided to embrace the trend and overhaul my own. Here's how I configured and deployed a self-hosted Ghost blog on Google Cloud, meeting my goals for simplicity, cost-efficiency, and customization.
TL;DR: Use a Ghost Docker image on Cloud Run, configure a custom domain, and connect it to Cloud SQL MySQL for a reliable blog setup at around $5/month.
Goals for the New Blog
When rethinking my blog, I had four main goals:
- A clean writing experience: The process of writing and publishing should be seamless and enjoyable.
- Cost efficiency: As this is a personal project, keeping costs low was a priority.
- Minimal maintenance: Once set up, the system should require little upkeep.
- Customizability: The ability to tweak the UI and functionality as needed was essential.
My previous blog was a static site generated from Markdown files. While functional, the editing experience felt clunky, and deployment was cumbersome. This led me to explore more robust platforms.
Prerequisites
Before diving in, ensure you have the following:
- Docker installed
- Google Cloud CLI (gcloud) configured
- Google Container Registry, Cloud Run, and Cloud SQL APIs enabled
- Google Cloud Billing set up
Helpful resources: Cloud Run setup, Billing management.
Choosing Ghost
Ghost describes itself as a "powerful platform for creating an online blog or publication." After experimenting with it, I found it aligned well with my goals:
- Writing experience: Ghost excels in providing a clean, user-friendly editor.
- Low maintenance: It requires minimal effort to keep running.
- Customizability: Theming and UI adjustments are straightforward.
However, Ghost Pro, the managed hosting option, starts at $29/month—too steep for my needs. Self-hosting Ghost via Docker presented a cost-effective alternative, especially when paired with Google Cloud's offerings.
Setting Up Ghost on Cloud Run
Cloud Run allows you to deploy containerized applications effortlessly. Here's how to get Ghost running:
-
Pull the Ghost Docker image:
docker pull ghost:3.12.0 docker tag ghost:3.12.0 gcr.io/<GCP_PROJECT_NAME>/ghost:3.12.0 docker push gcr.io/<GCP_PROJECT_NAME>/ghost:3.12.0
-
Deploy the image to Cloud Run:
Follow Google's Cloud Run deployment guide. Key settings to configure:
- Use Cloud Run (fully managed).
- Choose a region suitable for your audience.
- Allow unauthenticated invocations.
- Set the container port to
2368
(Ghost's default).
-
Connect a custom domain:
Follow Google's custom domain mapping guide. Update your DNS records as instructed.
Once deployed, access your Ghost admin panel at <your-domain>/ghost
to configure the first admin user.
Solving Data Persistence with Cloud SQL
The default Ghost Docker image uses SQLite for data storage. While fine for local development, it doesn't persist data across deployments. To solve this, I used Cloud SQL, Google's managed relational database service.
Setting Up Cloud SQL
-
Create a MySQL instance:
- Follow the prompts in the Cloud SQL setup.
- Use the
db-f1-micro
machine type to minimize costs. - Generate a strong password for your instance.
-
Connect Cloud Run to Cloud SQL:
- Cloud Run supports direct connections to Cloud SQL. Follow this guide to link the two services.
-
Configure Ghost to Use Cloud SQL:
Ghost requires some extra setup to connect to a database via Unix sockets. Add the following environment variables to your Cloud Run instance, replacing placeholders with your actual values:
database__client=mysql database__connection__socketPath=/cloudsql/<CLOUD_SQL_INSTANCE> database__connection__user=root database__connection__password=<DB_PASSWORD> database__connection__database=ghost
Wrapping Up
With Ghost running on Cloud Run and backed by Cloud SQL, you now have a powerful, cost-effective blogging platform. You can further enhance it with themes from the Ghost marketplace.
This setup meets all my goals: a clean writing experience, low cost, minimal maintenance, and full customizability. Happy blogging!