Skip to content

Commit 9ab4a39

Browse files
wyattwalterclaude
andauthored
chore(mongo): upgrade embedded MongoDB from 6.0 to 7.0 (#41743)
## Summary Upgrades the embedded MongoDB in the Appsmith Docker image from 6.0 (EOL July 2024) to 7.0. - **`base.dockerfile`** — switches apt repo, GPG key, and list file from the MongoDB `6.0` stream to `7.0`. Stays on the jammy (22.04) packages because MongoDB doesn't publish a noble (24.04) apt repo yet — same pattern the 6.0 install already used on Ubuntu 24.04. Local smoke build installs `mongodb-org 7.0.31` and `mongosh 2.8.2`. - **`mongodb-fixer.sh`** — writes a `.appsmith-mongo-fcv-min` marker file into the Mongo data directory once mongod is confirmed running under this release. Contents record the **minimum FCV this release commits to preserve** (constant `6.0`) — a release-level contract, not a live FCV reading. FCV is deliberately **not** raised to 7.0 — keeping it at 6.0 preserves the ability to downgrade back to a 6.x Appsmith release. Raise-FCV scaffolding and a marker-value bump can come back when MongoDB 8 needs it. - **`entrypoint.sh`** — adds `ensure_mongodb_fcv_compatible`, a pre-flight check that runs before supervisord starts mongod. MongoDB 7.0 refuses to start on data with FCV < 6.0; without this check, supervisord would retry mongod three times and give up, leaving the container in a confusing degraded state with no clear signal to the administrator. Reader only — never writes the marker. Only runs when there's existing local-Mongo data (gated on `shouldPerformInitdb=0 && isUriLocal=0` inside the function). ### Decision matrix | Data dir | Marker | Action | |---|---|---| | Fresh install | n/a | Skipped — nothing to check. Fixer writes the marker (constant `6.0`) on first real boot under supervisord. | | Has data | Present | Fast path — proceed, zero overhead. | | Has data | Missing | One-time `mongod --fork` probe. If it starts, proceed (fixer writes the marker on first boot under supervisord). If it fails, hard-fail with an actionable error pointing users to roll back to Appsmith v1.99 first. | Marker presence alone is what's trusted — the fixer writes it only after mongod is confirmed running under this release, so presence is proof this release successfully boots on this data. The value (`6.0`) is diagnostic: future Appsmith releases can inspect it to reason about upgrade safety. Linear: [APP-14867](https://linear.app/appsmith/issue/APP-14867/task-upgrade-mongo-base-image-in-appsmith-to-v7) ## Test plan - [x] **Fresh install**: empty `/appsmith-stacks` → entrypoint skips the FCV check (`shouldPerformInitdb=0` gate is false), `init_replica_set` initializes the data, supervisord starts mongod, fixer writes `.appsmith-mongo-fcv-min` with `6.0`. Second boot: marker present → fast path, skip probe. - [x] **Happy-path upgrade**: boot `appsmith-ce:v1.99` (last 6.x release), let the fixer run (FCV stays at 6.0), stop. Swap to this image and boot — entrypoint runs the probe (marker from prior image is missing), probe succeeds, fixer writes the marker. Subsequent boots are fast. - [x] **Failed + remediated upgrade**: boot `appsmith-ce:v1.69` (last mongo-5 release, pre-v1.70 cutover) to seed FCV 5.0 data. Swap to this image → expected **hard fail** with error block pointing to v1.99 rollback. Swap to `appsmith-ce:v1.99` → fixer raises FCV 5.0 → 6.0. Swap back to this image → probe succeeds, marker written. Verifies the error path *and* that the remediation instructions actually work end-to-end. - [x] **Marker-missing transitional path**: with the marker present, `rm /appsmith-stacks/data/mongodb/.appsmith-mongo-fcv-min`, reboot. Entrypoint should log `running one-time compatibility probe`, probe succeeds, fixer re-writes the marker. - [x] **Base image smoke build**: `docker build -f deploy/docker/base.dockerfile .` succeeds on linux/arm64. Image contains `mongodb-org 7.0.31` and `mongosh 2.8.2`. - [x] **CE→EE sync**: cherry-pick onto `community/release` and merge into EE `release` both apply cleanly (verified locally). - [x] **Fresh install** smoke-tested locally with the current DP image — probe skipped on `shouldPerformInitdb=0` gate, marker written by fixer after supervisord starts mongod. ## Out of scope - `deploy/helm/` chart still references Bitnami MongoDB 6.0.27 in `Chart.yaml` / `values.yaml`. That's tracked under a separate effort. 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Chores** * Upgraded bundled MongoDB from 6.0 to 7.0. * **New Features** * Added a startup compatibility probe that detects incompatible local/embedded MongoDB feature versions and halts startup with operator guidance when needed. * Added a persistent marker to record confirmed DB compatibility and skip repeated probes on subsequent startups. * Improved post-startup DB feature-version handling to record and persist the committed minimum FCV. <!-- end of auto-generated comment: release notes by coderabbit.ai --> <!-- This is an auto-generated comment: Cypress test results --> > [!WARNING] > Tests have not run on the HEAD af34f2d yet > <hr>Tue, 05 May 2026 22:44:32 UTC <!-- end of auto-generated comment: Cypress test results --> --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent c268bce commit 9ab4a39

3 files changed

Lines changed: 121 additions & 7 deletions

File tree

deploy/docker/base.dockerfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ RUN set -o xtrace \
2727
software-properties-common \
2828
git \
2929
&& add-apt-repository -y ppa:git-core/ppa \
30-
# Install MongoDB v6, PostgreSQL v14
31-
&& curl -fsSL https://www.mongodb.org/static/pgp/server-6.0.asc | gpg --dearmor -o /usr/share/keyrings/mongodb-server-6.0.gpg \
32-
&& echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-6.0.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/6.0 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-6.0.list \
30+
# Install MongoDB v7, PostgreSQL v14
31+
# Note: MongoDB 7.0 does not publish apt packages for Ubuntu 24.04 (noble) yet, so we use the jammy (22.04) packages — same pattern used for the previous 6.0 install.
32+
&& curl -fsSL https://www.mongodb.org/static/pgp/server-7.0.asc | gpg --dearmor -o /usr/share/keyrings/mongodb-server-7.0.gpg \
33+
&& echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/7.0 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-7.0.list \
3334
&& echo "deb http://apt.postgresql.org/pub/repos/apt $(grep CODENAME /etc/lsb-release | cut -d= -f2)-pgdg main" | tee /etc/apt/sources.list.d/pgdg.list \
3435
&& curl --silent --show-error --location https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
3536
&& apt update \

deploy/docker/fs/opt/appsmith/entrypoint.sh

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,80 @@ init_replica_set() {
334334
fi
335335
}
336336

337+
# Pre-flight check for embedded MongoDB 7.0 upgrades on existing data.
338+
#
339+
# MongoDB 7.0 refuses to start on data whose featureCompatibilityVersion (FCV)
340+
# is below 6.0. Without a check up front, supervisord would retry mongod a few
341+
# times and give up, leaving the container in a confusing degraded state with
342+
# no clear error for the administrator.
343+
#
344+
# Fast path: marker file ($MONGO_DB_PATH/.appsmith-mongo-fcv-min) is written by
345+
# mongodb-fixer.sh only after mongod is confirmed running under this Appsmith
346+
# release. Its presence proves this release has already booted successfully on
347+
# this data, so the probe can be skipped with zero overhead. Contents record
348+
# the FCV floor this release commits to, for future upgrade decisions; they
349+
# aren't consulted here.
350+
#
351+
# First boot after upgrade: no marker yet. Do a one-time mongod --fork probe
352+
# to verify the data is compatible. If it starts, proceed; the fixer will
353+
# write the marker after supervisord brings mongod up for real. If it fails,
354+
# print an actionable error and exit.
355+
ensure_mongodb_fcv_compatible() {
356+
# Only applies to existing local-Mongo data — fresh installs have nothing to
357+
# check, and external Mongo is out of our control.
358+
if [[ $shouldPerformInitdb -gt 0 || $isUriLocal -gt 0 ]]; then
359+
return
360+
fi
361+
362+
local marker="$MONGO_DB_PATH/.appsmith-mongo-fcv-min"
363+
if [[ -f "$marker" ]]; then
364+
tlog "MongoDB FCV marker present; skipping pre-flight check"
365+
return
366+
fi
367+
368+
tlog "No MongoDB FCV marker found on existing data; running one-time compatibility probe"
369+
# Persist the probe log inside the Mongo data directory so it survives container
370+
# restarts. $TMP would be wiped, leaving no forensic trail when an admin comes
371+
# back to investigate why their container exited. Append rather than truncate so
372+
# repeated probe runs (e.g. multiple failed upgrade attempts) all stay on record.
373+
local probe_log="$MONGO_DB_PATH/fcv-probe.log"
374+
printf '\n===== Appsmith MongoDB FCV pre-flight probe @ %s =====\n' "$(date -u +%Y-%m-%dT%H:%M:%SZ)" >> "$probe_log" 2>/dev/null || true
375+
if mongod --fork --port 27017 --dbpath "$MONGO_DB_PATH" --logpath "$probe_log" --logappend --bind_ip localhost >/dev/null 2>&1; then
376+
if ! mongod --dbpath "$MONGO_DB_PATH" --shutdown >/dev/null 2>&1; then
377+
tlog "ERROR: Pre-flight mongod probe started but shutdown failed. The probe mongod may still hold port 27017 or the data lock, which would prevent supervisord from starting mongod. Aborting. See $probe_log for details." >&2
378+
exit 1
379+
fi
380+
tlog "Pre-flight probe succeeded; mongodb-fixer will write the FCV marker after supervisord starts mongod"
381+
return
382+
fi
383+
384+
local probe_err
385+
probe_err="$(grep -Ei 'featurecompatibilityversion|upgrade|downgrade' "$probe_log" 2>/dev/null | tail -n 1 || true)"
386+
tlog "====================================================================================================" >&2
387+
tlog "==" >&2
388+
tlog "== ERROR: Embedded MongoDB 7.0 failed to start on the existing data. The most common cause is that the data is at featureCompatibilityVersion below the required 6.0 minimum." >&2
389+
if [[ -n "$probe_err" ]]; then
390+
tlog "== mongod log: $probe_err" >&2
391+
fi
392+
tlog "==" >&2
393+
tlog "== About this error:" >&2
394+
tlog "== Appsmith 2.x ships with MongoDB 7.x, which requires the database to be at featureCompatibilityVersion (FCV) 6.0 or higher. Appsmith releases 1.96 to 1.99 automatically raise FCV to 6.0 on boot, so any instance that has run one of those releases is fine. Instances that have only ever run Appsmith older than 1.70 may still be at FCV 5.0, which MongoDB 7.x refuses to load." >&2
395+
tlog "==" >&2
396+
tlog "== This check only runs for instances using the embedded MongoDB. Instances configured with an external MongoDB are not affected." >&2
397+
tlog "==" >&2
398+
tlog "== The failure happens during MongoDB pre-flight, before any Appsmith service comes online. No Appsmith database migrations have been attempted, so rolling back to a 1.x release is simply a matter of changing the image version on your deployment." >&2
399+
tlog "==" >&2
400+
tlog "== To recover:" >&2
401+
tlog "==" >&2
402+
tlog "== 1. Alter your Appsmith deployment to use a release in the 1.96 to 1.99 range (we recommend the latest, 1.99). These ship with MongoDB 6.x and will raise the compatibility version automatically." >&2
403+
tlog "== 2. Let the container start fully so the MongoDB FCV upgrade completes." >&2
404+
tlog "== 3. Shut down, then alter your Appsmith deployment to use this version again." >&2
405+
tlog "==" >&2
406+
tlog "== Full mongod log: $probe_log" >&2
407+
tlog "====================================================================================================" >&2
408+
exit 1
409+
}
410+
337411
use-mongodb-key() {
338412
# We copy the MongoDB key file to `$MONGODB_TMP_KEY_PATH`, so that we can reliably set its permissions to 600.
339413
# Why? When the host machine of this Docker container is Windows, file permissions cannot be set on files in volumes.
@@ -633,6 +707,7 @@ if [[ -z "${DYNO}" ]]; then
633707
tlog "Initializing MongoDB"
634708
init_mongodb
635709
init_replica_set
710+
ensure_mongodb_fcv_compatible
636711
fi
637712
else
638713
# These functions are used to limit heap size for Backend process when deployed on Heroku

deploy/docker/fs/opt/appsmith/mongodb-fixer.sh

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,67 @@
33
set -o errexit
44
set -o nounset
55

6+
# Marker file recording the minimum MongoDB featureCompatibilityVersion that
7+
# this Appsmith release commits to preserve. Written once mongod is confirmed
8+
# RUNNING under this release; read (presence only) by entrypoint.sh on
9+
# subsequent boots to fast-path the pre-flight compatibility check. See
10+
# entrypoint.sh::ensure_mongodb_fcv_compatible.
11+
#
12+
# The marker value is a release-level contract, not a live reading of mongod's
13+
# current FCV. Use `mongosh` if you want the live value.
14+
MONGO_FCV_MIN_MARKER="/appsmith-stacks/data/mongodb/.appsmith-mongo-fcv-min"
15+
16+
# Minimum FCV this Appsmith release commits to preserve. We deliberately do
17+
# NOT raise FCV to 7.0 — keeping it at 6.0 preserves the ability to roll back
18+
# to a 6.x Appsmith release if something goes wrong. When MongoDB 8 arrives,
19+
# bump this constant to 7.0; the ensure_fcv_floor block below will handle the
20+
# `setFeatureCompatibilityVersion` call automatically.
21+
FCV_MIN="6.0"
22+
23+
write_fcv_marker() {
24+
local value="$1"
25+
local tmp="${MONGO_FCV_MIN_MARKER}.tmp"
26+
if ! printf '%s\n' "$value" > "$tmp" 2>/dev/null; then
27+
tlog "warning: failed to write FCV marker temp file"
28+
return 0
29+
fi
30+
mv -f "$tmp" "$MONGO_FCV_MIN_MARKER" 2>/dev/null || tlog "warning: failed to move FCV marker into place"
31+
}
32+
633
{
734

835
while [[ ! -S "$TMP/supervisor.sock" ]]; do
936
sleep 1
1037
done
1138
tlog "supervisor.sock found"
1239

13-
while supervisorctl status mongodb | grep -q RUNNING; do
40+
while ! supervisorctl status mongodb | grep -q RUNNING; do
1441
sleep 1
1542
done
1643
tlog "MongoDB is RUNNING"
1744

45+
# Ensure FCV is at the floor this release commits to. In the steady state this
46+
# is a no-op — entrypoint.sh's pre-flight probe already guarantees mongod won't
47+
# come up on data below the supported FCV. The check is kept active so the
48+
# upgrade scaffolding is exercised and the next major-version bump is just a
49+
# constant change.
50+
tlog "Ensuring MongoDB featureCompatibilityVersion is at least $FCV_MIN"
1851
for _ in {1..60}; do
1952
if mongosh --quiet "$APPSMITH_DB_URL" --eval '
20-
parseFloat(db.adminCommand({getParameter: 1, featureCompatibilityVersion: 1}).featureCompatibilityVersion.version) < 6 &&
21-
db.adminCommand({setFeatureCompatibilityVersion: "6.0"})
53+
const floor = '"$FCV_MIN"';
54+
const current = parseFloat(db.adminCommand({getParameter: 1, featureCompatibilityVersion: 1}).featureCompatibilityVersion.version);
55+
if (current < floor) {
56+
db.adminCommand({setFeatureCompatibilityVersion: "'"$FCV_MIN"'", confirm: true});
57+
}
2258
'; then
23-
tlog "MongoDB version set to 6.0"
59+
tlog "MongoDB featureCompatibilityVersion floor of $FCV_MIN confirmed"
2460
break
2561
fi
2662
sleep 1
2763
done
2864

65+
tlog "Recording committed FCV minimum: $FCV_MIN"
66+
write_fcv_marker "$FCV_MIN"
2967
tlog Done
3068

3169
} | sed -u 's/^/mongodb-fixer: /'

0 commit comments

Comments
 (0)