繁体   English   中英

在 AWS 弹性 beantalk 上使用 webpacker gem 部署 rails react 应用程序

[英]Deploy rails react app with webpacker gem on AWS elastic beanstalk

我正在尝试使用 AWS Elastic Beanstalk 部署使用 webpacker gem 创建的 rails 5.1 和 react 应用程序。 问题是我不断收到以下错误:

Webpacker requires Node.js >= 6.0.0 and you are using 4.6.0

我在我的电脑上使用 Node 9.5.0。 有什么建议吗??

对于那些还需要安装 Yarn 的人,我发现以下内容对我有用:

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"
  02_download_nodejs:
    command: curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash -
  03_install_nodejs:
    command: yum -y install nodejs

使用 yum 安装 nodejs(假设您使用的是默认的 Amazon Linux)

https://nodejs.org/en/download/package-manager/#enterprise-linux-and-fedora

curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash -
yum -y install nodejs

现在要在您的实例上执行此操作,您需要将所需的命令添加到.ebextensions目录中的配置文件中,例如: .ebextensions/01_install_dependencies.config

文件内容:

commands:
  01_download_nodejs:
    command: curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash -
  02_install_nodejs:
    command: yum -y install nodejs

对于那些在升级到 Rails 6 时发现这个问题的人,我写了一篇关于如何修复它的帖子

基本上,您必须:

  • 在应用程序的顶层创建目录 .ebextensions
  • 创建 .config 文件,其中包含修复部署的命令(此处为脚本)
    • 添加将 nodejs 升级到 >=6.14.4 的命令
    • 添加容器命令以安装 webpack 和预编译资产
  • 通过弹性豆茎禁用资产构建
    • 将 RAILS_SKIP_ASSET_COMPILATION 设置为 True

这相当于:

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"
  02_download_nodejs:
    command: curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash -
  03_install_nodejs:
    command: yum -y install nodejs

container_commands:

  04_install_webpack:
    command: npm install --save-dev webpack
  05_precompile:
    command: bundle exec rake assets:precompile

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM