node.js - 如何缓存 NodeJS 全局模块 AWS CodeBuild

标签 node.js amazon-web-services npm npm-install aws-codebuild

有没有办法在 AWS CodeBuild 上缓存 NodeJS 全局模块?

我使用 LernaJS 来处理我的存储库,每次构建开始时,我都会使用命令 npm install -g lerna 安装它(需要 30 秒)。

为了解决这个问题,首先我使用命令 npm list -g 找出 npm install Lerna 的位置并返回

/usr/local/lib 
├─┬ grunt@1.0.4 
│ ├── coffeescript@1.10.0 
...
├─┬ lerna@3.14.1 
│ ├─┬ @lerna/add@3.14.0 
│ │ ├── @lerna/bootstrap@3.14.0 deduped 
...

然后我尝试缓存 /usr/local/lib/node_modules/**/* 文件夹,但收到以下错误:

[Container] 2019/05/30 20:09:00 Running command npm install -g lerna 
/codebuild/output/tmp/script.sh: 4: /codebuild/output/tmp/script.sh: npm: not found 

[Container] 2019/05/30 20:09:00 Command did not exit successfully npm install -g lerna exit status 127 
[Container] 2019/05/30 20:09:00 Phase complete: INSTALL State: FAILED 
[Container] 2019/05/30 20:09:00 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: npm install -g lerna. Reason: exit status 127 

所以我检查了 /usr/local/lib/node_modules/ 的内容,我有这些包:

[Container] 2019/05/30 20:19:11 Running command ls /usr/local/lib/node_modules 
grunt 
grunt-cli 
lerna 
npm 
webpack 

我最后一次尝试是缓存/usr/local/lib/node_modules/lerna/**/*。这样就不会抛出错误,但缓存也不起作用:

[Container] 2019/05/30 20:30:00 MkdirAll: /codebuild/local-cache/custom/656f09faf2819a785eae5e09f5d26a44ff4f20edf155297d6819c9600540cd26/usr/local/lib/node_modules/lerna 
[Container] 2019/05/30 20:30:00 Symlinking: /usr/local/lib/node_modules/lerna => /codebuild/local-cache/custom/656f09faf2819a785eae5e09f5d26a44ff4f20edf155297d6819c9600540cd26/usr/local/lib/node_modules/lerna 

...

[Container] 2019/05/30 20:30:01 Running command npm install -g lerna 
/usr/local/bin/lerna -> /usr/local/lib/node_modules/lerna/cli.js 
+ lerna@3.14.1 
added 650 packages from 321 contributors and updated 1 package in 40.628s 

我错过了什么吗?有没有办法将 Lerna 保存为 gruntgrunt-clnpmwebpack (在 /usr/local/lib/node_modules/)在构建开始之前?

谢谢!

最佳答案

感谢 @JD D 评论,我创建了一个 docker 镜像,将其推送到 AWS ECR 并将其用作我自己的镜像。

我的 Dockerfile:

FROM node:lts
RUN npm install -g yarn lerna
RUN apt-get update && \
  apt-get install -y groff less && \
  apt-get clean
RUN curl https://s3.amazonaws.com/aws-cli/awscli-bundle.zip -o awscli-bundle.zip
RUN unzip awscli-bundle.zip  && \
  ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws && \
  rm awscli-bundle.zip

关于node.js - 如何缓存 NodeJS 全局模块 AWS CodeBuild,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56385669/

相关文章:

node.js - 如何在 Azure 应用程序控制台上运行 npm 命令?

node.js 我可以为同一个项目使用多个 ssl 证书和 key 吗?如何使用?

node.js - PB mongodb、 Mongoose 、node.js

node.js - 声明多个模式后无法从数据库中获取数据(mongoose + express + mongodb

amazon-web-services - 云形成无法创建带有 VPCIdNotSpecified 的安全组

java - 从 Node.js 调用 Java Lambda 函数

javascript - 如何在react-native中重置IOS文件夹

node.js - 错误 HH604 : Error running JSON-RPC server: Must be authenticated! Hardhat Node.js Alchemy

c# - aws codebuild dotnet :5. 0 - 没有可用的 sdk 命令

node.js - Vuesax 4 错误 : Cannot find module 'chalk'