somanaboina / nodejs-aws-codedeploy-pipeline

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

nodejs-aws-codedeploy-pipeline

How to set ci/cd for nodejs app with aws codeDeploy and aws codePipeline

Installation instructions

1. Launch amazon linux server in aws

2. ssh to linux to install packages

ssh -i <key.pem> ec2-user@<ip-address> -v

3. Update and Upgrade linux machine and install node, nvm and pm2

sudo yum update
sudo yum upgrade
sudo yum install -y git htop wget

3.1 install node

To install or update nvm, you should run the [install script][2]. To do that, you may either download and run the script manually, or use the following cURL or Wget command:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

Or

wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

Running either of the above commands downloads a script and runs it. The script clones the nvm repository to ~/.nvm, and attempts to add the source lines from the snippet below to the correct profile file (~/.bash_profile, ~/.zshrc, ~/.profile, or ~/.bashrc).

3.2 Copy & Past (each line separately)

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

3.3 Verify that nvm has been installed

nvm --version

3.4 Install node

nvm install --lts # Latest stable node js server version

3.5 Check nodejs installed

node --version

3.6 Check npm installed

npm -v

4. Clone nodejs-aws-codedeploy-pipeline repository

cd /home/ec2-user
git clone https://github.com/saasscaleup/nodejs-aws-codedeploy-pipeline.git

5. Run node app.js (Make sure everything working)

cd nodejs-aws-codedeploy-pipeline
npm install
node app.js

6. Install pm2

npm install -g pm2 # may require sudo

7. Set node, pm2 and npm available to root

sudo ln -s "$(which node)" /sbin/node
sudo ln -s "$(which npm)" /sbin/npm
sudo ln -s "$(which pm2)" /sbin/pm2

8 Starting the app as sudo (Run nodejs in background and when server restart)

sudo pm2 start app.js --name=nodejs-express-app
sudo pm2 save     # saves the running processes
                  # if not saved, pm2 will forget
                  # the running apps on next boot

8.1 IMPORTANT: If you want pm2 to start on system boot

sudo pm2 startup # starts pm2 on computer boot

9. Install aws code deploy agent

sudo yum install -y ruby 
wget https://aws-codedeploy-us-east-1.s3.us-east-1.amazonaws.com/latest/install
chmod +x ./install
sudo ./install auto
sudo service codedeploy-agent start

10. Continue in AWS console...

Watch the rest of the youtube video...

About


Languages

Language:JavaScript 54.5%Language:Shell 45.5%