Skip to content

Conversation

@bob10042
Copy link

Issue

Fixes #333

Problem

Docker build fails with:
\
E: Unable to locate package nodejs
\\

This happens because the NodeSource repository setup and the \�pt-get install nodejs\ are in separate RUN commands. The package index from the first RUN layer is not available in subsequent layers.

Solution

Combined the NodeSource setup, apt-get update, and apt-get install nodejs into a single RUN command:

\\dockerfile
RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - &&
apt-get update &&
apt-get install -y nodejs
\\

Root Cause

Docker layers are independent. When you run \�pt-get update\ in one layer and \�pt-get install\ in another, the package cache from the first layer is not guaranteed to be available or valid in the second layer.

Testing

This fix follows standard Docker best practices for package installation.

The NodeSource setup script adds the repository but doesn't refresh the apt
cache, causing 'apt-get install nodejs' to fail with 'Unable to locate package'.

Changes:
- Add apt-get update after NodeSource setup script to refresh package lists
- Combine NodeSource setup and nodejs install into single RUN for efficiency
- Add apt-get clean and remove apt lists to reduce image size

Fixes thoughtworks#333
Copilot AI review requested due to automatic review settings January 30, 2026 14:54
@bob10042 bob10042 requested a review from a team as a code owner January 30, 2026 14:54
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 fixes a Docker build failure where the Node.js package installation was failing with "Unable to locate package nodejs". The issue occurred because the NodeSource repository setup and package installation were in separate RUN commands, causing the package index to be unavailable in subsequent layers.

Changes:

  • Combined NodeSource setup, apt-get update, and Node.js installation into a single RUN command
  • Added apt cache cleanup to the Cypress dependencies installation for smaller image size
  • Improved comments for clarity and added context about the installation steps

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +6 to 11
# Install Node.js using NodeSource - run apt-get update after setup script
# The setup script adds the NodeSource repository but apt cache may be stale
RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - \
&& apt-get update \
&& apt-get install -y nodejs

Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

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

The apt-get update command here is redundant. The NodeSource setup script (setup_18.x) already runs apt-get update as part of its execution. This adds unnecessary time to the Docker build. Consider removing this line to optimize the build process.

Suggested change
# Install Node.js using NodeSource - run apt-get update after setup script
# The setup script adds the NodeSource repository but apt cache may be stale
RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - \
&& apt-get update \
&& apt-get install -y nodejs
# Install Node.js using NodeSource
# The setup script adds the NodeSource repository and runs apt-get update
RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - \
&& apt-get install -y nodejs

Copilot uses AI. Check for mistakes.
# The setup script adds the NodeSource repository but apt cache may be stale
RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - \
&& apt-get update \
&& apt-get install -y nodejs
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

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

For consistency with the other package installation command (lines 13-17) and Docker best practices, consider adding apt-get clean and rm -rf /var/lib/apt/lists/* at the end of this RUN command to reduce the image layer size. This helps minimize the final Docker image size by removing the apt package cache.

Suggested change
&& apt-get install -y nodejs
&& apt-get install -y nodejs \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

Copilot uses AI. Check for mistakes.
FROM nginx:1.23.0

# Update apt and install required packages
RUN apt-get update && apt-get upgrade -y
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

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

Following Docker best practices and for consistency with lines 16-17, consider adding apt-get clean and rm -rf /var/lib/apt/lists/* at the end of this RUN command to reduce the image layer size. This helps minimize the final Docker image size by removing the apt package cache after upgrades.

Suggested change
RUN apt-get update && apt-get upgrade -y
RUN apt-get update && apt-get upgrade -y \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

Copilot uses AI. Check for mistakes.
RUN apt-get install -y nodejs
# Install Node.js using NodeSource - run apt-get update after setup script
# The setup script adds the NodeSource repository but apt cache may be stale
RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - \
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

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

The RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - line downloads and executes a remote script as root without any integrity verification, creating a supply chain risk if the NodeSource endpoint or its delivery path is compromised. An attacker who can tamper with that script (via DNS, CDN, or repository compromise) could inject arbitrary commands into your build and produce a malicious image. Prefer installing Node.js via signed distribution packages or ensure the script is pinned and verified via checksum or signature before execution.

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.

docker build failed

1 participant