Skip to content

fix: restore standalone image optimization with correct runtime ownership - #12

Merged
freehere107 merged 2 commits into
mainfrom
codex/fix-standalone-image-optimizer
Oct 23, 2026
Merged

freehere107 merged 2 commits into
mainfrom
codex/fix-standalone-image-optimizer

Conversation

@freehere107

@freehere107 freehere107 commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Image optimization fails in the deployed standalone image for two independent reasons:

  • sharp is absent from the application dependencies and runtime image; setting NEXT_SHARP_PATH does not install it.
  • A read-only production check showed the Pod runs as UID/GID 1000, overriding the old image's nextjs UID/GID 1001. /app/.next is owned by 1001:1001 with mode 0755, so UID 1000 cannot create the missing .next/cache directory.

Add sharp 0.35.5 and build the standalone output inside Node 24.22.1 Alpine, matching the runtime architecture/libc and native image libraries. Use the existing non-root node user (1000:1000), copy runtime files with matching ownership, and explicitly create the writable cache. No world-writable permissions or GitOps changes are required.

Add a real container regression that runs with --network none --user 1000:1000. It serves an existing local PNG through /_next/image, decodes the 64px WebP using the container's own sharp, verifies MISS→HIT, verifies cache-file ownership, restarts the container, and requires a persisted disk-cache HIT. The existing workflow loads and tests the complete image before its main-only publication step. Pull requests do not log into the registry, push images, or deploy.

Validation:

  • Node 24.22.1: npm ci --no-audit --no-fund, npm test -- --runInBand (4 suites / 32 tests), npm run build.
  • Standalone trace loads sharp 0.35.5 and libvips 8.18.7 on the host.
  • node --check scripts/test-standalone-image.mjs, actionlint, git diff --check, staged gitleaks scan.
  • Exact-head CI run 39803368483 passed at a55ad4f833f0a8d174fed18374d4e2a2e72a2ce1: complete Alpine image build plus real container image regression, Node 24.22.1, sharp 0.35.5/libvips 8.18.7, 64×15 WebP decoded to 3840 pixel bytes, cold MISS→HIT and persisted HIT after restart. Registry login and publication were skipped.
  • Local Docker VM had only 1.1 GiB free, so the complete Linux image was verified by GitHub CI. The loaded test image ID was sha256:f0b9b455217c16c924306f077d43a4283c2c8a7eb57f7d772415a740b9b4e89c.

No production writes, merge, or deployment were performed.

@freehere107
freehere107 merged commit 1a0e78f into main Oct 23, 2026
1 check passed
@freehere107
freehere107 deleted the codex/fix-standalone-image-optimizer branch October 23, 2026 01:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant