diff --git a/Dockerfile.bun b/Dockerfile.bun index 323296ea189..5214e42a6a7 100644 --- a/Dockerfile.bun +++ b/Dockerfile.bun @@ -84,8 +84,19 @@ ENV DATA_DIR=/app/data RUN mkdir -p /app/data COPY --from=builder /app/.build/next/standalone ./ + +ENV OMNIROUTE_MIGRATIONS_DIR=/app/migrations + COPY --from=builder /app/scripts/dev/healthcheck.mjs ./healthcheck.mjs +# Bun uses bun:sqlite. Remove every standalone/vendor copy of the Node-only +# addon so no traced chunk can dlopen it and abort the process before fallback. +RUN find /app \ + -path '*/node_modules/better-sqlite3' \ + -prune \ + -exec rm -rf '{}' + \ + && test -z "$(find /app -type f -name 'better_sqlite3.node' -print -quit)" + RUN chown -R bun:bun /app /app/data USER bun diff --git a/changelog.d/fixes/11482-bun-runtime-native-addon.md b/changelog.d/fixes/11482-bun-runtime-native-addon.md new file mode 100644 index 00000000000..e0a44b8a295 --- /dev/null +++ b/changelog.d/fixes/11482-bun-runtime-native-addon.md @@ -0,0 +1 @@ +- **fix(docker-bun):** remove every vendored `better-sqlite3` native addon from the Bun runtime image so startup cannot abort before the `bun:sqlite` fallback ([#11482](https://github.com/diegosouzapw/OmniRoute/pull/11482)) — thanks @TheDemonTuan diff --git a/tests/unit/build/bun-runtime-native-addon.test.mjs b/tests/unit/build/bun-runtime-native-addon.test.mjs new file mode 100644 index 00000000000..1934bbcc4b7 --- /dev/null +++ b/tests/unit/build/bun-runtime-native-addon.test.mjs @@ -0,0 +1,20 @@ +import assert from "node:assert/strict"; +import { readFileSync } from "node:fs"; +import test from "node:test"; + +const dockerfile = readFileSync(new URL("../../../Dockerfile.bun", import.meta.url), "utf8"); + +test("Bun runner excludes every better-sqlite3 native addon", () => { + assert.doesNotMatch( + dockerfile, + /COPY --from=builder \/app\/node_modules\/better-sqlite3/ + ); + assert.match( + dockerfile, + /find \/app[\s\S]*-path '\*\/node_modules\/better-sqlite3'[\s\S]*-prune[\s\S]*-exec rm -rf '\{\}' \+/ + ); + assert.match( + dockerfile, + /test -z "\$\(find \/app -type f -name 'better_sqlite3\.node' -print -quit\)"/ + ); +});