简体   繁体   中英

pattern for multiple dockerfiles and 1 package.json

Say I have this:

project/
   app1/Dockerfile
   app2/Dockerfile
   app3/Dockerfile
   package.json

each app might use a subset of the dependencies in package.json. Is there a good way to create a lean version of the package.json file for each sub-app?

I realized I wasn't clear about what the problem is - the problem is that each Dockerfile (each project) doesn't need all the dependencies in package.json, in fact they might each use only 20% or fewer of the dependencies. So to pare down the size of docker images, we may want a way to override package.json, something like this:

  project/
       app1/
          Dockerfile
          dependencies.json
       app2/
          Dockerfile
          dependencies.json
       app3/
          Dockerfile
          dependencies.json
       package.json

where dependencies.json declares a subset of the dependencies from package.json, eg:

{
  dependencies: ['foo', 'bar', 'baz']
}

or even more fun maybe:

{
   antiDependencies: ['foo', 'bar', 'baz']
}

the dependencies to not install or what not.

(Untested solution)

I think one potential solution is to do exactly as in OP:

// package.js

const pkgJson = require('../../package.json')

module.exports = Object.assign({}, pkgJson, {

    dependencies: {
       ...pkgJson.dependencies,
       // eliminate these:
       heavyDep: undefined,  
       anotherHeavyDep: undefined
   }

});

this is NOT a good solution b/c it's dynamic, but maybe get the ball rolling.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM