Unverified Commit d054fe4a authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

Persist storage cache in Docker environments (#100790)

### What?

Next.js now persists its server-side storage cache in Docker
environments, the same as other environments. This covers the RSC /
Server Actions encryption key, preview-mode keys, and the development
Chrome DevTools workspace identifier.

### Why?

The shared storage-directory helper previously disabled `.next/cache`
persistence whenever Docker was detected. As a result, Docker
environments could not reuse cached RSC encryption secrets across
separate key-generation processes.

### How?

The shared helper now always resolves the cache directory beneath the
configured dist directory. Because storage is always available, each
consumer drops the now-unreachable fallback path and uses the existing
cache read/write flow directly. Existing key validation, expiry-based
rotation during builds, and `NEXT_SERVER_ACTIONS_ENCRYPTION_KEY`
precedence are unchanged.

Telemetry is intentionally unchanged: it has its own storage-location
logic for CI and Docker, which already stores telemetry configuration in
`.next/cache` there.

### Verification

- Ran a focused probe against the updated source with Docker detection
mocked. It confirmed RSC encryption-key cache write and reuse,
expired-key handling for runtime and builds, explicit encryption-key
precedence, and preview-key cache write and reuse.
- `pnpm --filter=next types`
- Not run: full Next.js integration tests.

<!-- NEXT_JS_LLM -->


<!-- fleet 3a3e1bf2-4e32-499c-8f71-ae9dd2d64f16 -->
Co-authored-by: 's avatarvercel-fleet-prod[bot] <318278635+vercel-fleet-prod[bot]@users.noreply.github.com>
Co-authored-by: 's avatarTobias Koppers <1365881+sokra@users.noreply.github.com>
parent b0b2e89e
...@@ -13,8 +13,6 @@ const EXPIRATION = 1000 * 60 * 60 * 24 * 14 // 14 days ...@@ -13,8 +13,6 @@ const EXPIRATION = 1000 * 60 * 60 * 24 * 14 // 14 days
async function writeCache(distDir: string, config: __ApiPreviewProps) { async function writeCache(distDir: string, config: __ApiPreviewProps) {
const cacheBaseDir = getStorageDirectory(distDir) const cacheBaseDir = getStorageDirectory(distDir)
if (!cacheBaseDir) return
const configPath = path.join(cacheBaseDir, CONFIG_FILE) const configPath = path.join(cacheBaseDir, CONFIG_FILE)
if (!fs.existsSync(cacheBaseDir)) { if (!fs.existsSync(cacheBaseDir)) {
await fs.promises.mkdir(cacheBaseDir, { recursive: true }) await fs.promises.mkdir(cacheBaseDir, { recursive: true })
...@@ -51,13 +49,6 @@ export async function generatePreviewKeys({ ...@@ -51,13 +49,6 @@ export async function generatePreviewKeys({
isBuild: boolean isBuild: boolean
}): Promise<__ApiPreviewProps> { }): Promise<__ApiPreviewProps> {
const cacheBaseDir = getStorageDirectory(distDir) const cacheBaseDir = getStorageDirectory(distDir)
if (!cacheBaseDir) {
// There's no persistent storage available. We generate a new config.
// This also covers development time.
return generateConfig()
}
const configPath = path.join(cacheBaseDir, CONFIG_FILE) const configPath = path.join(cacheBaseDir, CONFIG_FILE)
async function tryReadCachedConfig(): Promise<false | __ApiPreviewProps> { async function tryReadCachedConfig(): Promise<false | __ApiPreviewProps> {
if (!fs.existsSync(configPath)) return false if (!fs.existsSync(configPath)) return false
......
...@@ -15,8 +15,6 @@ const EXPIRATION = 1000 * 60 * 60 * 24 * 14 // 14 days ...@@ -15,8 +15,6 @@ const EXPIRATION = 1000 * 60 * 60 * 24 * 14 // 14 days
async function writeCache(distDir: string, configValue: string) { async function writeCache(distDir: string, configValue: string) {
const cacheBaseDir = getStorageDirectory(distDir) const cacheBaseDir = getStorageDirectory(distDir)
if (!cacheBaseDir) return
const configPath = path.join(cacheBaseDir, CONFIG_FILE) const configPath = path.join(cacheBaseDir, CONFIG_FILE)
if (!fs.existsSync(cacheBaseDir)) { if (!fs.existsSync(cacheBaseDir)) {
await fs.promises.mkdir(cacheBaseDir, { recursive: true }) await fs.promises.mkdir(cacheBaseDir, { recursive: true })
...@@ -42,13 +40,6 @@ async function loadOrGenerateKey( ...@@ -42,13 +40,6 @@ async function loadOrGenerateKey(
generateKey: () => Promise<string> generateKey: () => Promise<string>
): Promise<string> { ): Promise<string> {
const cacheBaseDir = getStorageDirectory(distDir) const cacheBaseDir = getStorageDirectory(distDir)
if (!cacheBaseDir) {
// There's no persistent storage available. We generate a new key.
// This also covers development time.
return await generateKey()
}
const configPath = path.join(cacheBaseDir, CONFIG_FILE) const configPath = path.join(cacheBaseDir, CONFIG_FILE)
async function hasCachedKey(): Promise<false | string> { async function hasCachedKey(): Promise<false | string> {
if (!fs.existsSync(configPath)) return false if (!fs.existsSync(configPath)) return false
......
import path from 'path' import path from 'path'
import isDockerFunction from 'next/dist/compiled/is-docker'
export function getStorageDirectory(distDir: string): string | undefined { export function getStorageDirectory(distDir: string): string {
const isLikelyEphemeral = isDockerFunction()
if (isLikelyEphemeral) {
return undefined
}
return path.join(distDir, 'cache') return path.join(distDir, 'cache')
} }
...@@ -51,9 +51,6 @@ async function getChromeDevtoolsWorkspace( ...@@ -51,9 +51,6 @@ async function getChromeDevtoolsWorkspace(
const distDir = path.join(root, configDistDir) const distDir = path.join(root, configDistDir)
const cacheBaseDir = getStorageDirectory(distDir) const cacheBaseDir = getStorageDirectory(distDir)
if (cacheBaseDir === undefined) {
workspaceUUID = randomUUID()
} else {
const cachedUUIDPath = path.join( const cachedUUIDPath = path.join(
cacheBaseDir, cacheBaseDir,
'chrome-devtools-workspace-uuid' 'chrome-devtools-workspace-uuid'
...@@ -78,7 +75,6 @@ async function getChromeDevtoolsWorkspace( ...@@ -78,7 +75,6 @@ async function getChromeDevtoolsWorkspace(
} }
} }
} }
}
return { return {
workspace: { workspace: {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment