- Jenkins project - 2 (deploy node js app on server)
Step 1 : In this step we have to create aws ec2 instance.
Step 2 : Install Jenkins.
Pre-Requisites:
- Java (JDK)
Run the below commands to install Java and Jenkins
Install Java
sudo apt update
sudo apt install openjdk-11-jre
Verify Java is Installed
java -version
Now, you can proceed with installing Jenkins
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
Note: 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 > Instances > Click on
In the bottom tabs -> Click on Security
Security groups
Add inbound traffic rules as shown in the image (you can just allow TCP 8080 as well, in my case, I allowed
All traffic
).
Step 3 : Login to Jenkins using the below URL:
http://:8080 [You can get the ec2-instance-public-ip-address from your AWS EC2 console page]
Note: If you are not interested in allowing All Traffic
to your EC2 instance 1. Delete the inbound traffic rule for your instance 2. Edit the inbound traffic rule to only allow custom TCP port 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.
Click on Install suggested plugins
Step 4 : click on create job
click on save.....
Step 5 : click on build now.
Step 6 :
Step 7 : click on build now and you will get error .
Step 8 : Docker Slave Configuration
Run the below command to Install Docker
sudo apt update
sudo apt install docker.io
Step 9 : Grant Jenkins user and Ubuntu user permission to docker deamon.
sudo usermod -aG docker jenkins
sudo reboot
Step 10 : Know build again ....
Step 11 :
Step 12 : You need to add port 8001 into your aws security group.
Step 13 : finally your to do app is running on port 8001:
<your public ip address>:8001
Step 14 : You need to install docker-compose on your server.
sudo apt install docker-compose
Note : Before building docker compose container you need to stop previous conainer using below command .
sudo docker ps
sudo docker kill <id>
click on Build again ....
Note : How to run docker container again with docker-compose
docker-compose up -d --no-deps --build web
Project : In this project we deploy node to to app
Step 15 : You need to add custom tcp port 8080 and source anywhere.