Skip to content

Commit 0174481

Browse files
committed
fix(lambda): isolate Docker build to prevent host node_modules corruption
The inner build script was running pnpm install directly on the bind-mounted host workspace, overwriting macOS/Windows node_modules with Linux-specific Prisma binaries. Now rsync sources to /build inside the container and only copy the final zip back to the host.
1 parent 1c730c8 commit 0174481

1 file changed

Lines changed: 25 additions & 11 deletions

File tree

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,43 @@
11
#!/usr/bin/env bash
22
# Run inside Docker (linux/amd64) — invoked by build-read-model-updater-lambda.sh
3+
#
4+
# /workspace is a bind-mount of the host repo. To avoid overwriting host
5+
# node_modules with Linux-specific binaries, we copy the source tree to
6+
# /build and perform all work there. Only the final zip is written back
7+
# to /workspace/dist/.
38
set -euo pipefail
49

5-
cd /workspace
6-
710
export CI=true
811

912
export DEBIAN_FRONTEND=noninteractive
1013
apt-get update -qq
11-
apt-get install -y -qq zip
14+
apt-get install -y -qq zip rsync
1215

1316
corepack enable && corepack prepare pnpm@9.15.9 --activate
1417

18+
# --- Copy source to isolated build directory ---
19+
BUILD=/build
20+
rm -rf "${BUILD}"
21+
rsync -a --exclude node_modules --exclude .turbo --exclude dist /workspace/ "${BUILD}/"
22+
cd "${BUILD}"
23+
1524
pnpm install --frozen-lockfile
1625
pnpm prisma:generate
1726
pnpm exec turbo build --filter=cqrs-es-example-js-rmu --filter=cqrs-es-example-js-bootstrap
1827

19-
STAGE="/workspace/dist/lambda/read-model-updater/stage"
20-
ZIP="/workspace/dist/lambda/read-model-updater/function.zip"
21-
rm -rf "${STAGE}" "${ZIP}"
28+
STAGE="${BUILD}/dist/lambda/read-model-updater/stage"
29+
ZIP_TMP="${BUILD}/dist/lambda/read-model-updater/function.zip"
30+
rm -rf "${STAGE}" "${ZIP_TMP}"
2231
mkdir -p "${STAGE}/node_modules"
2332

24-
pnpm dlx esbuild@0.25.0 /workspace/packages/bootstrap/src/lambda-rmu-handler.ts \
33+
pnpm dlx esbuild@0.25.0 "${BUILD}/packages/bootstrap/src/lambda-rmu-handler.ts" \
2534
--bundle \
2635
--platform=node \
2736
--target=node18 \
2837
--outfile="${STAGE}/index.js" \
2938
--external:@prisma/client
3039

31-
NM="$(node -p "const p=require('path');const x=require.resolve('@prisma/client/package.json',{paths:['/workspace/packages/bootstrap']});p.join(p.dirname(x),'..','..')")"
40+
NM="$(node -p "const p=require('path');const x=require.resolve('@prisma/client/package.json',{paths:['${BUILD}/packages/bootstrap']});p.join(p.dirname(x),'..','..')")"
3241
cp -r "${NM}/@prisma" "${STAGE}/node_modules/"
3342
cp -r "${NM}/.prisma" "${STAGE}/node_modules/"
3443

@@ -39,7 +48,12 @@ find "${STAGE}/node_modules" -name "introspection-engine-*" -delete 2>/dev/null
3948
find "${STAGE}/node_modules" -name "migration-engine-*" -delete 2>/dev/null || true
4049

4150
cd "${STAGE}"
42-
zip -q -r "${ZIP}" .
51+
zip -q -r "${ZIP_TMP}" .
52+
53+
# --- Write only the final artifact back to the host mount ---
54+
OUT_DIR="/workspace/dist/lambda/read-model-updater"
55+
mkdir -p "${OUT_DIR}"
56+
cp "${ZIP_TMP}" "${OUT_DIR}/function.zip"
4357

44-
echo "Wrote ${ZIP}"
45-
ls -la "${ZIP}"
58+
echo "Wrote ${OUT_DIR}/function.zip"
59+
ls -la "${OUT_DIR}/function.zip"

0 commit comments

Comments
 (0)