feat: Enhance Dockerfile for security and production readiness#76
feat: Enhance Dockerfile for security and production readiness#76abiteman merged 3 commits intoDumbWareio:mainfrom
Conversation
Set `NODE_ENV` to `production` explicitly for optimized builds and runtime behavior. Switch to running as a non-root user (`1000`) for improved container security. Adjusted ownership of `/app/data` and `/app/public/Assets` to ensure the non-root user has proper permissions, especially for the data volume. Updated `npm install` command to use `--omit=dev` for consistency with modern npm usage.
WalkthroughUpdates the Dockerfile to set Changes
Sequence Diagram(s)sequenceDiagram
participant Builder as Docker Build
participant Base as FROM node:...
participant FS as Image filesystem (/app)
participant Container as Container Runtime
Builder->>Base: inherit base image
Builder->>FS: ENV NODE_ENV=production
Builder->>FS: RUN npm ci --omit=dev
Builder->>FS: RUN mkdir -p /app/data /app/public/Assets
Builder->>FS: RUN chown -R node:node /app/data /app/public/Assets
Builder->>FS: USER node
note right of Container #DFF2E1: Container runs as non-root `node` user
Container->>FS: CMD ["npm","start"]
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 💡 Knowledge Base configuration:
You can enable these sources in your CodeRabbit configuration. 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
✨ Finishing Touches🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
Review by RecurseML🔍 Review performed on 8ae0c48..85ee25e ✨ No bugs found, your code is sparkling clean ⏭️ Files skipped (low suspicion) (1)• |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (3)
Dockerfile (3)
15-15: Use USER node instead of numeric UID.Clearer and resilient if the base image changes UIDs.
-USER 1000 +USER node
22-22: Exec-form CMD looks good; consider adding a HEALTHCHECK.Optional but improves operability in orchestration.
For example (adjust path/port to your app):
EXPOSE 3000 +HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \ + CMD wget -qO- http://127.0.0.1:3000/health || exit 1 -CMD ["npm", "start"] +CMD ["npm", "start"]
8-8: Prefernpm ci --omit=devfor reproducible installs
You nincompoops have a lockfile (package-lock.json), sonpm ciwill work and won’t mutate it—but it will skip your devDeps (nodemon,sharp). Verify none of those are needed at build/runtime, or move any required ones intodependencies. Optionally add--no-audit --no-fundto speed things up.Apply:
-RUN npm install --omit=dev +RUN npm ci --omit=dev
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
Dockerfile(1 hunks)
🔇 Additional comments (1)
Dockerfile (1)
3-3: Good: Explicit NODE_ENV=production.This will enable production optimizations in many libs and frameworks.
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Update the Dockerfile to use `npm ci` for dependency installation, which provides more reliable and reproducible builds by strictly adhering to `package-lock.json`. This is ideal for CI/CD and production environments. Additionally, switch from using the hardcoded UID `1000` to the named user `node`. This improves robustness and clarity, as it relies on the user defined by the base image rather than a potentially variable UID.
|
Looks good, thank you for contributing! |
Set
NODE_ENVtoproductionexplicitly for optimized builds and runtime behavior. Switch to running as a non-root user (1000) for improved container security. Adjusted ownership of/app/dataand/app/public/Assetsto ensure the non-root user has proper permissions, especially for the data volume. Updatednpm installcommand to use--omit=devfor consistency with modern npm usage.Summary by CodeRabbit