fix: ensure lmdb correct binaries are available for lambdas #253
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When
gatsby build
is run, it generates a "query engine", a process that includes bundling the code but also relocating native binaries into an "assets" directory inside the build cache. The assets are identified using a webpack loader that has various heuristics to identify native binaries, because there is no standard for this in Node. The datastore used by Gatsby is lmdb-js, which uses node-gyp-build for loading the correct native binary at runtime. The loader handles moduels that use node-gyp-build by calling thispath()
method at build time, relocating the defined binaries, and replacing the import with this path. The problem is that this then identifies the binary for the build environment, not the runtime. In our default build environment these do not match, because the Node ABI versions differ, meaning that the wrong binary is included, and the wrong path written to the bundle.This PR handles these as a special case, and manually relocates the correct lmdb binary for linux-x86/abi83, which matches the default lambda runtime. It then patches the bundle to ensure the loader path matches. It handles two different cases for this: the existing
lmdb-store
package, and thelmdb
package that Gatsby will be migrating to soon.Because this kind of hard-coded workaround is fragile, this PR also ensures that deploy previews run with a node version that triggers this behaviour, and uses Gatsby's
next
version so problems are identified early.To test, check the build logs for the deploy preview to see that Node 16 is being used (i.e. not Node 14 as is used in Lambdas). Then check an SSR page in the deploy preview to ensure it renders.