【问题标题】:Install packages with Yarn on Elastic Beanstalk在 Elastic Beanstalk 上使用 Yarn 安装包
【发布时间】:2019-11-08 14:08:35
【问题描述】:

我想在 Elastic Beanstalk 上安装软件包,使用 Yarn 作为 NPM 的替代品。我尝试了在网上找到的各种解决方案,但它们似乎都已经过时并且不再有效。这就是我现在所拥有的,如this gist 中所述。

files:
  '/opt/elasticbeanstalk/hooks/appdeploy/pre/49yarn.sh' :
    mode: '000755'
    owner: root
    group: root
    content: |
      #!/usr/bin/env bash
      set -euxo pipefail

      EB_APP_STAGING_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k app_staging_dir)

      if node -v; then
        echo 'Node already installed.'
      else
        echo 'Installing node...'
        curl --silent --location https://rpm.nodesource.com/setup_6.x | sudo bash -
        yum -y install nodejs
      fi

      if yarn -v; then
        echo 'Yarn already installed.'
      else
        echo 'Installing yarn...'
        wget https://dl.yarnpkg.com/rpm/yarn.repo -O /etc/yum.repos.d/yarn.repo
        yum -y install yarn
      fi

  '/opt/elasticbeanstalk/hooks/appdeploy/pre/50npm.sh' :
    mode: '000755'
    owner: root
    group: root
    content: |
      #!/usr/bin/env bash
      set -euxo pipefail

      yarn install --ignore-engines

【问题讨论】:

    标签: node.js amazon-elastic-beanstalk yarnpkg


    【解决方案1】:

    以上答案仅适用于 Amazon Linux (AMI) 1 版本。如果您使用的是 AMI 版本 2,您可以执行以下操作:

    1. 创建一个.platform/hooks/prebuild/yarn.sh 文件,内容如下:
    #!/bin/bash
    
    # need to install node first to be able to install yarn (as at prebuild no node is present yet)
    sudo curl --silent --location https://rpm.nodesource.com/setup_14.x | sudo bash -
    sudo yum -y install nodejs
    
    # install yarn
    sudo wget https://dl.yarnpkg.com/rpm/yarn.repo -O /etc/yum.repos.d/yarn.repo
    sudo yum -y install yarn
    
    # install
    cd /var/app/staging/
    
    # debugging..
    ls -lah
    
    yarn install --prod
    
    chown -R webapp:webapp node_modules/ || true # allow to fail
    
    1. 一定要 chmod +x 这个文件(它必须是可执行的)

    https://gist.github.com/cooperka/0960c0652353923883db15b4b8fc8ba5#gistcomment-3390935

    【讨论】:

      【解决方案2】:

      这是我用来在 Beanstalk 上运行 Yarn 的:

      commands:
        01_install_node:
          command: |
            sudo curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash -
            sudo yum -y install nodejs
        02_install_yarn:
          test: '[ ! -f /usr/bin/yarn ] && echo "Yarn not found, installing..."'
          command: |
            sudo wget https://dl.yarnpkg.com/rpm/yarn.repo -O /etc/yum.repos.d/yarn.repo
            sudo yum -y install yarn
      
      container_commands:
        01_run_yarn:
          command: |
            yarn install
            yarn run encore production
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-05-12
        • 2014-10-15
        • 2014-09-15
        • 2017-03-26
        • 2013-07-08
        • 2017-07-31
        • 2020-09-11
        相关资源
        最近更新 更多