Improve Dockerfile security, layering, and dev/prod parity#6882
Improve Dockerfile security, layering, and dev/prod parity#6882
Conversation
- Run app as non-root user (addgroup/adduser + USER app) - Remove vim from production image - Fix ARG ROOT: remove no-op global declaration, add default per-stage - Copy package*.json before COPY . . to improve npm layer caching - Replace fragile npm symlink with direct COPY from node-source - Add apk cache cleanup to build stage - Align devcontainer Ruby version with production (3.3 → 4.0) Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
COPY resolves the file to /usr/local/bin/npm, so Node sets __dirname
to /usr/local/bin/ and require('../lib/cli.js') in npm-cli.js points
to /usr/local/lib/cli.js (missing). A symlink keeps the real file at
/usr/local/lib/node_modules/npm/bin/npm-cli.js so __dirname resolves
correctly and the relative require works.
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
|
bots says: The failing job From the logs, the failure happens at the end of the job and doesn’t point to a specific spec failure; it’s consistent with the container being killed rather than tests failing. Fix: reduce memory pressure in CI (recommended)1) Don’t run
|
Summary
appuser instead of rootvimfrom production image (attack surface reduction)ARG ROOT: remove the no-op global declaration; each stage now carries its own default valuepackage*.jsonis copied andnpm ciruns beforeCOPY . ., so source changes don't bust the npm install layerln -sinto node_modules internals withCOPY --from=node-source /usr/local/bin/npmbuildstage (was missing, present in final stage)ruby:dev-3.3-bookworm→ruby:dev-4.0-bookwormto match productionTest plan
docker build .completes without errorsdocker runstarts Rails server and responds on port 3000whoamiinside container returnsapp(notroot)🤖 Generated with Claude Code