fix(docker): reduce image layers by merging RUN instructions (fixes OWASP#3690)#3781
fix(docker): reduce image layers by merging RUN instructions (fixes OWASP#3690)#3781ScienHAC wants to merge 2 commits intoOWASP:mainfrom
Conversation
|
The linked issue must be assigned to the PR author. |
|
Caution Review failedThe pull request is closed. Summary by CodeRabbit
WalkthroughThe Docker frontend Dockerfile is optimized by merging multiple RUN instructions in the builder stage to reduce image layers. The runner stage is enhanced with an explicit version check for the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested labels
Suggested reviewers
✨ Finishing touches🧪 Generate unit tests (beta)
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. Comment |
|
There was a problem hiding this comment.
Pull request overview
This PR optimizes the Docker build process for the frontend service by consolidating multiple RUN instructions into fewer commands, which reduces the number of image layers and potentially improves build efficiency.
Changes:
- Merged directory setup and symlink creation with apk package installation in the builder stage
- Consolidated npm vulnerability fixes (tar@7.5.7 and @isaacs/brace-expansion@5.0.1) with user/group creation in the runner stage
- Removed inline comments from within chained RUN commands to prevent Dockerfile syntax issues
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| grep -q '"version": "5.0.1"' "${BRACE_DIR}/package.json" && \ | ||
| addgroup --system --gid 1001 nodejs && \ |
There was a problem hiding this comment.
Merging the CVE vulnerability fixes with user/group creation creates a problematic dependency. If the npm vulnerability fixes fail (e.g., due to version unavailability or network issues), the system users won't be created, which will cause the container to fail at runtime when trying to switch to the 'nextjs' user.
These operations are semantically distinct: the CVE fixes are temporary workarounds that might need to be removed in the future when base images are updated, while user creation is a permanent structural requirement for the container.
Consider separating user creation into its own RUN instruction after the CVE fixes. This improves maintainability and ensures the container has the necessary users even if CVE fix commands need to be modified or removed. The additional layer from user creation is negligible compared to the reliability benefit.
| grep -q '"version": "5.0.1"' "${BRACE_DIR}/package.json" && \ | |
| addgroup --system --gid 1001 nodejs && \ | |
| grep -q '"version": "5.0.1"' "${BRACE_DIR}/package.json" | |
| RUN addgroup --system --gid 1001 nodejs && \ |
|
|
||
| # Fix CVE-2026-25547: Update npm's bundled @isaacs/brace-expansion to 5.0.1 in runner stage | ||
| RUN cd /tmp && \ | ||
| grep -q 'version.*7.5.7' "${TAR_DIR}/package.json" && \ |
There was a problem hiding this comment.
The removed comment "Fix CVE-2026-25547: Update npm's bundled @isaacs/brace-expansion to 5.0.1 in runner stage" should be preserved above the RUN instruction as a standalone comment. This documentation is important for understanding why this specific package update is being performed and makes future maintenance easier when determining if the fix can be removed.
Move the comment to line 65 (or the line before the cd /tmp command) as a separate comment line rather than removing it entirely.
| grep -q 'version.*7.5.7' "${TAR_DIR}/package.json" && \ | |
| grep -q 'version.*7.5.7' "${TAR_DIR}/package.json" && \ | |
| # Fix CVE-2026-25547: Update npm's bundled @isaacs/brace-expansion to 5.0.1 in runner stage |



Proposed change
Resolves #3690
This PR optimizes the Docker build process by reducing the number of image layers in
docker/frontend/Dockerfile.Summary of changes
apkpackage note installation into a singleRUNinstruction.npmvulnerability fix commands were merged with user/group creation into oneRUNinstruction.RUNcommands to avoid Dockerfile syntax issues.Benefits
Checklist
make check-testlocally and all tests passed