Skip to content

Instantly share code, notes, and snippets.

@darahayes
Forked from moshest/appspec.yml
Created March 24, 2017 14:42
Show Gist options
  • Save darahayes/df0a1a6199fcc2e11ed66eeb5a1ec322 to your computer and use it in GitHub Desktop.
Save darahayes/df0a1a6199fcc2e11ed66eeb5a1ec322 to your computer and use it in GitHub Desktop.
Node.js Project on AWS CodeDeploy CentOS
version: 0.0
os: linux
files:
- source: /
destination: /home/ec2-user/node
permissions:
- object: /home/ec2-user
owner: ec2-user
group: ec2-user
type:
- directory
- file
hooks:
BeforeInstall:
- location: install.sh
timeout: 300
runas: root
AfterInstall:
- location: post_install.sh
timeout: 600
runas: ec2-user
ApplicationStart:
- location: run.sh
timeout: 120
runas: ec2-user
ApplicationStop:
- location: stop.sh
timeout: 120
runas: ec2-user
ValidateService:
- location: validate.sh
timeout: 60
runas: ec2-user
#!/usr/bin/env bash
set -e
# update instance
yum -y update
# install general libraries like Java or ImageMagick
yum -y install default-jre ImageMagick
# add nodejs to yum
curl --silent --location https://rpm.nodesource.com/setup_4.x | bash -
yum -y install nodejs #default-jre ImageMagick
# install pm2 module globaly
npm install -g pm2
pm2 update
#!/usr/bin/env bash
set -e
cd ~/node
npm install
# setup NODE_ENV
if [ ! -z "$DEPLOYMENT_GROUP_NAME" ]; then
export NODE_ENV=$DEPLOYMENT_GROUP_NAME
hasEnv=`grep "export NODE_ENV" ~/.bash_profile | cat`
if [ -z "$hasEnv" ]; then
echo "export NODE_ENV=$DEPLOYMENT_GROUP_NAME" >> ~/.bash_profile
else
sed -i "/export NODE_ENV=\b/c\export NODE_ENV=$DEPLOYMENT_GROUP_NAME" ~/.bash_profile
fi
fi
# add node to startup
hasRc=`grep "su -l $USER" /etc/rc.d/rc.local | cat`
if [ -z "$hasRc" ]; then
sudo sh -c "echo 'su -l $USER -c \"cd ~/node;sh ./run.sh\"' >> /etc/rc.d/rc.local"
fi
#!/usr/bin/env bash
if [ ! -z "$DEPLOYMENT_GROUP_NAME" ]; then
export NODE_ENV=$DEPLOYMENT_GROUP_NAME
fi
cd ~/node
pm2 start bin/www -n www -i 0
#!/usr/bin/env bash
cd ~/node
pm2 stop www || true
#!/usr/bin/env bash
sleep 10
nc -zv 127.0.0.1 3000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment