Table of contents
step 1: Launch an instance and connect it through ssh.
step 2: clone the Repo in your terminal.
step 3: Change the directory and list the contents
step 4: Now install docker and check the version
step 5: Now add your current user to the docker group and reboot it
connect your instance again:)
step 6: After connecting, let's run the docker build command to automate everything present in this directory.
step 7: Once this is done, let's install Jenkins and continue our project in Jenkinsπ
Within this step we have certain sub-steps to install Jenkins, let's see those...
step 1: Install Java and check the version.
step 2: Install Jenkins and check the version
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-get update sudo apt-get install jenkins
step 8: As we can see in our DockerFile, we have given the destination port as 8000, now edit your inbound rules and enable 8000 port to access Jenkins.
step 9: Now copy your public IP address and paste it into the browser followed by your port number.
step 10: Now copy the path and paste into the terminal, and copy the hidden password and paste it into the browser.
step 11: Install suggested plugins.
step 12: Now fill in the details-->Save and Continue-->Save and Finish
step 13: Our Jenkins is now ready.
step 14: click on Create a job-->Enter the item name-->Select pipeline & press ok.
step 15: Give a simple description select GitHub and paste the below URL
here...
step 16: Select pipeline --> Type pipeline code--> press save.
step 17: Click on Build Now.
Now u can see something like this...
Now click #1
step 18: Now goto configure to edit the code.
copy the HTTPS link from Git and also check the branch...
And paste it here, in your code block.
- Now add
build command
in your build block.
After certain changes save --> Build Now.
Don't worry if you get the errors :)
yes, we got the colourful errorππ
now click on #2 and check the error.
So currently our Jenkins is running in this location.
And our error is...
now let's give permissions to the user.
Open terminal--> Add USER to docker group.copy the path where Jenkins is running--> paste in Terminal--> Add permission for the user-->and reboot the system as shown below.
Now reconnect with AWS instance--> login with your Jenkins account-->press build now again...
#3 build was successfull...
step 19: Now build is done, let's push it.
Before that make an account on Docker Hub, or sign in through it.
so this is my docker hub : )
Hence to push the image in Docker Hub, we need to login.
Type docker login
in your terminal.
Before editing the code in configure, let's create environment variables to safegaurd our credentials :)
Goto Dashboard--> click on Manage Jenkins--> Credentials.
Now click on system's-->Global Credentials.
Now click on add credentials.
Select username and password--> fill in the details--> click on create.
Now our credentials are added.
Goto configure in Jenkins-->edit the code in push to docker hub block-->save + Build Now.
Our next build is also successfull.
step 20: Now let's push our image to Docker Hub.
Goto configure --> edit the code as shown below in push block--> press build now.
Build successfully.
Now goto Docker Hub, refresh and check for your image.
we can see my-note-app image in our docker hub now!
step 21: Now let's deploy it.
Goto docker hub, copy the image name shown in docker push cmd.
Now goto configure and edit the code as shown below in Deploy block.
Now enable the 8000 port in your inbound rules.
Now go and press build now in Jenkins.
Now copy your public IP and paste it in the browser followed by your port number.
Our app is deployed successfully through Declarative Pipeline!!!!
But when you try to build it again, it will not deploy, as the 8000 port will be busy.
Hence to overcome this, we need docker-compose, which brings down the running thing's and runs it freshly again...
Now Goto your terminal and install docker-compose.
Run
docker ps
command to see the running containers and kill that container usingdocker kill <container-id>
command.Run
docker-compose up -d
cmd & rundocker ps
cmd to see the container running again :)Now goto configure in Jenkins & change the code of Deploy block as show below & press build now.
Now copy your public IP and paste it in the browser followed by the port number.
SCM
Now let's try with the SCM(source code management) where we get our pipeline code directly from Github itself. let's try...
step 1: Now goto configure and change from pipeline to SCM.
step 2: Fill in the fields with proper URL and specify the branch name properly.
Now save and build...
Finally, we learnt about Declarative pipeline and SCM process.
I think SCM is much easier than pipelineπππ jokes apart, If this blog made you gain at least 1% knowledge, do share it with your friends :)
Thank you so much for reading :)
Thanks, Shubham Londhe sir for this amazing project :)