Docker / GitLab:在docker镜像中安装的npm依赖项,但是通过runner没有得到满足

首先,我正在检查我在gitlab CI中作为docker runner使用的testingdocker镜像:

在Docker容器( testing )中运行这个命令…

 meteor npm list --depth=0 

给了我预期的结果:

 npm info it worked if it ends with ok npm info using npm@5.4.2 npm info using node@v8.6.0 project@1.0.0 /builds/namespace/project +-- autoprefixer@7.1.5 +-- babel-runtime@6.26.0 +-- bcrypt@1.0.3 +-- fluent-ffmpeg@2.1.2 +-- gm@1.23.0 +-- gridfs-stream@1.1.1 +-- react@16.0.0 

所以所有的依赖项都安装在docker镜像中。 现在我在我的gitLab CI中使用这个图像:

我的gitLab CI yml文件如下所示:

 unit: image: testing:latest stage: unit tags: - testing script: - meteor npm list --depth=0 

但结果是:

 npm info it worked if it ends with ok npm info using npm@5.4.2 npm info using node@v8.6.0 project@1.0.0 /builds/namespace/project +-- UNMET DEPENDENCY autoprefixer@7.1.4 +-- UNMET DEPENDENCY babel-runtime@6.26.0 +-- UNMET DEPENDENCY bcrypt@1.0.3 +-- UNMET DEPENDENCY fluent-ffmpeg@2.1.2 +-- UNMET DEPENDENCY gm@1.23.0 +-- UNMET DEPENDENCY gridfs-stream@1.1.1 +-- UNMET DEPENDENCY react@15.6.0 

为什么没有安装依赖关系? 每次CI运行作业时,我都不想安装它们。 相反,我希望docker镜像中已经安装的所有依赖项更快。

更新

运行CI阶段,没有node_modules目录,它存在于泊坞窗图像中…如何防止gitlab删除文件夹?

这是因为当开始构build时,它会再次获取您的repo,基本上用新鲜克隆覆盖内容。 最快的解决方法是暂时将依赖项移动到不同的文件夹,然后在实际构build期间将其移回。 例如,执行meteor npm installnode_modules移动到/example/node_modules然后在构build过程中将它们移回到/builds/namespace/project/node_modules