Configuration details:
- EC2 instance name: todaysphere-app
- Docker node.js app image name : todaysphere_app
- Docker node.js app container name: todaysphereapp
- App URL format - http://EC2_INSTANCE_PUBLIC_IP_ADDRESS:3000
Deployment link - https://todaysphere-app.onrender.com
TodaySphere Node.js App which has completely automated deployment using Jenkins, AWS EC2, Docker and GitHub CI/CD. This app accepts location as an input from the user and based on that it shows the current weather, news for that location/region, an activity of the day which the user can perform and NASA's Astronomy Picture of the Day. A one-stop solution to start a good day! 😃
For the Devops part of this project, I created an AWS EC2 instance, installed Jenkins on the server, then integrated Jenkins with this GitHub repository containing Node.js app code. Next, using Docker, I dockerized the Node.js app and automated this process on Jenkins. Finally automated the whole process using GitHub Webhooks.
App Name: Today + Atmosphere(around you) - TodaySphere 😉
- Node.js
- AWS EC2
- Jenkins
- Docker
- GitHub Webhooks (for CI/CD)
- WeatherStack
- Mapbox
- NewsAPI.org
- NASA Open APIs
- Bored API
To get started with the project, follow these steps:
- AWS account
- GitHub account
Note:
-
Make sure to enable port 8080 inbound traffic while creating the EC2 instance
-
(with default settings) Login as "ubuntu" using putty with the .ppk file
-
Inside the EC2 instance (choose OS as Ubuntu)
sudo apt update
- Installing Java inside EC2 instance
sudo apt install openjdk-11-jre
java -version
- Installing Jenkins on EC2 instance
wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key |sudo gpg --dearmor -o /usr/share/keyrings/jenkins.gpg
sudo sh -c 'echo deb [signed-by=/usr/share/keyrings/jenkins.gpg] http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
curl -fsSL https://pkg.jenkins.io/debian-stable/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-stable binary/ | sudo tee \
/etc/apt/sources.list.d/jenkins.list > /dev/null
sudo apt update
sudo apt install jenkins
sudo systemctl start jenkins.service
sudo systemctl status jenkins
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
- After setting up Jenkins, use the following commands to integrate it with GitHub
ssh-keygen
cat id_rsa.pub
cat id_rsa
- Running the Node.js app on EC2 instance
cd /var/lib/jenkins/workspace/todaysphere-app
sudo apt install nodejs
sudo apt install npm
sudo npm install
node app.js
- Installing Docker and Containerizing the Node.js app
sudo apt install docker.io
sudo chmod 777 /var/run/docker.sock
sudo docker build . -t todaysphere_app
sudo docker run -d --name todaysphereapp -p 3000:3000 todaysphere_app:latest
- Jenkins Build step (execute shell)
docker build . -t todaysphere_app
docker container rm -f todaysphereapp
docker run -d --name todaysphereapp -p 3000:3000 todaysphere_app:latest
- Optional - To open access to ports/firewall modification (incase 8080 port does not open)
sudo ufw allow OpenSSH
sudo ufw enable
sudo ufw allow 8080
sudo ufw status