ghost: migrated to v6 + Docker Compose setup

This commit is contained in:
2026-07-09 02:14:16 -07:00
parent 7f860d47b9
commit 1934ce36af
9 changed files with 144 additions and 96 deletions

View File

@@ -1,52 +1,63 @@
#!/bin/bash
# Sets up Ghost (Docker-based) from a backup stored in B2.
# Assumes B2 at ${BUCKET_PATH} contains:
# db.sql — mysqldump of the ghost database
# content/ — Ghost content directory
#
# Run ghost_server-migrate first to populate B2, then run this.
set -euo pipefail
# shellcheck source=ghost_server-env
. "${HOME}"/"${USER}"-env
email_address=hello@knravish.me
echo -e "\n[+] setting up ghost\n\n-------\n"
echo "[+] node and companions"
# ghost doesn't play well with nvm for some reason, probably because of installation location and sudo access
# Download and import the Nodesource GPG key
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
NODE_MAJOR=20 # Use a supported version
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list
sudo apt-get update
sudo apt-get install nodejs -y
TMP_DIR="/tmp/${USER}-restore"
echo "[+] getting ready..."
mkdir -p "${VOLUME_PATH}"/{content,mysql}
mkdir -p "${TMP_DIR}"
ghost_cli_ver="1.28.4"
sudo npm i -g ghost-cli@${ghost_cli_ver}
envsubst <"${HOME}"/"${USER}"-compose_template.yaml >"${HOME}"/"${USER}"-compose.yaml
sudo mkdir -p "${BLOG_PATH}"
sudo chown "${USER}":"${USER}" "${BLOG_PATH}"
sudo chmod 775 "${BLOG_PATH}"
# ---------------------------------------------------------------------------
# 1. Start MySQL; Ghost stays down until data is restored
# ---------------------------------------------------------------------------
echo "[+] starting MySQL..."
sudo docker compose -f "${HOME}"/"${USER}"-compose.yaml up -d db
# ghost really needs to update to newer nginx versions and conventions...
sudo mkdir -p /etc/nginx/sites-available/ /etc/nginx/sites-enabled/ /etc/nginx/snippets/
echo "[+] waiting for MySQL to be healthy..."
until sudo docker exec ghost-mysql mysqladmin ping -h localhost -u root --password="${DB_ROOT_PASSWORD}" --silent 2>/dev/null; do
sleep 3
done
echo "[+] ooh, interactive stuff"
# ---------------------------------------------------------------------------
# 2. Restore database from B2
# ---------------------------------------------------------------------------
echo "[+] downloading database dump from B2..."
rclone copyto "${BUCKET_PATH}/db.sql" "${TMP_DIR}/db.sql"
# currently track manually, maybe automate
ghost_ver="5.130.6"
echo "[+] restoring database..."
cat "${TMP_DIR}/db.sql" | sudo docker exec -i ghost-mysql mysql -u root --password="${DB_ROOT_PASSWORD}" ghost
cd "${BLOG_PATH}" && ghost install ${ghost_ver} --no-setup
echo "[+] database restored"
sudo cp "${HOME}"/"${USER}"-config.production.json "${BLOG_PATH}"/
sudo chown "${USER}":"${USER}" "${BLOG_PATH}"/"${USER}"-config.production.json
mv "${BLOG_PATH}"/"${USER}"-config.production.json "${BLOG_PATH}"/config.production.json
# ---------------------------------------------------------------------------
# 3. Restore content directory from B2
# ---------------------------------------------------------------------------
echo "[+] downloading content from B2..."
rclone copy "${BUCKET_PATH}/content/" "${VOLUME_PATH}/content/"
cd "${BLOG_PATH}" && ghost setup --auto --sslemail ${email_address}
echo "[+] content restored"
echo "[+] restoring backup data"
# ---------------------------------------------------------------------------
# 4. Start Ghost — it will run schema migrations (V5 -> V6) automatically
# ---------------------------------------------------------------------------
echo "[+] starting Ghost..."
sudo docker compose -f "${HOME}"/"${USER}"-compose.yaml up -d ghost
sudo rm -r "${BLOG_PATH}"/content/*
rm -rf "${TMP_DIR}"
rclone copyto "${BUCKET_PATH}" "${BLOG_PATH}"/ghostBackup.zip
sudo unzip "${BLOG_PATH}"/ghostBackup.zip -d "${BLOG_PATH}"/content/
sudo chown -R ghost:ghost "${BLOG_PATH}"/content/
echo -e "\n-----\nIMPORTANT\n-----\n[X] modify the nginx default config file to include the sites-enabled directory\n"
echo -e "\n-----\nINFO\n-----"
echo "[i] Ghost is starting and running database migrations. This may take a minute."
echo "[i] Check logs: sudo docker compose -f ~/ghost_server-compose.yaml logs -f ghost"