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/.
38set -euo pipefail
49
5- cd /workspace
6-
710export CI=true
811
912export DEBIAN_FRONTEND=noninteractive
1013apt-get update -qq
11- apt-get install -y -qq zip
14+ apt-get install -y -qq zip rsync
1215
1316corepack 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+
1524pnpm install --frozen-lockfile
1625pnpm prisma:generate
1726pnpm 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 } "
2231mkdir -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),'..','..')" ) "
3241cp -r " ${NM} /@prisma" " ${STAGE} /node_modules/"
3342cp -r " ${NM} /.prisma" " ${STAGE} /node_modules/"
3443
@@ -39,7 +48,12 @@ find "${STAGE}/node_modules" -name "introspection-engine-*" -delete 2>/dev/null
3948find " ${STAGE} /node_modules" -name " migration-engine-*" -delete 2> /dev/null || true
4049
4150cd " ${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