Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce size of npm dependencies => reduce weight of image on docker hub #309

Closed
adrienjoly opened this issue Mar 28, 2020 · 3 comments
Closed
Assignees
Labels
dependencies Pull requests that update a dependency file enhancement help wanted

Comments

@adrienjoly
Copy link
Member

adrienjoly commented Mar 28, 2020

E.g. by applying some changes recommended in Docker and Node.js Best Practices from Bret Fisher at DockerCon - YouTube.

From https://stackoverflow.com/questions/40642008/how-do-i-view-the-size-of-npm-packages:

✗ npx cost-of-modules
npx : 16 installé(s) en 4.599s

Making sure dependencies are installed
npm install --production


> openwhyd@1.30.6 postinstall /Users/adrienjoly/dev/openwhyd/openwhyd
> npm run -s donate; cp node_modules/playemjs/dist/playem-*.js public/js/


   *** Thanks for downloading Openwhyd! ***
Please consider donating to our open collective

 => https://opencollective.com/openwhyd/donate

audited 24435 packages in 12.168s

6 packages are looking for funding
  run `npm fund` for details

found 378 vulnerabilities (372 low, 1 moderate, 5 high)
  run `npm audit fix` to fix them, or `npm audit` for details

Calculating...


┌─────────────────┬──────────────┬────────┐
│ name            │ children     │ size   │
├─────────────────┼──────────────┼────────┤
│ forever         │ 432          │ 20.35M │
├─────────────────┼──────────────┼────────┤
│ playemjs        │ 2            │ 15.39M │
├─────────────────┼──────────────┼────────┤
│ iconv           │ 2            │ 8.18M  │
├─────────────────┼──────────────┼────────┤
│ request         │ 59           │ 4.38M  │
├─────────────────┼──────────────┼────────┤
│ argon2          │ 82           │ 4.09M  │
├─────────────────┼──────────────┼────────┤
│ mongodb         │ 13           │ 3.43M  │
├─────────────────┼──────────────┼────────┤
│ connect-mongo   │ 6            │ 3.27M  │
├─────────────────┼──────────────┼────────┤
│ emailjs         │ 2            │ 2.72M  │
├─────────────────┼──────────────┼────────┤
│ express         │ 82           │ 2.51M  │
├─────────────────┼──────────────┼────────┤
│ algoliasearch   │ 23           │ 2.23M  │
├─────────────────┼──────────────┼────────┤
│ hogan.js        │ 0            │ 0.81M  │
├─────────────────┼──────────────┼────────┤
│ async           │ 0            │ 0.66M  │
├─────────────────┼──────────────┼────────┤
│ express-session │ 9            │ 0.31M  │
├─────────────────┼──────────────┼────────┤
│ apn             │ 1            │ 0.23M  │
├─────────────────┼──────────────┼────────┤
│ formidable      │ 0            │ 0.14M  │
├─────────────────┼──────────────┼────────┤
│ htmlparser      │ 0            │ 0.11M  │
├─────────────────┼──────────────┼────────┤
│ object-sizeof   │ 3            │ 0.10M  │
├─────────────────┼──────────────┼────────┤
│ ent             │ 0            │ 0.09M  │
├─────────────────┼──────────────┼────────┤
│ colors          │ 0            │ 0.04M  │
├─────────────────┼──────────────┼────────┤
│ q-set           │ 0            │ 0.01M  │
├─────────────────┼──────────────┼────────┤
│ 20 modules      │ 317 children │ 52.06M │
└─────────────────┴──────────────┴────────┘
@adrienjoly adrienjoly added help wanted dependencies Pull requests that update a dependency file enhancement labels Mar 28, 2020
adrienjoly added a commit that referenced this issue Mar 28, 2020
Contributes to #309.

Log files were found while checking the contents of our Docker image, in PR #306. => Let's ignore them.
adrienjoly pushed a commit that referenced this issue Mar 28, 2020
## [1.33.1](v1.33.0...v1.33.1) (2020-03-28)

### Bug Fixes

* **docker:** ignore log files ([#311](#311)) ([5b83c07](5b83c07)), closes [#309](#309) [#306](#306)
@adrienjoly
Copy link
Member Author

adrienjoly commented Mar 28, 2020

EDIT: Souvenir of what our docker hub profile looks like before merging this PR:

image

  • v1.4.3 = 396.12 MB
    [...]
  • v1.32 = 391.49 MB
  • v1.33.2 = 391.44 MB
  • v1.33.3 = 386 MB (after removing forever)
  • v1.33.4 = 383.47 MB (after reducing playemjs)
  • v1.33.6 = 203.14 MB 🔥 (after switching to node-slim docker image)

image

adrienjoly added a commit that referenced this issue Mar 28, 2020
@adrienjoly
Copy link
Member Author

After removing forever (the biggest dependency, in #313), the biggest dependency becomes playemjs! 😅

$ npx cost-of-modules

┌─────────────────┬──────────────┬────────┐
│ name            │ children     │ size   │
├─────────────────┼──────────────┼────────┤
│ playemjs        │ 2            │ 15.39M │
├─────────────────┼──────────────┼────────┤
│ iconv           │ 2            │ 8.18M  │
├─────────────────┼──────────────┼────────┤
│ request         │ 59           │ 4.38M  │
├─────────────────┼──────────────┼────────┤
│ argon2          │ 85           │ 4.11M  │
├─────────────────┼──────────────┼────────┤
│ mongodb         │ 13           │ 3.43M  │
├─────────────────┼──────────────┼────────┤
│ connect-mongo   │ 6            │ 3.27M  │
├─────────────────┼──────────────┼────────┤
│ emailjs         │ 2            │ 2.72M  │
├─────────────────┼──────────────┼────────┤
│ express         │ 82           │ 2.51M  │
├─────────────────┼──────────────┼────────┤
│ algoliasearch   │ 23           │ 2.23M  │
├─────────────────┼──────────────┼────────┤
│ hogan.js        │ 0            │ 0.81M  │
├─────────────────┼──────────────┼────────┤
│ async           │ 0            │ 0.66M  │
├─────────────────┼──────────────┼────────┤
│ express-session │ 9            │ 0.31M  │
├─────────────────┼──────────────┼────────┤
│ apn             │ 1            │ 0.23M  │
├─────────────────┼──────────────┼────────┤
│ formidable      │ 0            │ 0.14M  │
├─────────────────┼──────────────┼────────┤
│ htmlparser      │ 0            │ 0.11M  │
├─────────────────┼──────────────┼────────┤
│ object-sizeof   │ 3            │ 0.10M  │
├─────────────────┼──────────────┼────────┤
│ ent             │ 0            │ 0.09M  │
├─────────────────┼──────────────┼────────┤
│ colors          │ 0            │ 0.04M  │
├─────────────────┼──────────────┼────────┤
│ q-set           │ 0            │ 0.01M  │
├─────────────────┼──────────────┼────────┤
│ 19 modules      │ 181 children │ 43.58M │
└─────────────────┴──────────────┴────────┘

adrienjoly pushed a commit that referenced this issue Mar 28, 2020
## [1.33.3](v1.33.2...v1.33.3) (2020-03-28)

### Bug Fixes

* **deps:** remove forever from dependencies ([#313](#313)) ([b41699d](b41699d)), closes [#309](#309)
adrienjoly added a commit that referenced this issue Mar 28, 2020
Contributes to #309.

We identified in #309 (comment) that PlayemJS had become Openwhyd's biggest dependency (in terms of size in MBs), after getting rid of `forever`.
adrienjoly pushed a commit that referenced this issue Mar 28, 2020
## [1.33.4](v1.33.3...v1.33.4) (2020-03-28)

### Bug Fixes

* **deps:** upgrade to (smaller) playemjs v0.3.1 ([#314](#314)) ([4ea4237](4ea4237)), closes [#309](#309) [/github.com//issues/309#issuecomment-605508547](https://github.com//github.com/openwhyd/openwhyd/issues/309/issues/issuecomment-605508547)
adrienjoly added a commit that referenced this issue Mar 28, 2020
Contributes to #309.

Upgraded `playemjs` to a version that doesn't need `git` to install `soundmanager2` dependency. (as `git` is not installed on the `slim` version of the `node` docker image)
adrienjoly pushed a commit that referenced this issue Mar 28, 2020
## [1.33.6](v1.33.5...v1.33.6) (2020-03-28)

### Bug Fixes

* **docker:** use slim node docker image ([#312](#312)) ([b9d58ae](b9d58ae)), closes [#309](#309)
@adrienjoly adrienjoly self-assigned this Mar 28, 2020
@adrienjoly
Copy link
Member Author

Note: after upgrading Node.js (#656), the size of the docker image went from 123 to 428 MB!

image

cf:

=> Re-opening

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file enhancement help wanted
Projects
None yet
Development

No branches or pull requests

1 participant