Deploy rails react app with webpacker gem on AWS elastic beanstalk

For those that run into needing to also install Yarn, I have found the below just worked for me:

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

For those of you who found this issue when upgrading to Rails 6, I wrote a post on how to fix it.

Basically, you have to:

  • Create directory .ebextensions in the top level of your application
  • Create .config file which contains the commands to fix deployments (script here)
    • Add commands for upgrading nodejs to >=6.14.4
    • Add container commands to install webpack & precompile assets
  • Disable asset building through elastic beanstalk
    • set set RAILS_SKIP_ASSET_COMPILATION to True

What that amounts to is:

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