diff --git a/packages/gatsby/src/utils/cache-lmdb.ts b/packages/gatsby/src/utils/cache-lmdb.ts index addac1cbc40b6..55c7e8d0a9d74 100644 --- a/packages/gatsby/src/utils/cache-lmdb.ts +++ b/packages/gatsby/src/utils/cache-lmdb.ts @@ -13,7 +13,10 @@ const cacheDbFile = }` : `caches-lmdb` -const dbPath = path.join(process.cwd(), `.cache/${cacheDbFile}`) +const dbPath = path.join( + global.__GATSBY?.root || process.cwd(), + `.cache/${cacheDbFile}` +) function getAlreadyOpenedStore(): RootDatabase | undefined { if (!globalThis.__GATSBY_OPEN_ROOT_LMDBS) { diff --git a/packages/gatsby/src/utils/page-ssr-module/lambda.ts b/packages/gatsby/src/utils/page-ssr-module/lambda.ts index c40c4416d3605..fb4c4f0b61944 100644 --- a/packages/gatsby/src/utils/page-ssr-module/lambda.ts +++ b/packages/gatsby/src/utils/page-ssr-module/lambda.ts @@ -23,7 +23,13 @@ function setupFsWrapper(): string { } catch (e) { // we are in a read-only filesystem, so we need to use a temp dir - const TEMP_CACHE_DIR = path.join(tmpdir(), `gatsby`, `.cache`) + const TEMP_DIR = path.join(tmpdir(), `gatsby`) + const TEMP_CACHE_DIR = path.join(TEMP_DIR, `.cache`) + + global.__GATSBY = { + root: TEMP_DIR, + buildId: ``, + } // TODO: don't hardcode this const cacheDir = `/var/task/.cache` @@ -148,8 +154,8 @@ async function getEngine(): Promise { reject(error) }) }) + console.log(`Downloaded datastore from CDN`) } - console.log(`Downloaded datastore from CDN`) const graphqlEngine = new GraphQLEngine({ dbPath,