Fix Next.js standalone Dockerfile cache permissions#16290
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 16290Or
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 16290" |
There was a problem hiding this comment.
Pull request overview
Updates Aspire’s generated Dockerfile for Next.js “standalone” publishes so the runtime image follows the official Next.js ownership pattern and allows the non-root node user to write to .next (notably .next/cache) at runtime.
Changes:
- Generate
COPY --chown=node:nodeforpublic,.next/standalone, and.next/staticin the Next.js standalone runtime stage. - Ensure
.nextexists and is owned bynode:nodebefore switching toUSER node. - Update Verify snapshots for both npm and pnpm Next.js standalone Dockerfile cases.
Show a summary per file
| File | Description |
|---|---|
| src/Aspire.Hosting.JavaScript/JavaScriptHostingExtensions.cs | Adjusts Next.js standalone runtime-stage Dockerfile generation to set correct ownership and create/chown .next before USER node. |
| tests/Aspire.Hosting.JavaScript.Tests/Snapshots/AddViteAppTests.VerifyDockerfileWhenPublishedAsNextStandalone.verified.txt | Updates expected generated Dockerfile snapshot for Next.js standalone (npm). |
| tests/Aspire.Hosting.JavaScript.Tests/Snapshots/AddViteAppTests.VerifyDockerfileWhenNextJsAppUsesPnpm.verified.txt | Updates expected generated Dockerfile snapshot for Next.js standalone (pnpm). |
Copilot's findings
- Files reviewed: 3/3 changed files
- Comments generated: 1
| .Run("mkdir .next") | ||
| .Run("chown node:node .next") |
There was a problem hiding this comment.
The runtime stage uses two separate RUN instructions (mkdir then chown), which adds an extra layer to the generated image. Consider combining these into a single RUN to keep the generated Dockerfile leaner and improve build/cache performance.
| .Run("mkdir .next") | |
| .Run("chown node:node .next") | |
| .Run("mkdir .next && chown node:node .next") |
There was a problem hiding this comment.
Agree BUT I rather keep it matching the recommended dockerfile for standalone mode as much as possible.
JamesNK
left a comment
There was a problem hiding this comment.
LGTM — the generated Dockerfile now correctly follows the official Next.js Docker example for file ownership, ensuring the non-root node user can write to .next/cache at runtime. Snapshots are consistent with the code change.
One minor note already raised in the existing review thread: the two separate RUN mkdir .next / RUN chown node:node .next could be combined into a single RUN mkdir .next && chown node:node .next to save a Docker layer.
|
🎬 CLI E2E Test Recordings — 72 recordings uploaded (commit View recordings
📹 Recordings uploaded automatically from CI run #24595139815 |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Description
Update the generated Dockerfile for Next.js standalone publish so the runtime image follows the ownership pattern from the official Next.js sample and allows the non-root
nodeuser to write to.nextat runtime.public,.next/standalone, and.next/staticwith--chown=node:node.nextin the runtime image and assign it tonode:nodebefore switching toUSER nodeValidation:
dotnet test tests/Aspire.Hosting.JavaScript.Tests/Aspire.Hosting.JavaScript.Tests.csproj -- --filter-not-trait "quarantined=true" --filter-not-trait "outerloop=true"aspire deployof a TypeScript AppHost with a real Next.js app, including:/api/helloroutenext/imageoptimization request returningX-Nextjs-Cache: MISSthenX-Nextjs-Cache: HITnodeuser can write files under/app/.next/cacheFixes #16277
Checklist
<remarks />and<code />elements on your triple slash comments?aspire.devissue: