Jie*_*eng 29 amazon-web-services node.js npm amazon-elastic-beanstalk yarnpkg
是否可以配置EBS使用yarn包管理器而不是NPM来安装我的NodeJS应用程序?
Gre*_*n23 28
我已经找到了办法,但它有点笨拙.
.ebextensions/yarn.config文件.(这个名字不一定是'纱'.)将此内容放入文件中:
files:
# Runs right before `npm install` in '.../50npm.sh'
"/opt/elasticbeanstalk/hooks/appdeploy/pre/49yarn.sh" :
mode: "000775"
owner: root
group: users
content: |
#!/bin/bash
app="$(/opt/elasticbeanstalk/bin/get-config container -k app_staging_dir)";
# install node
curl --silent --location https://rpm.nodesource.com/setup_8.x | bash -;
# install yarn
curl --silent --location https://dl.yarnpkg.com/rpm/yarn.repo | tee /etc/yum.repos.d/yarn.repo;
yum -y install yarn;
# install node_modules with yarn
cd "${app}";
yarn --production;
Run Code Online (Sandbox Code Playgroud)这个ebextension创建了一个文件,它可以做三件事:
为了使Elastic Beanstalk在运行yarn install之前运行npm install,将在下创建该文件/opt/elasticbeanstalk/hooks/appdeploy/pre.这会将文件转换为预部署挂钩,这意味着Elastic Beanstalk将在部署的第一阶段运行它.默认情况下,此目录中有另一个文件,该文件50npm.sh运行npm install.由于Elastic Beanstalk按字母顺序运行此目录中的文件,49yarn.sh(我们的文件)将在之前运行50npm.sh(默认文件),从而导致yarn install之前运行npm install.
一个潜在的问题是,在部署阶段的此时,Elastic Beanstalk UI(在Configuration> 下Software Configuration)中设置的环境变量不可用.如果您有一个用于安装私有npm模块的npm身份验证令牌,这是一个大问题.
另一个潜在的问题是,这会手动安装节点,因此您在Elastic Beanstalk UI(在Configuration>下面Software Configuration)中指定的"节点版本" 将不会影响您的应用程序使用的节点版本; 你需要在这个ebextension中指定它.Elastic Beanstalk 50npm.sh都安装节点并运行npm install.由于我们必须yarn install在该文件运行之前运行,因此我们还必须手动安装节点.然后,当Elastic Beanstalk进入安装节点时,它会检测到该节点已安装但未验证它是否为正确的版本,因此它会跳过节点安装.
作为参考,纱线安装说明来自此处:https: //yarnpkg.com/docs/install#linux-tab
我按照https://yarnpkg.com/lang/en/docs/install/上的说明执行了此操作
commands:
01_install_yarn:
command: "sudo wget https://dl.yarnpkg.com/rpm/yarn.repo -O /etc/yum.repos.d/yarn.repo && curl --silent --location https://rpm.nodesource.com/setup_6.x | sudo bash - && sudo yum install yarn -y"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8468 次 |
| 最近记录: |