Skip to content

Instantly share code, notes, and snippets.

@bhalash
Forked from sealocal/yarn.config
Last active October 17, 2017 16:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bhalash/76910f52b089de0466a9627b09d2b648 to your computer and use it in GitHub Desktop.
Save bhalash/76910f52b089de0466a9627b09d2b648 to your computer and use it in GitHub Desktop.
Install Yarn and NodeJS on AWS Elastic Beanstalk EC2 Instance with Amazon Linux Ruby Platform, prior to precompiling assets for a Rails app
# vim: set ft=yaml:
# @see https://gist.github.com/sealocal/0cd468ba4f12cdada436aebe534b40da
---
files:
'/opt/elasticbeanstalk/hooks/appdeploy/pre/09_yarn_install.sh':
mode: '000775'
owner: root
group: users
content: |
#!/bin/bash
EB_APP_STAGING_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k app_staging_dir)
EB_APP_USER=$(/opt/elasticbeanstalk/bin/get-config container -k app_user)
if [[ $(which yarn 2>&1 > /dev/null) != 0 ]]; then
# Consider that the EC2 instance is managed by AWS Elastic Beanstalk.
# Changes made via SSH WILL BE LOST if the instance is replaced by auto-scaling.
# QUESTION: Will this script be run on new instances that are created by auto-scaling?
# QUESTION: Should installation be moved to a rake task?
sudo wget https://dl.yarnpkg.com/rpm/yarn.repo -O /etc/yum.repos.d/yarn.repo
file /etc/yum.repos.d/yarn.repo
if [[ $(node --version) != 'v6.10.0' ]]; then
# Download the Node v6 setup script
curl --location https://rpm.nodesource.com/setup_6.x > /home/ec2-user/node_install.sh
# Confirm that it downloaded
file /home/ec2-user/node_install.sh
# Run the Node v6 setup script
sudo bash /home/ec2-user/node_install.sh
# Install nodejs
sudo yum install -y nodejs
node --version
fi
# install yarn
sudo yum install -y yarn
yarn --version
fi
cd $EB_APP_STAGING_DIR
yarn install
commands:
01_remove_old_yarn_script:
command: 'rm -f /opt/elasticbeanstalk/hooks/appdeploy/pre/*yarn*.bak'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment