Visitar URL original
Fix better-sqlite3 architecture in Docker images by lirlia · Pull Request #1541 · dbgate/dbgate · GitHub
Skip to content

Fix better-sqlite3 architecture in Docker images - #1541

Open
lirlia wants to merge 1 commit into
dbgate:masterfrom
lirlia:agent/rebuild-better-sqlite3-per-architecture
Open

lirlia wants to merge 1 commit into
dbgate:masterfrom
lirlia:agent/rebuild-better-sqlite3-per-architecture

Conversation

@lirlia

@lirlia lirlia commented Aug 19, 2026 •

Copy link
Copy Markdown

Summary

  • Rebuild better-sqlite3 in a target-platform build stage for both the Debian and Alpine images.
  • Copy the rebuilt application into the final runtime stage, keeping compiler toolchains out of the final images.
  • Open an in-memory SQLite database during each platform build, so a wrong-architecture native addon fails the existing multi-arch build immediately.

Related to #653.

Root cause

.github/workflows/build-docker.yaml runs yarn prepare:docker on the x86_64 GitHub Actions runner before Docker Buildx starts. prepare:docker calls install:drivers:docker, which installs better-sqlite3 and creates:

docker/node_modules/better-sqlite3/build/Release/better_sqlite3.node

for x86_64.

Buildx subsequently builds linux/amd64, linux/arm64, and linux/arm/v7, but the Dockerfiles only copy that already-prepared directory. A COPY does not rebuild native addons, so the ARM images receive the x86-64 ELF.

Reproduction

On an ARM64 host:

docker pull --platform linux/arm64 dbgate/dbgate:7.2.5

docker run --rm \
  --platform linux/arm64 \
  --entrypoint node \
  dbgate/dbgate:7.2.5 \
  -e "const Database = require('better-sqlite3'); const db = new Database(':memory:'); db.close()"

This fails with ERR_DLOPEN_FAILED because the native addon has the wrong architecture.

The addon can also be inspected from the image:

docker create \
  --platform linux/arm64 \
  --name dbgate-arm64-inspect \
  dbgate/dbgate:7.2.5

docker cp \
  dbgate-arm64-inspect:/home/dbgate-docker/node_modules/better-sqlite3/build/Release/better_sqlite3.node \
  ./better_sqlite3.node

docker rm dbgate-arm64-inspect
file ./better_sqlite3.node

Before this change, file reports an x86-64 ELF even though the image platform is ARM64.

@lirlia
lirlia marked this pull request as ready for review August 19, 2026 07:32

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant