diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..f6b2950 --- /dev/null +++ b/.env.example @@ -0,0 +1,7 @@ +# Copy to .env next to compose.yaml if you need non-default values. +# Do not commit a real .env file. + +GHOST_PORT=2373 +GHOST_URL=http://localhost:2373 +# Bind-mount for themes, images, and the SQLite database (same role as ~/.ghost/content). +# GHOST_CONTENT=/home/you/.ghost/content diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6277138..bca445c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,3 +23,19 @@ jobs: - name: Run static validation fixture tests run: bash tests/run-validation-tests.sh + + - name: Run compose and workflow fixture tests + run: bash tests/run-compose-tests.sh + + - name: Lint GitHub Actions workflows + run: | + bash <(curl --fail --silent --show-error --location https://raw.githubusercontent.com/rhysd/actionlint/914e7df21a07ef503a81201c76d2b11c789d3fca/scripts/download-actionlint.bash) 1.7.12 + ./actionlint -oneline + + compose-smoke: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Validate compose.yaml and boot Ghost + run: bash scripts/compose-smoke.sh --start diff --git a/.github/workflows/publish-static.yml b/.github/workflows/publish-static.yml new file mode 100644 index 0000000..903b8b1 --- /dev/null +++ b/.github/workflows/publish-static.yml @@ -0,0 +1,177 @@ +name: Publish static site + +# Reusable workflow: start Ghost (official image), run gssg, validate, optionally deploy Pages. +# Call from your blog repo — see examples/github/publish-static.yml and docs/v3/CI.md +# workflow_dispatch on this repository is a dry-run unless deploy_pages is true. + +on: + workflow_call: + inputs: + production_domain: + description: Public blog URL (https://USER.github.io/REPO) + required: true + type: string + gh_username: + description: GitHub username (used for gssg --subDir) + required: true + type: string + gh_repo: + description: Pages repository name + required: false + type: string + default: "" + ghost_port: + required: false + type: string + default: "2373" + content_path: + description: Directory in the caller repo to mount as Ghost content (themes, images, SQLite) + required: false + type: string + default: "content" + scripts_repository: + required: false + type: string + default: paladini/ghost-on-github-pages + scripts_ref: + required: false + type: string + default: master + deploy_pages: + required: false + type: boolean + default: true + allow_empty: + description: Export even when the content directory is missing (publishes a fresh empty Ghost) + required: false + type: boolean + default: false + workflow_dispatch: + inputs: + production_domain: + description: Public blog URL (https://USER.github.io/REPO) + required: true + type: string + gh_username: + description: GitHub username + required: true + type: string + gh_repo: + description: Pages repository name + required: false + type: string + default: "" + deploy_pages: + description: Deploy to GitHub Pages after export + required: false + type: boolean + default: false + allow_empty: + description: Export even when the content directory is missing + required: false + type: boolean + default: true + +permissions: + contents: read + pages: write + id-token: write + +concurrency: + group: pages-${{ github.repository }} + # Match the GitHub Pages starter: do not cancel an in-progress production deploy. + cancel-in-progress: false + +jobs: + export: + runs-on: ubuntu-latest + steps: + - name: Checkout caller repository + uses: actions/checkout@v4 + with: + path: blog + + - name: Checkout Ghost on GitHub Pages scripts + uses: actions/checkout@v4 + with: + # Reusable calls default to this repo on master. workflow_dispatch uses the current commit. + repository: ${{ inputs.scripts_repository || (github.event_name == 'workflow_dispatch' && github.repository || 'paladini/ghost-on-github-pages') }} + ref: ${{ inputs.scripts_ref || (github.event_name == 'workflow_dispatch' && github.sha || 'master') }} + path: gogp + + - name: Install wget and Node.js tools + run: | + sudo apt-get update + sudo apt-get install -y wget + npm install -g ghost-static-site-generator + + - name: Prepare Ghost content and blog folder + env: + CONTENT_PATH: ${{ inputs.content_path || 'content' }} + ALLOW_EMPTY: ${{ inputs.allow_empty }} + run: | + set -euo pipefail + WORKSPACE="${GITHUB_WORKSPACE}" + export GHOST_INSTALL="${WORKSPACE}/.gogp-home" + mkdir -p "${GHOST_INSTALL}" + CONTENT_SRC="${WORKSPACE}/blog/${CONTENT_PATH}" + if [ -d "$CONTENT_SRC" ]; then + export GHOST_CONTENT="$CONTENT_SRC" + elif [ "${ALLOW_EMPTY}" = "true" ]; then + export GHOST_CONTENT="${GHOST_INSTALL}/content" + mkdir -p "$GHOST_CONTENT" + echo "No ${CONTENT_PATH}/ in the repository; using an empty Ghost content directory." + else + echo "[ERROR] ${CONTENT_PATH}/ was not found in the repository." >&2 + echo "[ERROR] Refusing to publish an empty Ghost site. Add a content snapshot or set allow_empty: true." >&2 + exit 1 + fi + echo "GHOST_INSTALL=$GHOST_INSTALL" >> "$GITHUB_ENV" + echo "GHOST_CONTENT=$GHOST_CONTENT" >> "$GITHUB_ENV" + bash "${WORKSPACE}/gogp/scripts/compose-setup.sh" + + - name: Start Ghost + env: + GHOST_PORT: ${{ inputs.ghost_port || '2373' }} + GHOST_URL: http://localhost:${{ inputs.ghost_port || '2373' }} + run: | + set -euo pipefail + docker compose -f "${GITHUB_WORKSPACE}/gogp/compose.yaml" up -d + bash -c 'set -euo pipefail; source "${GITHUB_WORKSPACE}/gogp/includes/lib/common.sh"; wait_for_ghost_http 45' + + - name: Export static site + env: + GHOST_PORT: ${{ inputs.ghost_port || '2373' }} + GH_USERNAME: ${{ inputs.gh_username }} + GH_REPO: ${{ inputs.gh_repo }} + PRODUCTION_DOMAIN: ${{ inputs.production_domain }} + run: | + set -euo pipefail + export GHOST_SERVER_URL="http://localhost:${GHOST_PORT}" + bash "${GITHUB_WORKSPACE}/gogp/scripts/export-static.sh" + + - name: Stop Ghost + if: always() + run: docker compose -f "${GITHUB_WORKSPACE}/gogp/compose.yaml" down --remove-orphans || true + + - name: Setup GitHub Pages + if: ${{ inputs.deploy_pages == true || inputs.deploy_pages == 'true' }} + uses: actions/configure-pages@v5 + + - name: Upload GitHub Pages artifact + if: ${{ inputs.deploy_pages == true || inputs.deploy_pages == 'true' }} + uses: actions/upload-pages-artifact@v3 + with: + path: ${{ github.workspace }}/.gogp-home/publish + + deploy: + if: ${{ inputs.deploy_pages == true || inputs.deploy_pages == 'true' }} + needs: export + runs-on: ubuntu-latest + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + steps: + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v5 diff --git a/.gitignore b/.gitignore index bb2e082..f333be2 100644 --- a/.gitignore +++ b/.gitignore @@ -197,4 +197,7 @@ GitHub.sublime-settings # Track shell helpers (overrides Python lib/ ignore above) !includes/lib/ -!includes/lib/** \ No newline at end of file +!includes/lib/** + +# Local Compose scratch (CI smoke / docker volumes) +.tmp-ghost-content/ \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 0393e78..20270e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,21 @@ All notable changes to this project are documented here. +## [3.1.0] - 2026-11-16 + +### Fixed + +- Static publishing no longer stops when `wget` saves an HTTP error page (status 8), including Ghost's 404 page. That exit used to abort `gssg` before it rewrote localhost links. +- `gssg` is now called with `--url`, the flag that rewrites localhost links. gssg 1.1.4 ignores `--productionDomain`. +- Markdown indexes written by Ghost 6 get the same public URL rewrite, so validation no longer fails on those files. + +### Added + +- **Docker Compose** alternative to `install.sh` using the official `ghost:6` image, SQLite at `~/.ghost/content/data/ghost.db`, and a bind mount at `~/.ghost/content` ([#28](https://github.com/paladini/ghost-on-github-pages/issues/28)) +- `scripts/compose-setup.sh`, `scripts/export-static.sh`, and `scripts/compose-smoke.sh` +- Reusable GitHub Action to generate static files in CI and publish to GitHub Pages +- Guides: [docs/v3/DOCKER.md](docs/v3/DOCKER.md), [docs/v3/CI.md](docs/v3/CI.md) + ## [3.0.0] - 2026-07-03 ### Added diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 812f808..e0483b3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -43,10 +43,12 @@ CI runs the same checks on every pull request. Run them before submitting: ```bash bash scripts/shellcheck.sh bash tests/run-validation-tests.sh +bash tests/run-compose-tests.sh ``` - **shellcheck** — catches common mistakes in shell scripts (`install.sh`, `deploy.sh`, `migrate.sh`, and related files). - **Validation tests** — verify that published HTML does not contain broken `localhost` links or image paths. These tests protect users from bugs that only show up after publishing. +- **Compose tests** — check `compose.yaml` and the publish GitHub Action against the documented Ghost 6 / `~/.ghost` layout. If Docker is installed, also run `bash scripts/compose-smoke.sh` (add `--start` to boot the image). If you do not have `shellcheck` installed, the script skips that step with a warning. On Ubuntu/Debian: `sudo apt-get install shellcheck`. @@ -54,6 +56,7 @@ If you do not have `shellcheck` installed, the script skips that step with a war - [ ] `bash scripts/shellcheck.sh` passes (or only warns that shellcheck is missing) - [ ] `bash tests/run-validation-tests.sh` passes +- [ ] `bash tests/run-compose-tests.sh` passes - [ ] Documentation updated if behavior or user-facing steps changed - [ ] Commit message explains **why** the change helps users @@ -61,11 +64,14 @@ If you do not have `shellcheck` installed, the script skips that step with a war | Area | Purpose | |------|---------| -| `install.sh` | First-time setup | +| `install.sh` | First-time setup (Ghost-CLI) | +| `compose.yaml` / `scripts/compose-setup.sh` | Optional Docker Compose setup | | `migrate.sh` | Upgrade from Classic v2 to v3 | | `includes/deploy.sh` | Publish blog to GitHub Pages | | `includes/lib/common.sh` | Shared helpers | | `scripts/validate-static.sh` | Pre-publish HTML checks | +| `scripts/export-static.sh` | Static export without `git push` (host or CI) | +| `.github/workflows/publish-static.yml` | Reusable Pages publish Action | | `docs/` | User-facing guides | ## Questions? diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..e2aa1f9 --- /dev/null +++ b/compose.yaml @@ -0,0 +1,30 @@ +# Official Ghost image for local editing. Static export still uses gssg (host or CI). +# See docs/v3/DOCKER.md + +# Fixed project name so `docker compose up/down` is the same stack from this +# repository and from ~/.ghost. +name: gogp + +services: + ghost: + image: ghost:6 + ports: + - "${GHOST_PORT:-2373}:2368" + environment: + NODE_ENV: development + url: ${GHOST_URL:-http://localhost:2373} + database__client: sqlite3 + database__connection__filename: /var/lib/ghost/content/data/ghost.db + volumes: + - ${GHOST_CONTENT:-${HOME}/.ghost/content}:/var/lib/ghost/content + healthcheck: + test: + [ + "CMD-SHELL", + "node -e \"require('http').get('http://127.0.0.1:2368', r => process.exit(r.statusCode >= 200 && r.statusCode < 500 ? 0 : 1)).on('error', () => process.exit(1))\"", + ] + interval: 10s + timeout: 5s + retries: 12 + start_period: 40s + restart: unless-stopped diff --git a/docs/GLOSSARY.md b/docs/GLOSSARY.md index 43b785f..c8fc20c 100644 --- a/docs/GLOSSARY.md +++ b/docs/GLOSSARY.md @@ -26,4 +26,8 @@ Short definitions for words used in this project. **wget** — A small program used behind the scenes to copy web pages when building your static site. The install guide helps you install it if needed. -**Node.js (Node)** — Software Ghost needs to run. You install it once before using this project. +**Node.js (Node)** — Software Ghost needs to run (and that `gssg` uses when publishing). You install it once before using this project, even if Ghost itself runs in Docker. + +**Docker Compose** — A way to run Ghost in a container using the official `ghost:6` image, with your files in `~/.ghost/content`. See [v3/DOCKER.md](v3/DOCKER.md). + +**GitHub Action** — A script GitHub runs for you. This project can generate the static blog in CI and publish it to GitHub Pages. See [v3/CI.md](v3/CI.md). diff --git a/docs/README.md b/docs/README.md index 7cb5e13..1f30dcd 100644 --- a/docs/README.md +++ b/docs/README.md @@ -21,6 +21,8 @@ Pick the guide that matches your situation. - [What to install first](v3/REQUIREMENTS.md) - [Getting started — new blog](v3/GETTING-STARTED.md) - [How to publish changes](v3/DEPLOY.md) +- [Run Ghost with Docker Compose](v3/DOCKER.md) +- [Publish from GitHub Actions](v3/CI.md) - [Multiple GitHub repositories (optional)](v3/MULTI-REPO.md) ## Classic version 2.x (maintenance) diff --git a/docs/TROUBLESHOOTING.md b/docs/TROUBLESHOOTING.md index 4aaf9d9..97f4bd4 100644 --- a/docs/TROUBLESHOOTING.md +++ b/docs/TROUBLESHOOTING.md @@ -20,6 +20,30 @@ Answers in plain English. If you are stuck, [open an issue](https://github.com/p 2. Make sure you have an internet connection. 3. On Linux, you may need `curl` and build tools for Ghost — see Ghost's official docs. +## Docker Compose + +### `docker compose` is not found + +Install Docker Desktop (Windows/macOS) or Docker Engine + the Compose plugin (Linux). In WSL, enable the Docker Desktop WSL integration. See [DOCKER.md](v3/DOCKER.md). + +### Ghost never opens at http://localhost:2373 + +1. Run `docker compose ps` and `docker compose logs ghost`. +2. Confirm nothing else is using port **2373**. +3. If you set `GHOST_PORT`, also set `GHOST_URL` to `http://localhost:THAT_PORT`. + +### Posts disappear after `docker compose down` + +The database must be `~/.ghost/content/data/ghost.db`. If that file is missing, the container was not using the Compose file from this project. Run `./scripts/compose-setup.sh` again and start Ghost with `docker compose up -d` so the project name is `gogp`. + +### `uninstall.sh` says the stack may still be running + +Docker could not stop the `gogp` project. Run `docker compose ps` in `~/.ghost` and then `docker compose down`. Your files are still in `~/.ghost` until you delete that folder yourself. + +### `deploy.sh` says the blog folder is not set up + +Run `./scripts/compose-setup.sh` from this project first so `~/.ghost/.docker` and `deploy.sh` exist. Do not mix a Ghost-CLI install and Compose in the same `~/.ghost` folder. + ## Publish problems ### "Static files were not created" @@ -35,6 +59,8 @@ Answers in plain English. If you are stuck, [open an issue](https://github.com/p ghost start ``` + Or, with Docker: `docker compose up -d` (see [DOCKER.md](v3/DOCKER.md)). + 2. Open `http://localhost:2373` in your browser and confirm the blog loads. 3. Run `./deploy.sh` again. diff --git a/docs/v3/CI.md b/docs/v3/CI.md new file mode 100644 index 0000000..7d41aa5 --- /dev/null +++ b/docs/v3/CI.md @@ -0,0 +1,68 @@ +# Generate the static site in GitHub Actions (version 3) + +Two supported ways to get HTML onto GitHub Pages: + +1. **Local publish (default)** — run `./deploy.sh` from `~/.ghost`. This is what [DEPLOY.md](DEPLOY.md) describes. +2. **CI publish** — start Ghost in GitHub Actions with Docker Compose, run `gssg`, then deploy the artifact to GitHub Pages. + +CI does **not** replace Ghost or `gssg`. It runs the same export path as `scripts/export-static.sh`. + +## What the Action does + +The reusable workflow [`.github/workflows/publish-static.yml`](../../.github/workflows/publish-static.yml): + +1. Checks out your blog repository. +2. Starts the official **`ghost:6`** image with your `content/` folder mounted. If that folder is missing, the job fails unless `allow_empty` is true. +3. Waits until Ghost answers on `localhost:2373`. +4. Runs `gssg` with `--url` (and `--subDir` when the repo is not `USERNAME.github.io`). +5. Runs `scripts/validate-static.sh`. +6. Uploads `publish/` and deploys with official GitHub Pages actions (`upload-pages-artifact` + `deploy-pages`). + +You can still push to a **separate Pages repo** with `deploy.sh` instead of GitHub Actions. That remains the original v3 pattern. + +## Add the workflow to your blog repository + +1. Copy [examples/github/publish-static.yml](../../examples/github/publish-static.yml) to `.github/workflows/publish-static.yml` in **your** blog repo. +2. Replace `YOUR_USERNAME` and `YOUR_REPO`. +3. In GitHub: **Settings → Pages → Source → GitHub Actions**. +4. Put a Ghost **content snapshot** in `content/` before the first deploy. The workflow stops if that folder is missing, so it does not replace your Pages site with an empty Ghost: + + ``` + content/data/ # SQLite database (ghost.db) + content/images/ + content/themes/ + ``` + + Copy from `~/.ghost/content` after you have used Ghost locally. + +**Do not commit secrets.** Leave `.env` out of git. Do not put SMTP, Stripe, or Mailgun keys in `content/settings`. A local SQLite blog with no members/payment config is enough. + +## Inputs + +| Input | Required | Default | Meaning | +|-------|----------|---------|---------| +| `production_domain` | yes | | Public URL, e.g. `https://you.github.io/my-blog` | +| `gh_username` | yes | | Used to compute `gssg --subDir` | +| `gh_repo` | no | empty | Repository name; empty or `you.github.io` means site root | +| `content_path` | no | `content` | Folder in the **caller** repo mounted as Ghost content | +| `ghost_port` | no | `2373` | Host port inside the job | +| `deploy_pages` | no | `true` | Set `false` to export without deploying | +| `allow_empty` | no | `false` | Set `true` only when you intend to export a fresh empty Ghost | +| `scripts_repository` / `scripts_ref` | no | this project / `master` | Where to load `compose.yaml` and scripts | + +No tokens beyond `GITHUB_TOKEN` (Pages permissions) are required. + +## Dry-run on this project + +`workflow_dispatch` on `publish-static.yml` in **this** repository exports a site without deploying (`deploy_pages` defaults to `false`, `allow_empty` defaults to `true`). CI also runs `scripts/compose-smoke.sh --start`, which fails unless `content/data/ghost.db` is written on the mount. + +## Keep using `deploy.sh` + +If you do not want to version `content/`, keep editing locally and run: + +``` +cd ~/.ghost +./deploy.sh +``` + +That pushes static files to the Pages repo you already use. The Action is optional. diff --git a/docs/v3/DEPLOY.md b/docs/v3/DEPLOY.md index 38309d9..1ee5bc1 100644 --- a/docs/v3/DEPLOY.md +++ b/docs/v3/DEPLOY.md @@ -6,11 +6,21 @@ After you edit your blog locally, use `deploy.sh` to send updates to GitHub Page 1. Make sure Ghost is running: + **Ghost-CLI (`install.sh`):** + ``` cd ~/.ghost ghost start ``` + **Docker Compose:** + + ``` + docker compose up -d + ``` + + (from this project folder or from `~/.ghost` — see [DOCKER.md](DOCKER.md)) + 2. Edit your blog at **http://localhost:2373/ghost** 3. Publish to the web: @@ -47,10 +57,14 @@ See [TROUBLESHOOTING.md](../TROUBLESHOOTING.md). Common fixes: -- Run `ghost start` before `deploy.sh` +- Run `ghost start` (Ghost-CLI) or `docker compose up -d` (Compose) before `deploy.sh` - Check your internet connection - Confirm your GitHub repository still exists and is public +## Publish from GitHub Actions + +To generate static files in CI and deploy with GitHub Pages actions, see [CI.md](CI.md). You can still use `deploy.sh` to push to the Pages repository you already use. + ## Multiple repositories If you publish to more than one GitHub repo, see [MULTI-REPO.md](MULTI-REPO.md). diff --git a/docs/v3/DOCKER.md b/docs/v3/DOCKER.md new file mode 100644 index 0000000..0726035 --- /dev/null +++ b/docs/v3/DOCKER.md @@ -0,0 +1,117 @@ +# Run Ghost with Docker Compose (version 3) + +Use this if you prefer Docker instead of `install.sh` (Ghost-CLI + Node on your computer). Publishing still uses **gssg** and `deploy.sh` — Ghost itself is not rewritten. + +This is the easier path on **Windows with WSL**. + +## What you'll need + +| Item | Why | +|------|-----| +| [Docker](https://docs.docker.com/get-docker/) with Compose v2 | Runs the official Ghost image | +| `wget` and [Node.js](https://nodejs.org/) LTS | Needed on the **host** for `gssg` when you publish | +| A free [GitHub](https://github.com) account | Hosts the static blog | + +You do **not** need Ghost-CLI for this path. + +### Windows (WSL) + +1. Install [Docker Desktop](https://docs.docker.com/desktop/setup/install/windows-install/) with the **WSL 2** engine. +2. Install a Linux distro from the Microsoft Store (Ubuntu is fine) and open it. +3. In that WSL terminal, confirm: + + ``` + docker compose version + ``` + +## Ghost version + +`install.sh` installs Ghost via `ghost-cli@latest` (currently Ghost **6**). Compose uses the same major: **`ghost:6`** (official image). + +## Step 1 — Prepare `~/.ghost` + +From this project folder: + +``` +chmod +x scripts/compose-setup.sh +./scripts/compose-setup.sh +``` + +This creates your **blog folder** at `~/.ghost`, including: + +| Path | Role | +|------|------| +| `~/.ghost/content/` | Themes, images, and the SQLite database (`content/data/ghost.db`) | +| `~/.ghost/current/` | Where `gssg` writes `static/` (same as the Ghost-CLI layout) | +| `~/.ghost/deploy.sh` | Same publish script as `install.sh` | +| `~/.ghost/.docker` | Tells `deploy.sh` that Ghost runs in Docker | + +## Step 2 — Start Ghost + +From this project folder (or from `~/.ghost`, which has a copy of `compose.yaml`): + +``` +docker compose up -d +``` + +Optional environment variables (see `.env.example`; do not commit a real `.env`): + +| Variable | Default | Meaning | +|----------|---------|---------| +| `GHOST_PORT` | `2373` | Host port | +| `GHOST_URL` | `http://localhost:2373` | URL Ghost uses for links | +| `GHOST_CONTENT` | `$HOME/.ghost/content` | Bind mount for content | + +If you change `GHOST_PORT`, set `GHOST_URL` to match (for example `http://localhost:2373`). + +Compose uses the project name `gogp`. Starting or stopping from this folder and from `~/.ghost` controls the same stack. + +The database file is `~/.ghost/content/data/ghost.db`. Posts stay there when the container is removed. This SQLite setup does not run Ghost's MySQL job outbox; those jobs use Ghost's direct-dispatch path. Publishing with `gssg` does not need MySQL. + +Ghost may log a connection error while measuring an image, because inside the container it calls `http://localhost:2373` and the process itself listens on port 2368. The blog on your computer is still at that URL. `gssg` runs on the host and reads it from there. + +## Step 3 — Open Ghost Admin + +1. Open a browser. +2. Go to **http://localhost:2373/ghost** +3. Create your admin account and write posts. + +The public preview of the local blog is **http://localhost:2373**. + +## Step 4 — Publish with `deploy.sh` + +Keep the container running. On the **host** (WSL or macOS/Linux): + +``` +cd ~/.ghost +./deploy.sh +``` + +`deploy.sh` calls `gssg` against `http://localhost:2373`, validates the HTML, and pushes to your GitHub Pages repository — the same flow as after `install.sh`. + +To export files **without** pushing: + +``` +export GH_USERNAME=yourname +export GH_REPO=your-repo +cd ~/.ghost +./scripts/export-static.sh +``` + +Static files land in `~/.ghost/publish/`. + +## Stop or remove + +``` +docker compose down +``` + +Your posts stay in `~/.ghost/content`. To uninstall, run `~/.ghost/uninstall.sh` (stops Compose; you delete the folder yourself if you want a full cleanup). + +## GitHub Actions + +To generate and publish the static site in CI, see [CI.md](CI.md). + +## If something goes wrong + +See [TROUBLESHOOTING.md](../TROUBLESHOOTING.md). diff --git a/docs/v3/GETTING-STARTED.md b/docs/v3/GETTING-STARTED.md index 9819f72..6516d94 100644 --- a/docs/v3/GETTING-STARTED.md +++ b/docs/v3/GETTING-STARTED.md @@ -8,6 +8,8 @@ Set up a free Ghost blog on GitHub Pages in a few steps. Complete [REQUIREMENTS.md](REQUIREMENTS.md) first (Node.js, wget, GitHub account). +Prefer Docker instead of installing Ghost with Node on your computer? Follow [DOCKER.md](DOCKER.md) (recommended on Windows/WSL), then continue from **Step 3** below. + ## Step 1 — Download version 3 1. Download the latest release: [github.com/paladini/ghost-on-github-pages/releases/latest](https://github.com/paladini/ghost-on-github-pages/releases/latest) diff --git a/docs/v3/REQUIREMENTS.md b/docs/v3/REQUIREMENTS.md index 8c3f51d..a3eec11 100644 --- a/docs/v3/REQUIREMENTS.md +++ b/docs/v3/REQUIREMENTS.md @@ -6,7 +6,7 @@ Install these **before** running `install.sh`. | Item | Why | |------|-----| -| A computer with macOS or Linux | Windows users can try [WSL](https://learn.microsoft.com/en-us/windows/wsl/) | +| A computer with macOS or Linux | Windows users can try [WSL](https://learn.microsoft.com/en-us/windows/wsl/). On WSL, [Docker Compose](DOCKER.md) is often easier than `install.sh`. | | [Node.js](https://nodejs.org/) LTS (v18 or v20) | Runs Ghost | | `wget` | Used when creating your static site | | A free [GitHub](https://github.com) account | Hosts your blog for free | @@ -14,6 +14,8 @@ Install these **before** running `install.sh`. You do **not** need Python for version 3. +To run Ghost in Docker instead of Ghost-CLI, you also need Docker Compose v2 — see [DOCKER.md](DOCKER.md). + ## Step 1 — Install Node.js 1. Go to [https://nodejs.org/](https://nodejs.org/) @@ -69,7 +71,7 @@ Example URL: `git@github.com:yourname/my-blog.git` ## Optional — Ghost version note -Version 3 uses Ghost installed via Ghost-CLI. If you hit compatibility issues, see [TROUBLESHOOTING.md](../TROUBLESHOOTING.md) or open an issue. +Version 3 uses Ghost installed via Ghost-CLI (`ghost-cli@latest`, currently Ghost 6) or the official Docker image `ghost:6`. If you hit compatibility issues, see [TROUBLESHOOTING.md](../TROUBLESHOOTING.md) or open an issue. ## Next step diff --git a/examples/github/publish-static.yml b/examples/github/publish-static.yml new file mode 100644 index 0000000..0ff3bcf --- /dev/null +++ b/examples/github/publish-static.yml @@ -0,0 +1,27 @@ +# Copy this file to YOUR BLOG REPOSITORY as .github/workflows/publish-static.yml +# content/ is required (themes, images, data/ghost.db). Without it the workflow fails +# instead of publishing an empty site. Do not commit secrets. +# Enable GitHub Pages: Settings → Pages → Source: GitHub Actions +# See docs/v3/CI.md + +name: Publish static site + +on: + push: + branches: [main, master] + workflow_dispatch: + +permissions: + contents: read + pages: write + id-token: write + +jobs: + publish: + uses: paladini/ghost-on-github-pages/.github/workflows/publish-static.yml@master + with: + production_domain: https://YOUR_USERNAME.github.io/YOUR_REPO + gh_username: YOUR_USERNAME + gh_repo: YOUR_REPO + content_path: content + deploy_pages: true diff --git a/includes/lib/common.sh b/includes/lib/common.sh index 0c190d3..d9b71d2 100644 --- a/includes/lib/common.sh +++ b/includes/lib/common.sh @@ -1,14 +1,14 @@ #!/usr/bin/env bash # Shared helpers for install, deploy, and migrate scripts. -GHOST_INSTALL="${HOME}/.ghost" -GHOST_PATH="${GHOST_INSTALL}/current" +GHOST_INSTALL="${GHOST_INSTALL:-${HOME}/.ghost}" +GHOST_PATH="${GHOST_PATH:-${GHOST_INSTALL}/current}" GHOST_PORT="${GHOST_PORT:-2373}" -GHOST_SERVER_URL="http://localhost:${GHOST_PORT}" -PUBLISH_PATH="${GHOST_INSTALL}/publish" -DEPLOY_CONF="${GHOST_INSTALL}/deploy.conf" -SITES_CONF="${GHOST_INSTALL}/sites.conf" -SCRIPT_VERSION="3.0.0" +GHOST_SERVER_URL="${GHOST_SERVER_URL:-http://localhost:${GHOST_PORT}}" +PUBLISH_PATH="${PUBLISH_PATH:-${GHOST_INSTALL}/publish}" +DEPLOY_CONF="${DEPLOY_CONF:-${GHOST_INSTALL}/deploy.conf}" +SITES_CONF="${SITES_CONF:-${GHOST_INSTALL}/sites.conf}" +SCRIPT_VERSION="3.1.0" die() { echo "[ERROR] $*" >&2 @@ -29,10 +29,40 @@ require_command() { fi } +ghost_is_docker() { + [ -f "${GHOST_INSTALL}/.docker" ] +} + ghost_current_ready() { + if ghost_is_docker; then + [ -d "${GHOST_INSTALL}/content" ] && [ -d "${GHOST_PATH}" ] + return + fi [ -d "${GHOST_PATH}" ] && { [ -f "${GHOST_PATH}/config.development.json" ] || [ -L "${GHOST_PATH}" ]; } } +ghost_http_up() { + local code + if command -v curl >/dev/null 2>&1; then + code="$(curl -s -o /dev/null --max-time 3 -w "%{http_code}" "${GHOST_SERVER_URL}" || true)" + [[ "$code" =~ ^[23][0-9][0-9]$ ]] + return + fi + wget -q --spider --timeout=3 "${GHOST_SERVER_URL}" 2>/dev/null +} + +wait_for_ghost_http() { + local tries="${1:-30}" + local i + for ((i = 1; i <= tries; i++)); do + if ghost_http_up; then + return 0 + fi + sleep 2 + done + return 1 +} + production_domain_for() { local username="$1" local repo="$2" @@ -65,11 +95,41 @@ run_gssg() { info "Creating static files from your blog. This may take a minute..." + require_command wget + # gssg requests /404 and old Ghost asset paths with wget --content-on-error. + # wget 1.21 still exits 8 after saving an HTTP error page, and gssg then + # stops before rewriting localhost links. Exit 8 means the server answered + # with an error. Connection failures use a different status and still abort. + local wget_bin wrap + wget_bin="$(command -v wget)" + wrap="$(mktemp -d)" + cat > "${wrap}/wget" << EOF +#!/bin/sh +"${wget_bin}" "\$@" +status=\$? +if [ "\$status" -eq 8 ]; then + exit 0 +fi +exit "\$status" +EOF + chmod +x "${wrap}/wget" + + local gssg_status=0 if [ -n "$subdir" ]; then - gssg --domain "$GHOST_SERVER_URL" --productionDomain "$production_domain" --dest "$dest" --subDir "$subdir" --fail-on-error + PATH="${wrap}:${PATH}" gssg --domain "$GHOST_SERVER_URL" --url "$production_domain" --dest "$dest" --subDir "$subdir" --fail-on-error || gssg_status=$? else - gssg --domain "$GHOST_SERVER_URL" --productionDomain "$production_domain" --dest "$dest" --fail-on-error + PATH="${wrap}:${PATH}" gssg --domain "$GHOST_SERVER_URL" --url "$production_domain" --dest "$dest" --fail-on-error || gssg_status=$? fi + rm -rf "$wrap" + if [ "$gssg_status" -ne 0 ]; then + exit "$gssg_status" + fi + + # Ghost 6 also writes Markdown indexes. gssg rewrites html/xml/js only. + while IFS= read -r file; do + sed "s|${GHOST_SERVER_URL}|${production_domain}|g" "$file" > "${file}.rewritten" + mv "${file}.rewritten" "$file" + done < <(find "$dest" -type f -name '*.md') } prepare_publish_dir() { @@ -177,7 +237,20 @@ ensure_gssg() { ensure_ghost_running() { if ! ghost_current_ready; then - die "Your blog folder is not set up yet. Run install.sh first." + die "Your blog folder is not set up yet. Run install.sh or scripts/compose-setup.sh first." + fi + + if ghost_is_docker; then + if ghost_http_up; then + return 0 + fi + if [ -f "${GHOST_INSTALL}/compose.yaml" ] && command -v docker >/dev/null 2>&1; then + info "Starting your local blog with Docker Compose..." + (cd "$GHOST_INSTALL" && docker compose up -d) || die "Could not start Ghost. See docs/v3/DOCKER.md" + wait_for_ghost_http 40 || die "Ghost did not become ready at ${GHOST_SERVER_URL}. See docs/v3/DOCKER.md" + return 0 + fi + die "Ghost is not running at ${GHOST_SERVER_URL}. Start it with: docker compose up -d (see docs/v3/DOCKER.md)" fi cd "$GHOST_INSTALL" || die "Could not open your blog folder at ${GHOST_INSTALL}" @@ -188,6 +261,9 @@ ensure_ghost_running() { } configure_ghost_url() { + if ghost_is_docker; then + return 0 + fi if ghost_current_ready; then cd "$GHOST_INSTALL" || return 0 ghost config url "$GHOST_SERVER_URL" >/dev/null 2>&1 || true diff --git a/includes/uninstall.sh b/includes/uninstall.sh index 5075764..0a64505 100755 --- a/includes/uninstall.sh +++ b/includes/uninstall.sh @@ -3,7 +3,7 @@ set -euo pipefail HOME_PATH="${HOME}" -GHOST_INSTALL="${HOME_PATH}/.ghost" +GHOST_INSTALL="${GHOST_INSTALL:-${HOME_PATH}/.ghost}" uninstall() { if [ ! -d "$GHOST_INSTALL" ]; then @@ -18,6 +18,24 @@ uninstall() { exit 0 fi + if [ -f "${GHOST_INSTALL}/.docker" ]; then + if ! command -v docker >/dev/null 2>&1; then + echo "[WARN] Docker is not available. The Compose stack may still be running." >&2 + exit 1 + fi + if [ ! -f "${GHOST_INSTALL}/compose.yaml" ]; then + echo "[WARN] ${GHOST_INSTALL}/compose.yaml is missing. The Compose stack may still be running." >&2 + exit 1 + fi + if ! (cd "$GHOST_INSTALL" && docker compose down); then + echo "[WARN] Could not stop the Docker Compose stack. It may still be running." >&2 + exit 1 + fi + echo "[INFO] Docker Compose Ghost was stopped. Your files are still in ${GHOST_INSTALL}." + echo "[INFO] Delete that folder yourself if you want a full cleanup (includes posts and images)." + exit 0 + fi + cd "$GHOST_INSTALL" && ghost uninstall --no-prompt --force echo "[INFO] Ghost has been removed from your computer." } diff --git a/install.sh b/install.sh index 382f2b5..3b0f4cb 100755 --- a/install.sh +++ b/install.sh @@ -82,10 +82,13 @@ move_includes() { cp "${ABSOLUTE_PATH}/includes/deploy.sh" "${GHOST_INSTALL}/" cp "${ABSOLUTE_PATH}/includes/uninstall.sh" "${GHOST_INSTALL}/" - cp -R "${ABSOLUTE_PATH}/includes/lib" "${GHOST_INSTALL}/lib" + mkdir -p "${GHOST_INSTALL}/lib" + # Copy contents. `cp -R src dest` nests src inside dest when dest already exists. + cp -R "${ABSOLUTE_PATH}/includes/lib/." "${GHOST_INSTALL}/lib/" mkdir -p "${GHOST_INSTALL}/scripts" cp "${ABSOLUTE_PATH}/scripts/validate-static.sh" "${GHOST_INSTALL}/scripts/" - chmod +x "${GHOST_INSTALL}/scripts/validate-static.sh" + cp "${ABSOLUTE_PATH}/scripts/export-static.sh" "${GHOST_INSTALL}/scripts/" + chmod +x "${GHOST_INSTALL}/scripts/validate-static.sh" "${GHOST_INSTALL}/scripts/export-static.sh" cp "${ABSOLUTE_PATH}/includes/index.html" "${GHOST_PATH}/" cp "${ABSOLUTE_PATH}/includes/gitignore.base" "${GHOST_PATH}/" cp "${ABSOLUTE_PATH}/includes/gitignore.base" "${GHOST_PATH}/.gitignore" diff --git a/readme.md b/readme.md index cd79041..49de243 100644 --- a/readme.md +++ b/readme.md @@ -35,6 +35,8 @@ **Full details:** [Release notes](RELEASE_NOTES_v3.0.0.md) · [Changelog](CHANGELOG.md) +**3.1.0** adds Docker Compose and a GitHub Action for static publish. See the [3.1.0 changelog](CHANGELOG.md#310---2026-11-16). + ## How your blog gets online ```mermaid @@ -49,6 +51,8 @@ flowchart LR | I want to… | Start here | |------------|------------| | Set up a **new** blog | [Getting Started](docs/v3/GETTING-STARTED.md) | +| Run Ghost with **Docker** (Windows/WSL) | [Docker Compose](docs/v3/DOCKER.md) | +| Publish from **GitHub Actions** | [CI / Pages](docs/v3/CI.md) | | **Upgrade** from Classic v2 | [Migration guide](docs/MIGRATION.md) | | Fix a **problem** | [Troubleshooting](docs/TROUBLESHOOTING.md) | | Understand a **term** | [Glossary](docs/GLOSSARY.md) | diff --git a/scripts/compose-setup.sh b/scripts/compose-setup.sh new file mode 100755 index 0000000..047d5af --- /dev/null +++ b/scripts/compose-setup.sh @@ -0,0 +1,61 @@ +#!/usr/bin/env bash +# Copy publish scripts into ~/.ghost for the Docker Compose path. +# Does not install Ghost-CLI; start Ghost with: docker compose up -d + +set -euo pipefail + +SOURCE="${BASH_SOURCE[0]}" +while [ -h "$SOURCE" ]; do + ABSOLUTE_PATH="$(cd -P "$(dirname "$SOURCE")" && pwd)" + SOURCE="$(readlink "$SOURCE")" + [[ $SOURCE != /* ]] && SOURCE="$ABSOLUTE_PATH/$SOURCE" +done +ABSOLUTE_PATH="$(cd -P "$(dirname "$SOURCE")" && pwd)" +ROOT="$(cd "${ABSOLUTE_PATH}/.." && pwd)" + +# shellcheck source=includes/lib/common.sh +source "${ROOT}/includes/lib/common.sh" + +usage() { + echo "Usage: compose-setup.sh" + echo "" + echo " Prepares ~/.ghost for Ghost running in Docker Compose." + echo " Then run: docker compose up -d" + echo " See docs/v3/DOCKER.md" +} + +if [ "${1:-}" = "-h" ] || [ "${1:-}" = "--help" ]; then + usage + exit 0 +fi + +if [ -d "${GHOST_PATH}" ] && [ -L "${GHOST_PATH}" ]; then + die "A Ghost-CLI install already exists at ${GHOST_INSTALL}. Use that, or move it aside before using Compose." +fi + +info "Preparing blog folder at ${GHOST_INSTALL}..." +mkdir -p "${GHOST_INSTALL}/content" "${GHOST_PATH}" "${GHOST_INSTALL}/scripts" + +cp "${ROOT}/includes/deploy.sh" "${GHOST_INSTALL}/" +cp "${ROOT}/includes/uninstall.sh" "${GHOST_INSTALL}/" +mkdir -p "${GHOST_INSTALL}/lib" +# Copy contents. `cp -R src dest` nests src inside dest when dest already exists. +cp -R "${ROOT}/includes/lib/." "${GHOST_INSTALL}/lib/" +cp "${ROOT}/scripts/validate-static.sh" "${GHOST_INSTALL}/scripts/" +cp "${ROOT}/scripts/export-static.sh" "${GHOST_INSTALL}/scripts/" +cp "${ROOT}/compose.yaml" "${GHOST_INSTALL}/compose.yaml" +if [ -f "${ROOT}/.env.example" ]; then + cp "${ROOT}/.env.example" "${GHOST_INSTALL}/.env.example" +fi +cp "${ROOT}/includes/index.html" "${GHOST_PATH}/" +cp "${ROOT}/includes/gitignore.base" "${GHOST_PATH}/.gitignore" +chmod +x "${GHOST_INSTALL}/deploy.sh" "${GHOST_INSTALL}/uninstall.sh" +chmod +x "${GHOST_INSTALL}/scripts/validate-static.sh" "${GHOST_INSTALL}/scripts/export-static.sh" + +touch "${GHOST_INSTALL}/.docker" + +info "Done. Start Ghost with:" +info " cd ${ROOT} && docker compose up -d" +info " # or: cd ${GHOST_INSTALL} && docker compose up -d" +info "Open the editor at: ${GHOST_SERVER_URL}/ghost" +info "When you are ready to go live: cd ~/.ghost && ./deploy.sh" diff --git a/scripts/compose-smoke.sh b/scripts/compose-smoke.sh new file mode 100755 index 0000000..1932bc1 --- /dev/null +++ b/scripts/compose-smoke.sh @@ -0,0 +1,64 @@ +#!/usr/bin/env bash +# Validate compose.yaml and optionally start Ghost long enough to prove it responds. + +set -euo pipefail + +ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +COMPOSE_FILE="${ROOT}/compose.yaml" +START_GHOST="${COMPOSE_SMOKE_START:-0}" + +if [ "${1:-}" = "--start" ]; then + START_GHOST=1 +fi + +if ! command -v docker >/dev/null 2>&1; then + echo "[WARN] docker is not installed; skipping compose smoke." + exit 0 +fi + +if ! docker compose version >/dev/null 2>&1; then + echo "[WARN] docker compose is not available; skipping compose smoke." + exit 0 +fi + +export GHOST_PORT="${GHOST_PORT:-2373}" +export GHOST_URL="${GHOST_URL:-http://localhost:${GHOST_PORT}}" +export GHOST_CONTENT="${GHOST_CONTENT:-${ROOT}/.tmp-ghost-content}" +mkdir -p "$GHOST_CONTENT" + +echo "[INFO] Validating ${COMPOSE_FILE}..." +docker compose -f "$COMPOSE_FILE" config >/dev/null +echo "[OK] compose.yaml is valid." + +if [ "$START_GHOST" != "1" ]; then + exit 0 +fi + +cleanup() { + docker compose -f "$COMPOSE_FILE" down --remove-orphans >/dev/null 2>&1 || true +} +trap cleanup EXIT + +echo "[INFO] Starting Ghost (this downloads ghost:6 on first run)..." +docker compose -f "$COMPOSE_FILE" up -d + +# shellcheck source=includes/lib/common.sh +source "${ROOT}/includes/lib/common.sh" +GHOST_SERVER_URL="http://localhost:${GHOST_PORT}" + +if ! wait_for_ghost_http 45; then + docker compose -f "$COMPOSE_FILE" logs ghost >&2 || true + echo "[ERROR] Ghost did not become ready at ${GHOST_SERVER_URL}" >&2 + exit 1 +fi + +DB_FILE="${GHOST_CONTENT}/data/ghost.db" +if [ ! -f "$DB_FILE" ]; then + docker compose -f "$COMPOSE_FILE" logs ghost >&2 || true + echo "[ERROR] SQLite database was not written to ${DB_FILE}" >&2 + echo "[ERROR] Posts would be lost when the container is removed." >&2 + exit 1 +fi + +echo "[OK] Ghost responded at ${GHOST_SERVER_URL}" +echo "[OK] SQLite database is at ${DB_FILE}" diff --git a/scripts/export-static.sh b/scripts/export-static.sh new file mode 100755 index 0000000..db007cc --- /dev/null +++ b/scripts/export-static.sh @@ -0,0 +1,67 @@ +#!/usr/bin/env bash +# Create static files from a running Ghost (Ghost-CLI or Docker). Does not push to GitHub. + +set -euo pipefail + +SOURCE="${BASH_SOURCE[0]}" +while [ -h "$SOURCE" ]; do + ABSOLUTE_PATH="$(cd -P "$(dirname "$SOURCE")" && pwd)" + SOURCE="$(readlink "$SOURCE")" + [[ $SOURCE != /* ]] && SOURCE="$ABSOLUTE_PATH/$SOURCE" +done +ABSOLUTE_PATH="$(cd -P "$(dirname "$SOURCE")" && pwd)" + +if [ -f "${ABSOLUTE_PATH}/../includes/lib/common.sh" ]; then + ROOT="$(cd "${ABSOLUTE_PATH}/.." && pwd)" + # shellcheck source=includes/lib/common.sh + source "${ROOT}/includes/lib/common.sh" + VALIDATE_SCRIPT="${ROOT}/scripts/validate-static.sh" + INCLUDE_INDEX="${ROOT}/includes/index.html" +else + # Copied into ~/.ghost/scripts by compose-setup.sh / install.sh + # shellcheck source=lib/common.sh + source "${ABSOLUTE_PATH}/../lib/common.sh" + VALIDATE_SCRIPT="${GHOST_INSTALL}/scripts/validate-static.sh" + INCLUDE_INDEX="${GHOST_PATH}/index.html" +fi + +usage() { + echo "Usage: export-static.sh" + echo "" + echo " Reads Ghost at http://localhost:${GHOST_PORT:-2373} and writes static files." + echo " Set GH_USERNAME and GH_REPO (or PRODUCTION_DOMAIN) before running." + echo " See docs/v3/CI.md" +} + +if [ "${1:-}" = "-h" ] || [ "${1:-}" = "--help" ]; then + usage + exit 0 +fi + +GH_USERNAME="${GH_USERNAME:-}" +GH_REPO="${GH_REPO:-}" +PRODUCTION_DOMAIN="${PRODUCTION_DOMAIN:-}" + +if [ -z "$PRODUCTION_DOMAIN" ]; then + if [ -z "$GH_USERNAME" ]; then + die "Set PRODUCTION_DOMAIN or GH_USERNAME (and GH_REPO). See docs/v3/CI.md" + fi + PRODUCTION_DOMAIN="$(production_domain_for "$GH_USERNAME" "$GH_REPO")" +fi + +SUBDIR="$(gssg_subdir_for "$GH_USERNAME" "$GH_REPO")" + +require_command wget +ensure_gssg +ensure_ghost_running + +run_gssg "$PRODUCTION_DOMAIN" "$SUBDIR" +prepare_publish_dir "${GHOST_PATH}" +if [ -f "$INCLUDE_INDEX" ]; then + cp "$INCLUDE_INDEX" "$PUBLISH_PATH/index.html" +fi + +"$VALIDATE_SCRIPT" "$PUBLISH_PATH/static" + +info "Static files are in ${PUBLISH_PATH}" +info "Live URL will be ${PRODUCTION_DOMAIN}" diff --git a/tests/run-compose-tests.sh b/tests/run-compose-tests.sh new file mode 100755 index 0000000..b60db9f --- /dev/null +++ b/tests/run-compose-tests.sh @@ -0,0 +1,122 @@ +#!/usr/bin/env bash + +set -euo pipefail + +ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +COMPOSE="${ROOT}/compose.yaml" +WORKFLOW="${ROOT}/.github/workflows/publish-static.yml" +EXAMPLE="${ROOT}/examples/github/publish-static.yml" +FAILED=0 + +fail() { + echo "[ERROR] $*" >&2 + FAILED=1 +} + +require_text() { + local file="$1" + local pattern="$2" + local label="$3" + if grep -Eq "$pattern" "$file"; then + echo "[OK] ${label}" + else + fail "${label}: expected /${pattern}/ in ${file}" + fi +} + +[ -f "$COMPOSE" ] || fail "missing compose.yaml" +[ -f "$WORKFLOW" ] || fail "missing publish-static.yml" +[ -f "$EXAMPLE" ] || fail "missing examples/github/publish-static.yml" + +require_text "$COMPOSE" '^name:[[:space:]]*gogp' "fixed Compose project name" +require_text "$COMPOSE" 'image:[[:space:]]*ghost:6' "official Ghost 6 image" +require_text "$COMPOSE" '\$\{GHOST_PORT:-2373\}:2368' "host port 2373 maps to 2368" +require_text "$COMPOSE" '/var/lib/ghost/content' "content volume mount" +require_text "$COMPOSE" 'database__client:[[:space:]]*sqlite3' "SQLite client" +require_text "$COMPOSE" 'database__connection__filename:[[:space:]]*/var/lib/ghost/content/data/ghost\.db' "SQLite file on the content mount" +require_text "$COMPOSE" 'NODE_ENV:[[:space:]]*development' "development mode" +require_text "$WORKFLOW" 'workflow_call:' "reusable workflow_call trigger" +require_text "$WORKFLOW" 'allow_empty:' "explicit empty-content opt-in" +require_text "$WORKFLOW" 'cancel-in-progress:[[:space:]]*false' "do not cancel an in-progress Pages deploy" +require_text "$WORKFLOW" 'actions/configure-pages@v5' "Pages configuration" +require_text "$WORKFLOW" 'actions/upload-pages-artifact@v3' "Pages artifact upload" +require_text "$WORKFLOW" 'actions/deploy-pages@v5' "Pages deploy" +require_text "$WORKFLOW" 'ghost-static-site-generator' "gssg in CI" +require_text "$WORKFLOW" 'Refusing to publish an empty Ghost site' "missing content fails the export" +require_text "$EXAMPLE" 'uses:[[:space:]]*paladini/ghost-on-github-pages/.github/workflows/publish-static.yml@master' "example calls reusable workflow" +require_text "${ROOT}/.github/workflows/ci.yml" '914e7df21a07ef503a81201c76d2b11c789d3fca' "actionlint installer is pinned" +require_text "${ROOT}/.github/workflows/ci.yml" '1\.7\.12' "actionlint version is pinned" +require_text "${ROOT}/scripts/compose-setup.sh" 'includes/lib/\.' "compose setup replaces lib contents" +require_text "${ROOT}/install.sh" 'includes/lib/\.' "install replaces lib contents" +require_text "${ROOT}/scripts/compose-smoke.sh" 'data/ghost\.db' "smoke test checks the SQLite file" + +if command -v docker >/dev/null 2>&1 && docker compose version >/dev/null 2>&1; then + if docker compose -f "$COMPOSE" config >/dev/null; then + echo "[OK] docker compose config" + else + fail "docker compose config failed" + fi +else + echo "[WARN] docker compose not available; skipped compose config" +fi + +TMP_ROOT="$(mktemp -d)" +cleanup_tmp() { + rm -rf "$TMP_ROOT" +} +trap cleanup_tmp EXIT + +export GHOST_INSTALL="${TMP_ROOT}/.ghost" +export HOME="${TMP_ROOT}/home" +mkdir -p "$HOME" +if ! bash "${ROOT}/scripts/compose-setup.sh" >/dev/null; then + fail "compose-setup.sh failed on the first run" +fi +if ! bash "${ROOT}/scripts/compose-setup.sh" >/dev/null; then + fail "compose-setup.sh failed on the second run" +fi +if [ -f "${GHOST_INSTALL}/lib/lib/common.sh" ]; then + fail "second compose-setup.sh nested lib/lib/common.sh" +elif [ ! -f "${GHOST_INSTALL}/lib/common.sh" ]; then + fail "compose-setup.sh did not install lib/common.sh" +else + echo "[OK] compose-setup.sh replaces lib on rerun" +fi + +run_uninstall() { + local docker_exit="$1" + local case_dir="${TMP_ROOT}/uninstall-${docker_exit}" + local bin="${case_dir}/bin" + mkdir -p "$bin" "${case_dir}/.ghost" + printf '%s\n' '#!/bin/sh' "exit ${docker_exit}" > "${bin}/docker" + chmod +x "${bin}/docker" + touch "${case_dir}/.ghost/.docker" "${case_dir}/.ghost/compose.yaml" + set +e + PATH="${bin}:${PATH}" GHOST_INSTALL="${case_dir}/.ghost" HOME="${case_dir}" \ + bash "${ROOT}/includes/uninstall.sh" >/tmp/gogp-uninstall.out 2>/tmp/gogp-uninstall.err <<< 'yes' + local status=$? + set -e + UNINSTALL_STATUS=$status + UNINSTALL_OUT="$(cat /tmp/gogp-uninstall.out /tmp/gogp-uninstall.err)" +} + +run_uninstall 1 +if [ "$UNINSTALL_STATUS" -eq 0 ] || ! grep -q "may still be running" <<<"$UNINSTALL_OUT"; then + fail "uninstall reported success when docker compose down failed" +else + echo "[OK] uninstall fails when Compose does not stop" +fi + +run_uninstall 0 +if [ "$UNINSTALL_STATUS" -ne 0 ] || ! grep -q "Docker Compose Ghost was stopped" <<<"$UNINSTALL_OUT"; then + fail "uninstall did not report a stopped stack after docker compose down succeeded" +else + echo "[OK] uninstall reports stopped only after Compose stops" +fi + +if [ "$FAILED" -ne 0 ]; then + echo "[ERROR] Compose / workflow tests failed." >&2 + exit 1 +fi + +echo "[OK] Compose and workflow fixture tests passed."