Skip to content

Commit 0682f42

Browse files
committed
feat: report Flarum version drift between the image and the volume
An image only ever seeds an empty volume, so an existing forum keeps the flarum/core it was installed with and a pull can never move it. Nothing said so, which left the tag describing a Flarum the operator was not running (issue #7). Read the installed version from the volume's composer.lock on boot and compare it with the baked FLARUM_SKELETON_VERSION. Log a match, warn loudly on a difference with the deliberate-upgrade commands, and write installed/image/drift to storage/.flarum_version for scripting. Reports only. Adopting the skeleton on update stays deliberately out: the skeleton carries its own composer.json/lock, so copying it over a live volume would delete every extension installed through the Extension Manager while leaving their rows and migrations behind. The check runs before the hard-require block so the number reflects what the volume booted with, not what this same boot goes on to install.
1 parent 1d8709f commit 0682f42

2 files changed

Lines changed: 83 additions & 0 deletions

File tree

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,40 @@ docker compose logs -f flarum
7373
When it's ready, visit `APP_URL` and log in with the `ADMIN_USER` /
7474
`ADMIN_PASS` you set in `.env`.
7575

76+
## Updating the image
77+
78+
**Pulling a new image does not upgrade an existing forum, by design.** The image
79+
tag describes what a **fresh install** gets, not what an already-installed volume
80+
runs. The baked Flarum only ever seeds an empty volume, so `docker compose pull`
81+
on a live site gives you new nginx/PHP/entrypoint and the **same** Flarum.
82+
83+
That keeps a routine pull from becoming a database-migrating operation on a
84+
running forum. It does mean the tag and the forum can differ, so every boot logs
85+
which is which:
86+
87+
```
88+
[!] WARNING: VERSION DRIFT: this forum runs Flarum 2.0.0-rc.5, this image ships 2.0.0-rc.6.
89+
```
90+
91+
The same three facts are written to `storage/.flarum_version` inside the
92+
container, for scripting or a status check:
93+
94+
```bash
95+
docker compose exec flarum cat storage/.flarum_version
96+
# installed=2.0.0-rc.5
97+
# image=2.0.0-rc.6
98+
# drift=true
99+
```
100+
101+
Upgrading Flarum stays a deliberate act. Back up first, then either use the
102+
**Extension Manager** in admin, or:
103+
104+
```bash
105+
docker compose exec flarum backup.sh
106+
docker compose exec -u www-data flarum composer update flarum/core --with-all-dependencies
107+
docker compose restart flarum # runs migrations on the way back up
108+
```
109+
76110
## TLS / reverse proxy
77111

78112
This stack publishes plain HTTP on port **80** (and the realtime websocket on

entrypoint.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,55 @@ if [ "$DO_RESTORE" = "true" ] && [ -n "$RESTORE_FILES" ] && [ -f "$RESTORE_FILES
289289
chown -R www-data:www-data "$WORKDIR/storage" "$WORKDIR/public/assets" 2>/dev/null || true
290290
fi
291291

292+
# ── Version drift: what this image ships vs what this volume actually runs ────
293+
# The baked skeleton only ever seeds an EMPTY volume (see the install branch
294+
# above), so an existing forum keeps whatever flarum/core it was installed with,
295+
# including a version an admin later upgraded to through the Extension Manager,
296+
# which this image never hears about. Pulling a new image tag therefore does not
297+
# move a live forum — deliberately, see issue #7 — and until now nothing said so,
298+
# which left the tag describing a Flarum the operator was not running.
299+
#
300+
# This reports, and never acts. Upgrading stays a deliberate act.
301+
#
302+
# Read before the hard-require block below, so the number reflects what the
303+
# volume booted with rather than anything this same boot goes on to install.
304+
installed_core_version() {
305+
php -r '
306+
$f = $argv[1];
307+
if (! is_readable($f)) exit(1);
308+
$lock = json_decode(file_get_contents($f), true);
309+
foreach (($lock["packages"] ?? []) as $p) {
310+
if (($p["name"] ?? "") === "flarum/core") { echo ltrim($p["version"], "v"); exit; }
311+
}
312+
exit(1);
313+
' "$1" 2>/dev/null
314+
}
315+
316+
VERSION_STATUS_FILE="$WORKDIR/storage/.flarum_version"
317+
INSTALLED_CORE=$(installed_core_version "$WORKDIR/composer.lock") || INSTALLED_CORE=""
318+
[ -n "$INSTALLED_CORE" ] || INSTALLED_CORE="unknown"
319+
320+
if [ "$INSTALLED_CORE" = "unknown" ] || [ "$FLARUM_SKELETON_VERSION" = "unknown" ]; then
321+
VERSION_DRIFT="unknown"
322+
log "Flarum core: running '${INSTALLED_CORE}', image ships '${FLARUM_SKELETON_VERSION}' (not comparable)."
323+
elif [ "$INSTALLED_CORE" = "$FLARUM_SKELETON_VERSION" ]; then
324+
VERSION_DRIFT="false"
325+
log "Flarum core ${INSTALLED_CORE} matches the version baked into this image."
326+
else
327+
VERSION_DRIFT="true"
328+
warn "VERSION DRIFT: this forum runs Flarum ${INSTALLED_CORE}, this image ships ${FLARUM_SKELETON_VERSION}."
329+
warn " Pulling an image never upgrades an existing forum. The tag describes what a FRESH install"
330+
warn " would get, not what is running here. Nothing is broken; they are simply not the same."
331+
warn " To upgrade deliberately, back up first, then update through composer:"
332+
warn " docker compose exec flarum backup.sh"
333+
warn " docker compose exec -u www-data flarum composer update flarum/core --with-all-dependencies"
334+
warn " (or use the Extension Manager in admin). Background: linkrobins/flarum-docker#7"
335+
fi
336+
337+
printf 'installed=%s\nimage=%s\ndrift=%s\n' \
338+
"$INSTALLED_CORE" "$FLARUM_SKELETON_VERSION" "$VERSION_DRIFT" > "$VERSION_STATUS_FILE" 2>/dev/null || true
339+
chown www-data:www-data "$VERSION_STATUS_FILE" 2>/dev/null || true
340+
292341
# ── Required extensions (hard-require — fail the boot on a composer error) ─────
293342
composer_require() {
294343
local pkg="$1"

0 commit comments

Comments
 (0)