Skip to content

fix(docker): reduce image layers by merging RUN instructions (fixes OWASP#3690)#3781

Closed
ScienHAC wants to merge 2 commits intoOWASP:mainfrom
ScienHAC:main
Closed

fix(docker): reduce image layers by merging RUN instructions (fixes OWASP#3690)#3781
ScienHAC wants to merge 2 commits intoOWASP:mainfrom
ScienHAC:main

Conversation

@ScienHAC
Copy link
Contributor

@ScienHAC ScienHAC commented Feb 5, 2026

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

  • In the builder stage, directory setup commands were merged with the apk package note installation into a single RUN instruction.
  • In the runner stage, npm vulnerability fix commands were merged with user/group creation into one RUN instruction.
  • Removed inline comments inside chained RUN commands to avoid Dockerfile syntax issues.

Benefits

  • Fewer Docker layers
  • Smaller image size
  • Faster build times
  • Cleaner and more maintainable Dockerfile

Checklist

  • Required: I followed the contributing workflow
  • Required: I verified that my code works as intended and resolves the issue
  • Required: I ran make check-test locally and all tests passed
  • I used AI for code, documentation, tests, or communication related to this PR

Copilot AI review requested due to automatic review settings February 5, 2026 08:01
@github-actions
Copy link

github-actions bot commented Feb 5, 2026

The linked issue must be assigned to the PR author.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 5, 2026

Caution

Review failed

The pull request is closed.

Summary by CodeRabbit

  • Chores
    • Enhanced build process reliability through optimized Docker configuration and dependency version validation in the build pipeline.

Walkthrough

The 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 @isaacs/brace-expansion dependency (version 5.0.1) before npm pack, with command reordering to validate the dependency version prior to subsequent operations.

Changes

Cohort / File(s) Summary
Docker Optimization
docker/frontend/Dockerfile
Builder stage consolidates APK cache directory creation and symlink into a single RUN instruction. Runner stage adds a pre-check for @isaacs/brace-expansion version 5.0.1 before npm pack and reorders steps to perform version validation before group/user creation.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

frontend, docker

Suggested reviewers

  • arkid15r
  • kasya
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions bot closed this Feb 5, 2026
@sonarqubecloud
Copy link

sonarqubecloud bot commented Feb 5, 2026

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +74 to +75
grep -q '"version": "5.0.1"' "${BRACE_DIR}/package.json" && \
addgroup --system --gid 1001 nodejs && \
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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 && \

Copilot uses AI. Check for mistakes.

# 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" && \
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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

Copilot uses AI. Check for mistakes.
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.

merging Multiple RUN Instruction in Frontend DockerFile.

2 participants