Skip to content

Docker image layers contain stale npm cache data #115

Description

@CalvinTPark

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

docker-spfx/Dockerfile

Lines 16 to 17 in 9248280

RUN npm i --location=global gulp-cli@3 yo pnpm
RUN npm i --location=global @microsoft/generator-sharepoint@1.21.1

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions