Ghost but with SQLite, Litestream and S3 Adapter
154
Github Repo for understand how it build and works: https://github.com/tegarimansyah/ghost-playbook
To achive that goals, we need to check current ghost docker image and look how we can improve it.
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).
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"
# ======================
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"
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