Skip to content

Commit

Permalink
fix(gatsby): open lmdb instances in writeable locations in generated …
Browse files Browse the repository at this point in the history
…ssr/dsg function (#38631)

(cherry picked from commit 3af35ae)
  • Loading branch information
pieh committed Oct 16, 2023
1 parent 1e8748c commit 059d703
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 4 additions & 1 deletion packages/gatsby/src/utils/cache-lmdb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 8 additions & 2 deletions packages/gatsby/src/utils/page-ssr-module/lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -148,8 +154,8 @@ async function getEngine(): Promise<GraphQLEngineType> {
reject(error)
})
})
console.log(`Downloaded datastore from CDN`)
}
console.log(`Downloaded datastore from CDN`)

const graphqlEngine = new GraphQLEngine({
dbPath,
Expand Down

0 comments on commit 059d703

Please sign in to comment.