Day 30 - Deploying node js application on AWS EC2 using Jenkins, GitHub and Docker

Day 30 - Deploying node js application on AWS EC2 using Jenkins, GitHub and Docker

ยท

2 min read

Install Jenkins on Instance

Install Java

COPY

sudo apt update
sudo apt install openjdk-11-jre

Verify Java is Installed

COPY

java -version

Now, you can proceed with installing Jenkins

COPY

curl -fsSL https://pkg.jenkins.io/debian/jenkins.io-2023.key | sudo tee \
  /usr/share/keyrings/jenkins-keyring.asc > /dev/null
echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
  https://pkg.jenkins.io/debian binary/ | sudo tee \
  /etc/apt/sources.list.d/jenkins.list > /dev/null
sudo apt-get update
sudo apt-get install jenkins

By default, Jenkins will not be accessible to the external world due to the inbound traffic restriction by AWS. Open port 8080 in the inbound traffic rules as show below.

  • EC2 > Click on your Instance

  • In the bottom tabs -> Click on Security

  • Click on link below, Security groups -> Edit Inbound rules

  • Add inbound traffic rules, you can just allow TCP 8080 as well, I have allowed All Traffic

Login to Jenkins using the below URL:

  • public_ip_of_instance:8080

  • After you login to Jenkins, run the command to copy the Jenkins Admin Password - sudo cat /var/lib/jenkins/secrets/initialAdminPassword - Enter the Administrator password

  • Install Suggested Plugins

  • Create Admin User

  • If required customize your URL and Save or Save and Finish as it is

Install node js on ubuntu instance

Install node packet manager also

sudo apt-get update

sudo apt-get install npm

Install Docker on Instance

sudo apt-get update

sudo apt-get install docker.io

On jenkins create a job

and provide github url

github.com/AnushaaNayak/nodejs-on-ec2

Configure ssh keys on github and jenkins

Click on Build now

Check on server that code has been cloned from github

Allow port 4000 to run

Write a Dockerfile

docker build . -t node-app

Note: IP of server might be changed if server rebooted

When docker image is killed application is not accessible

Now Include Webhook in pipeline

Wait for webhook to be green

Install github integration plugin on jenkins

Make some changes in Github

Yaaay!!!!! We did it!๐ŸŽ‰

๐Ÿ™Œ Thank you for taking the time to explore this blog!๐Ÿ“š I hope you found the information both helpful and insightful.โœจ

๐Ÿš€ Enjoy your learning journey, and don't hesitate to reach out if you have any feedback. ๐Ÿค“ Happy exploring!

ย