How to set ci/cd for nodejs app with aws code deploy and aws code pipline
ssh -i <key.pem> ubuntu@<ip-address> -v
sudo apt-get update
sudo apt-get upgrade
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
).
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
nvm --version
nvm install --lts # Latest stable node js server version
node --version
npm -v
cd /home/ubuntu
git clone https://github.com/saasscaleup/nodejs-server-cicd.git
cd /home/ubuntu/nodejs-server-cicd
node app.js
npm install -g pm2 # may require sudo
sudo pm2 start app.js --name=nodejs-server
sudo pm2 save # saves the running processes
# if not saved, pm2 will forget
# the running apps on next boot
sudo pm2 startup # starts pm2 on computer boot
sudo ln -s "$(which node)" /sbin/node
sudo ln -s "$(which npm)" /sbin/npm
sudo ln -s "$(which pm2)" /sbin/pm2
sudo yum install -y ruby
wget https://aws-codedeploy-us-east-1.s3.amazonaws.com/releases/codedeploy-agent_1.0-1.1597_all.deb
mkdir codedeploy-agent_1.0-1.1597_ubuntu20
dpkg-deb -R codedeploy-agent_1.0-1.1597_all.deb codedeploy-agent_1.0-1.1597_ubuntu20
sed 's/2.0/2.7/' -i ./codedeploy-agent_1.0-1.1597_ubuntu20/DEBIAN/control
dpkg-deb -b codedeploy-agent_1.0-1.1597_ubuntu20
sudo dpkg -i codedeploy-agent_1.0-1.1597_ubuntu20.deb
sudo systemctl start codedeploy-agent
sudo systemctl enable codedeploy-agent
Watch the rest of the youtube video...