Sign inSign up

tegarimansyah/ghost-sqlite

By tegarimansyah

•Updated over 2 years ago

Ghost but with SQLite, Litestream and S3 Adapter

Image
0

154

tegarimansyah/ghost-sqlite repository overview

⁠Ghost⁠ but with SQLite, Litestream and S3 Adapter

Github Repo for understand how it build and works: https://github.com/tegarimansyah/ghost-playbook⁠

⁠Our Goals

  • Run a docker image is cheap (or free), but managed database is not.
  • SQLite is the most affordable (since it doesn't need any server). But Ghost 5 are dropping it's support for SQLite⁠ in production. But yeah we can still use it, but really recommended to pin the version.
  • When we run container, most of the time we will expect the storage is ephemeral. So you lost your data (especially our SQLite db) once you delete the container. So we need to Backup it (use external volume or other approach).
  • I use litestream to replicate the sqlite db and save it to S3 compatible object storage (I use Cloudflare R2). The cost is super cheap (or free) and the data is save. I also can take a look my data without go to my server.
  • Since we know we will deal with ephemeral container, it's nice to setup remote storage for our media, e.g. in S3.

To achive that goals, we need to check current ghost docker image and look how we can improve it.

⁠Motivation

I got 2 incidents that make me lost all of my blog data and 1 minor issue.

The first one when I upgrade the Ghost version in docker, suddenly it wipe out my data in MySQL, novice mistake: not creating a backup. The second one is when I late to pay my server, they delete my instance and all of its data. I do have a backup, but inside the server 😭, I just don't expect my personal matter makes we forgot to pay it. Well, I think it's because it just a "side-project", I'm not looking at detail like how I implement in my company.

The minor one is due to little to no traffic in my website, so sometimes mysql goes to "sleep" mode and the first request makes Ghost response a 5xx. Well we can fix it but the error is not so obvious and intermitent.

That's why I try to use another approach by using Ghost (Docker) with SQLite and Litestream. It will maintain my backup and save it to Cloudflare R2 (which is really cheap to free).

⁠Configuration

Create a .env file, Litesteram configuration also read from this config.

# Your expected domain. It will use in somewhere like "preview" link.
# It still can be run in localhost
url="https://bongkar.cloud"

# ======================
# Database options, please choose one
# # Database using mysql
# database__client=mysql
# database__connection__host=ghost_db
# database__connection__port=3306
# database__connection__user=mysqluser
# database__connection__password=supersecret
# database__connection__database=ghost

# Database using sqlite
database__client="sqlite3"
database__connection__filename="content/data/ghost-test.db"
database__useNullAsDefault=true
database__debug=false
# ======================

# ======================
# Mail
# I use gmail smtp, but you can use oher provider
mail__transport="SMTP"
mail__options__host="YOUR-EMAIL-SERVER-NAME"
mail__options__port=465
mail__options__service="EMAIL"
mail__options__auth__user="YOUR-EMAIL-SMTP-ACCESS-KEY-ID"
mail__options__auth__pass="YOUR-EMAIL-SMTP-SECRET-ACCESS-KEY"
mail__from="'Acme Support' <[email protected]>"
# ======================

# ======================
# S3 Storage Adapter
# I use Cloudflare R2 instead of AWS S3
AWS_ACCESS_KEY_ID=""
AWS_SECRET_ACCESS_KEY=""
AWS_DEFAULT_REGION=""
GHOST_STORAGE_ADAPTER_S3_PATH_BUCKET=""
GHOST_STORAGE_ADAPTER_S3_PATH_PREFIX="" # folder name inside the bucket
GHOST_STORAGE_ADAPTER_S3_ENDPOINT="https://YOUR-R2-ID.r2.cloudflarestorage.com" # S3-compatible endpoint
GHOST_STORAGE_ADAPTER_S3_FORCE_PATH_STYLE="true"
# ======================

⁠Usage

Use docker-compose

version: '3'
services:
  ghost:
    image: tegarimansyah/ghost-sqlite:5.79.4-alpine
    ports:
      - 2368:2368
    env_file:
      - .env

or with docker command

docker run --env-file=.env --rm tegarimansyah/ghost-sqlite:5.79.4-alpine

Behind the scene, this will run

$ docker-entrypoint.sh litestream replicate -config litestream.yml -exec "node current/index.js"

Tag summary

Content type

Image

Digest

sha256:6426f9b13…

Size

191.1 MB

Last updated

over 2 years ago

docker pull tegarimansyah/ghost-sqlite:5.79.4-alpine