Skip to content

Commit bb4fac5

Browse files
committed
fix(docker): force better-sqlite3 to compile from source under QEMU
both prebuild-install and node-gyp rebuild were failing silently under QEMU arm64 emulation on GitHub Actions amd64 runners. prebuild-install first attempts to download a prebuilt binary from GitHub releases; under QEMU + CI this either times out, returns an incompatible binary, or the exact node-v115-linux-arm64 prebuilt simply does not exist for better-sqlite3@9.6.0. The fallback 'node-gyp rebuild' then also failed silently. Fix: set npm_config_build_from_source=true on the pnpm install call so prebuild-install skips the download entirely and goes straight to node-gyp compilation. python3/make/g++ are already in the image so this always succeeds. Also add a verification RUN that fails the image build immediately if better_sqlite3.node is still missing after install, giving an early actionable error instead of a runtime crash.
1 parent d267264 commit bb4fac5

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

apps/cas/backend/Dockerfile

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,16 @@ RUN apt-get update -qq && apt-get install -y --no-install-recommends \
3434
RUN npm install -g pnpm@10.11.0
3535

3636
# Install from pruned manifests.
37-
# better-sqlite3 is in onlyBuiltDependencies (pnpm-workspace.yaml) so pnpm
38-
# runs its install script, which downloads the prebuilt arm64 binary directly.
37+
# npm_config_build_from_source skips the prebuild-install download entirely
38+
# and goes straight to node-gyp compilation — necessary because under QEMU
39+
# the prebuild-install download either fails or downloads an incompatible binary.
3940
COPY --from=pruner /app/out/json/ .
4041
COPY --from=pruner /app/out/pnpm-lock.yaml ./pnpm-lock.yaml
41-
RUN pnpm install --frozen-lockfile
42+
RUN npm_config_build_from_source=true pnpm install --frozen-lockfile
43+
44+
# Verify the binary was actually compiled (fail loudly during build if not)
45+
RUN find /app/node_modules/.pnpm -name 'better_sqlite3.node' | grep . || \
46+
(echo 'ERROR: better_sqlite3.node was not compiled!' && exit 1)
4247

4348
# Copy source for all packages in the pruned subset and build in dep order.
4449
# turbo respects "dependsOn": ["^build"] so executor and its deps build first.

apps/template/backend/Dockerfile

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,14 @@ COPY apps/template/backend/package.json ./apps/template/backend/package.json
4848
COPY apps/template/frontend/package.json ./apps/template/frontend/package.json
4949

5050
# Install deps for the template backend only.
51-
# better-sqlite3 is in onlyBuiltDependencies (pnpm-workspace.yaml) so pnpm
52-
# downloads its prebuilt arm64 binary — no QEMU compilation needed.
53-
RUN pnpm install --frozen-lockfile --filter @cfxdevkit/template-backend
51+
# npm_config_build_from_source skips the prebuild-install download entirely
52+
# and goes straight to node-gyp compilation — necessary because under QEMU
53+
# the prebuild-install download either fails or downloads an incompatible binary.
54+
RUN npm_config_build_from_source=true pnpm install --frozen-lockfile --filter @cfxdevkit/template-backend
55+
56+
# Verify the binary was actually compiled (fail loudly during build if not)
57+
RUN find /app/node_modules/.pnpm -name 'better_sqlite3.node' | grep . || \
58+
(echo 'ERROR: better_sqlite3.node was not compiled!' && exit 1)
5459

5560
COPY apps/template/backend/ ./apps/template/backend/
5661
RUN pnpm --filter @cfxdevkit/template-backend build

0 commit comments

Comments
 (0)