自定义AWS ElasticBeanstalk NodeJS安装(使用yarn) [英] Customize AWS ElasticBeanstalk NodeJS Install (use yarn)

查看:153
本文介绍了自定义AWS ElasticBeanstalk NodeJS安装(使用yarn)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将EBS配置为使用纱线包管理器而不是NPM安装我的NodeJS应用程序?

Isit possible to configure EBS to install my NodeJS application using yarn package manager instead of NPM?

推荐答案

我想出了一种方法,但是有点不客气.

I've figured out a way, but it is a little hacky.

  1. 创建一个.ebextensions/yarn.config文件. (名称不必为'yarn'.)
  2. 将此内容放入文件中

  1. Create a .ebextensions/yarn.config file. (The name does not have to be 'yarn'.)
  2. Put this content into the file:

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;

此扩展名创建的文件可以执行3件事:

This ebextension creates a file which does 3 things:

  1. 安装节点.
  2. 安装纱线.
  3. 用yarn安装node_modules.

为了使Elastic Beanstalk在运行npm install之前运行yarn install,请在/opt/elasticbeanstalk/hooks/appdeploy/pre下创建文件.这会将文件转换为预部署挂钩,这意味着Elastic Beanstalk将在部署的第一阶段运行它.默认情况下,此目录中还有一个名为50npm.sh的文件,该文件运行npm install.由于Elastic Beanstalk按字母顺序运行此目录中的文件,因此49yarn.sh(我们的文件)将在50npm.sh(默认文件)之前运行,从而导致yarn installnpm install之前运行.

In order to make Elastic Beanstalk run yarn install before it runs npm install, the file is created under /opt/elasticbeanstalk/hooks/appdeploy/pre. This turns the file into a pre-deployment hook, which means that Elastic Beanstalk will run it during the first phase of deployment. By default, there is another file in this directory called 50npm.sh, which runs npm install. Since Elastic Beanstalk runs the files in this directory alphabetically, 49yarn.sh (our file) will run before 50npm.sh (the default file), resulting in yarn install running before npm install.

一个潜在的问题是,在部署阶段的这一点上,在Elastic Beanstalk UI中设置的环境变量(在Configuration> Software Configuration下)不可用.如果您有一个用于安装私有npm模块的npm auth令牌,这将是一个大问题.

One potential problem is that the environment variables set in the Elastic Beanstalk UI (under Configuration > Software Configuration) are not available at this point of the deployment phase. This is a big problem if you have an npm auth token there which you use to install private npm modules.

另一个潜在的问题是这会手动安装节点,因此您在Elastic Beanstalk UI中(在Configuration> Software Configuration下)指定的节点版本"将不会对您的应用程序使用的节点版本产生影响.您需要在此ebextension中指定它. Elastic Beanstalk的50npm.sh既安装节点又运行npm install.由于必须在文件运行之前运行yarn install,所以我们还必须手动安装节点.然后,当Elastic Beanstalk转到安装节点时,它将检测到该节点已经安装,但不验证其版本是否正确,因此它跳过了该节点的安装.

Another potential problem is that this installs node manually, so the "Node version" you specify in the Elastic Beanstalk UI (under Configuration > Software Configuration) will have no effect on the version of node your application uses; you need to specify it in this ebextension. Elastic Beanstalk's 50npm.sh both installs node and runs npm install. Since we have to run yarn install before that file runs, we also have to install node manually. Then, when Elastic Beanstalk goes to install node, it detects that node is already installed but does not verify that it is the correct version, so it skips the node installation.

作为参考,纱线安装说明来自此处: https://yarnpkg.com/docs/install#linux-tab

For reference, the yarn installation instructions came from here: https://yarnpkg.com/docs/install#linux-tab

这篇关于自定义AWS ElasticBeanstalk NodeJS安装(使用yarn)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆