Skip to content

Commit 3af35ae

Browse files
authored
fix(gatsby): open lmdb instances in writeable locations in generated ssr/dsg function (#38631)
1 parent 47ec2ac commit 3af35ae

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

packages/gatsby/src/utils/cache-lmdb.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ const cacheDbFile =
1313
}`
1414
: `caches-lmdb`
1515

16-
const dbPath = path.join(process.cwd(), `.cache/${cacheDbFile}`)
16+
const dbPath = path.join(
17+
global.__GATSBY?.root || process.cwd(),
18+
`.cache/${cacheDbFile}`
19+
)
1720

1821
function getAlreadyOpenedStore(): RootDatabase | undefined {
1922
if (!globalThis.__GATSBY_OPEN_ROOT_LMDBS) {

packages/gatsby/src/utils/page-ssr-module/lambda.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,13 @@ function setupFsWrapper(): string {
2323
} catch (e) {
2424
// we are in a read-only filesystem, so we need to use a temp dir
2525

26-
const TEMP_CACHE_DIR = path.join(tmpdir(), `gatsby`, `.cache`)
26+
const TEMP_DIR = path.join(tmpdir(), `gatsby`)
27+
const TEMP_CACHE_DIR = path.join(TEMP_DIR, `.cache`)
28+
29+
global.__GATSBY = {
30+
root: TEMP_DIR,
31+
buildId: ``,
32+
}
2733

2834
// TODO: don't hardcode this
2935
const cacheDir = `/var/task/.cache`
@@ -148,8 +154,8 @@ async function getEngine(): Promise<GraphQLEngineType> {
148154
reject(error)
149155
})
150156
})
157+
console.log(`Downloaded datastore from CDN`)
151158
}
152-
console.log(`Downloaded datastore from CDN`)
153159

154160
const graphqlEngine = new GraphQLEngine({
155161
dbPath,

0 commit comments

Comments
 (0)