简体   繁体   English

多个 dockerfiles 的模式和 1 package.json

[英]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.每个应用程序可能会使用 package.json 中的一部分依赖项。 Is there a good way to create a lean version of the package.json file for each sub-app?有没有什么好的方法可以为每个子应用创建精简版的 package.json 文件?

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.我意识到我不清楚问题是什么 - 问题是每个 Dockerfile(每个项目)不需要 package.json 中的所有依赖项,事实上它们可能每个只使用 20% 或更少的依赖项。 So to pare down the size of docker images, we may want a way to override package.json, something like this:因此,为了减少 docker 图像的大小,我们可能需要一种方法来覆盖 package.json,如下所示:

  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.json声明了 package.json 的依赖项子集,例如:

{
  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:我认为一种可能的解决方案是完全按照 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.这不是一个好的解决方案,因为它是动态的,但也许能让球滚动起来。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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