Docker image layers contain stale `npm cache` data
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from pnp/docker-spfx
-
enhancement
pnp/docker-spfx#108 · 7 comments · 1 reaction · 3 assignees ·
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 84/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
sympozium-ai/sympozium#627 ·
-
repo:raw-data
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
hotosm/raw-data-api#316 · 1 comment ·
-
agentic-workflows cascade-suspected
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
willow
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
openedx/openedx-authz#460 ·