Skip to content

Instantly share code, notes, and snippets.

@stanleycyang
Last active November 5, 2016 13:32
Show Gist options
  • Save stanleycyang/f46492850ff42f2ce6e1 to your computer and use it in GitHub Desktop.
Save stanleycyang/f46492850ff42f2ce6e1 to your computer and use it in GitHub Desktop.
Faster Elastic Beanstalk deployment (NodeJS 4.2.1)
#!/bin/bash
# Include envs
. /opt/elasticbeanstalk/env.vars
function error_exit
{
eventHelper.py --msg "$1" --severity ERROR
exit $2
}
#make sure node binaries can be found globally
if [ ! -L /usr/bin/node ]; then
ln -s /opt/elasticbeanstalk/node-install/node-v$NODE_VER-linux-$ARCH/bin/node /usr/bin/node
fi
if [ ! -L /usr/bin/npm ]; then
ln -s /opt/elasticbeanstalk/node-install/node-v$NODE_VER-linux-$ARCH/bin/npm /usr/bin/npm
fi
if [ ! -f "/opt/elasticbeanstalk/node-install/npm_updated" ]; then
/opt/elasticbeanstalk/node-install/node-v$NODE_VER-linux-$ARCH/bin/npm install npm@$NPM_VER -g
touch /opt/elasticbeanstalk/node-install/npm_updated
echo "YAY! Updated global NPM version to `npm -v`"
else
echo "Skipping NPM -g version update. To update, please uncomment 40install_node.sh:12"
fi
#!/bin/bash
. /opt/elasticbeanstalk/env.vars
function error_exit
{
eventHelper.py --msg "$1" --severity ERROR
exit $2
}
#install not-installed yet app node_modules
if [ ! -d "/var/node_modules" ]; then
mkdir /var/node_modules ;
fi
if [ -d /tmp/deployment/application ]; then
ln -s /var/node_modules /tmp/deployment/application/
fi
OUT=$([ -d "/tmp/deployment/application" ] && cd /tmp/deployment/application && /opt/elasticbeanstalk/node-install/node-v$NODE_VER-linux-$ARCH/bin/npm install --silent --production 2>&1) || error_exit "Failed to run npm install. $OUT" $?
echo $OUT
export HOME=/root
export NPM_CONFIG_LOGLEVEL=error
export NPM_CONFIG_PRODUCTION=true
export NPM_VER=3.10.5
export NODE_VER=6.2.2
export ARCH=x64
export PATH="$PATH:/opt/elasticbeanstalk/node-install/node-v$NODE_VER-linux-$ARCH/bin/:/root/.npm"
export NODE_PATH=/usr/bin/node
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment