apache / openwhisk

Apache OpenWhisk is an open source serverless cloud platform
https://openwhisk.apache.org/
Apache License 2.0
6.5k stars 1.16k forks source link

Why does OpenWhisk node containers install plenty of never-used dependencies? #1721

Closed balupton closed 7 years ago

balupton commented 7 years ago

Why are any of these here? https://github.com/openwhisk/openwhisk/blob/0eaee0463103e416d12ef07fbe736a9f344ea5e9/core/nodejs6Action/Dockerfile#L21-L75

Especially when there is already https://github.com/openwhisk/openwhisk/blob/0eaee0463103e416d12ef07fbe736a9f344ea5e9/core/nodejs6Action/Dockerfile#L19 to install the package dependencies - the deps the package actually uses

rabbah commented 7 years ago

there are two parts at play:

  1. installing the required dependencies to run the nodejs proxy for actions (that's what the npm install from the package.json accomplishes)

  2. installing useful packages so that actions have them readily accessible and eschewing the need for an action zip file containing the dependencies

From time to time we have the list of packages in response to interest. We separate the two because they server different constraints and one may change independent of the other.

balupton commented 7 years ago

Thanks for the speedy response!

eschewing the need for an action zip file containing the dependencies

Hrmmm. Why would that be the case, as https://github.com/openwhisk/openwhisk/blob/0eaee0463103e416d12ef07fbe736a9f344ea5e9/core/nodejs6Action/Dockerfile#L17-L19 seems to remove any bundled deps, and then reinstall them anyway - so I'd imagine that node_modules shouldn't be getting included in action zips as the rm removes it anyway for reinstalling

rabbah commented 7 years ago

this line

RUN rm -rf .project .settings build.xml Dockerfile README node_modules logs

removes any files that might have been copied from your local file system into the docker image

and this line

RUN npm install .

runs npm install on the left over package.json

all modules are insalled inside the container not mounted from the host (for example if there are requirements to build a native package it has to be specific to the container not the host).

rabbah commented 7 years ago

so I'd imagine that node_modules shouldn't be getting included in action zips as the rm removes it anyway for reinstalling

I may be inferring something incorrectly about your question - when openwhisk runs a user action, it does not build a new Docker image for that action.

The nodejs6action container is a generic base image. The user code is injected into the container later, and run, without modifying the base image. So modules that come in via zip file are not modified since they are not subject to a docker build.

rabbah commented 7 years ago

@balupton anything else we can help with here?

balupton commented 7 years ago

no all good thanks