Docker image layers contain stale `npm cache` data

Open Beginner friendly
#115 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
76/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
docker
Domain
devops

Research direction

Start with the npm install commands in Dockerfile lines 16–17 and review Docker image layer behavior. Build the updated image and verify that clearing the npm cache is in the same layer as the installs; confirm the image size reduction and that project builds, including the case in #114, still work.

Written by the indexing model from the issue text.

Description

The npm install commands in the Dockerfile don't remove the npm cache files.

The cached files become stale as the image ages and likely unused.

This resulting an image size being increase by over 1GB with internal testing:

2.455GB -> 1.359GB

https://github.com/pnp/docker-spfx/blob/9248280243d2fac041cad7bf2a87299b1d3fb2e9/Dockerfile#L16-L17

Have tested image change with project builds including in #114

  • I am willing to contribute to this issue

Potential Solution:

Clear the cache after the package installs:

RUN npm i --location=global gulp-cli@3 yo pnpm \
  && npm i --location=global @microsoft/generator-sharepoint@1.21.1 \
  && npm cache clean --force
- RUN npm i --location=global gulp-cli@3 yo pnpm 
- RUN npm i --location=global @microsoft/generator-sharepoint@1.21.1 
+ RUN npm i --location=global gulp-cli@3 yo pnpm \
+  && npm i --location=global @microsoft/generator-sharepoint@1.21.1 \
+  && npm cache clean --force

Note that clearing the cache in a separate layer (subsequent command) will not decrease the image's size.

Dominant language
Dockerfile
Stars
134
Forks
47
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from pnp/docker-spfx

All issues in pnp/docker-spfx

Similar issues

More DevOps issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.