#3 Jenkinsfile to Build and Push Image onto DockerHub

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys welcome back in previous lectures we have seen how to set up jenkins master and slave configuration and how to run a maven build on the slave system in this lecture we are going to take a node.js application where we want to containerize and commit it into the hub.docker.com for this also we are going to set up a new slave system because it is dedicated to the only docker related builds we will take the node.js application and convert that into a darker image everything we are going to do with the jenkins file now let's see the what is the procedure we should follow before discussing further i would like to communicate about our upcoming devops page we could see that it industry is expecting more and more devops experts hopefully this could be the best time to switch your carrier on to devops why don't you grab this opportunity by taking the help of galaxy technologies we are starting a new devops batch from 21st february 2022. which means that upcoming monday if you are interested you can reach out to us through the mobile or whatsapp or through email we are happy to help you and let's jump back to our discussion so these are the steps we need to follow first thing is we need a node.js application which is already available in my github repository we need to create a docker file i have already created it it is very simple i will explain it then we need to create a jenkins file yes i have created it i will go through with the jenkins file so that even you can use in our environment if it is necessary then we need to install jenkins pipeline plugin on our jenkins master node anyway by default you are going to get it if not i will show you how to install it after that we are committing this onto the docker hub right so we need to create a docker hub credentials i will show you how to create a secure token on the docker hub and we are going to use that one at last we need to run our jenkins job on our slave system that is where we need a docker on our slave system all right for this i have already set up a new jenkins server i will quickly add that as a jenkins slave and we'll go through with these steps let's jump into our github repository this is my github repository that is node.js demo i am going to give this repo url in the description of this video please check it out and if you see here this is the node.js application let's go inside and we have few files and the test cases that's okay so this is the application we are going to use the node app to copy our application i will show you next docker file we are going to convert this as a darker image that is the reason we need a docker file let's open this one and see the instructions from node latest we are pulling the latest node image then work dir we are changing it to the default application location that is usr src app then we are copying our node app onto this location whatever we have seen right that test under some node app applications those we are copying inside to this location then we are installing the npm and npm runs on port number 3000 and we are starting the npm application that's it it is quite simple okay next thing jenkins file so this is the important file which we need to understand this entire jenkins file will help us to pull the application code build an image and we are going to log into our docker hub then commit an image once image is committed log out from the docker hub these are the instructions or stages we are going to follow as part of this jenkins file and you can see here first initially agent any is there any means it can run on any system but we want to restrict with the our new system which we are about to create it so for that one what i have done i have created a new docker build server and i have already logged in and to configure it first we need to install java right so i'm quickly installing java to reduce the time all right java installation is completed and we are going to use this as a docker build server so we need to install docker as well you have installed docker docker installation is completed in case if we are using base waste as a node.js application may be node.js we need to install it over here but we are converting as a container so there is no node.js packages are required over here and we need to start our docker service service docker status service docker start okay that's it we have set up required things to to build our docker applications now we need to add this one to agent to our jenkins server i will quickly do that one even you can check out our previous video how to set up a slave system on jenkins so quickly i'm going to do this is a docker server or docker node i'm going to give it is a permanent agent and we can copy the existing node i am just going to use the existing node it will copy the same configurations from there i am going to use the same build path and the label is i i'm not going to use the same label docker build node i'm going to give and let it be the defaults and save it now i just need to download it i will copy it and i will copy it onto our sorry sftp so drag and drop and let me pull the command mean time this is the command we should run and go back here it's still copying i can run this command from anywhere so i will just directly jump onto home slash easy to minus user okay if you are confusing about this please check out our previous lecture where i have shown you how to configure jenkins master and slave configuration i just want to show you how quick and easy it is okay i'm just running in the background that's it i made a docker server as a agent now i can run my jenkins job to run over here okay let's go back go to not notes go to dashboard and create a new item so here i'm going to name it as a docker build or docker job and this is your pipeline script right so pipeline select it and we need to scroll down and this is the jenkins file right so agent any we have done next thing environment variable i missed to explain about the darker credentials so we need to create a darker credentials why because as part of this jenkins job we are logging into our docker hub we can use our docker hub username and password which we are trying to use to log in over here or else the secure way is once you have logged into your account go to your account there account settings and here we have a security option here we need to generate the access token okay this is the secure way to generate i'm going to give it as a jenkins and let it be read write delete access with this access key token now you can see here you can run using this access key token just we need to run this one whenever it asks for password we need to give this one so username is galaxy and password is this one so just copy this one okay and go to our jenkins server before creating this job we need to add these credentials to our jenkins server okay for that i just opened new tab again manage jenkins and we need to go to manage credentials here we need to add our credentials okay we have already some existing credentials anyway i'm just going inside over here and global credentials add credentials and this is username and password don't go with the username with private key or a secret file okay so username is galaxyright and password we just copied and id whatever id we are giving same id we need to mention in our jenkins file over here okay so i am going to give the docker hub galaxy okay so i'm just giving this as a id and whatever id we give same id we need to update over here okay but anyway we haven't copied it yet so let me take this code and copy it over here now i will take the docker hub galaxy this is the one right id so same id i need to update it over here okay i have updated the credentials now we are taking the code from where we are taking this is the path right remedy node.js demo dot git then once we have taken it we are building the image so you can see here docker build minus t okay it might not be visible properly let me go here yeah so here you can see docker build minus t this is the tag we are using so velocity slash node app this is the image name and build number so whatever build number we are giving getting same build number we are using it as a variable all right next thing we are logging into docker hub while logging into docker hub we are using credentials you can see here echo docker hub credentials underscore pwd these are the docker hub credentials under this one we are only retrieving the password and we are logging with the username so here it is taking the username whatever is echoing over here that it is passing it as a password that's it once it is logged in we are going to commit this image so what is the image galaxy note app build number right same thing we are committing it over here and you can see here this is the docker hub right here we are going to get a new repository called node app and with the build number we will see the tag all right so that is what it is going to do i hope it is going to work fine apply and save it now let's build it sorry before building configure if we go and you can see here agent we have given any so it may run on any three systems that is either in the master node or any slave node why it runs on any slave node because while configuring our node system we mention it as a use as much as possible okay if you able to recollect it anyway let's go back and we'll build it and if it runs on only docker build node then only it is going to successful if it runs on any other system it is going to fail let's see that one build is started now yeah it's failed why it's failed we can see this logs okay this command is not working there is a reason where run docker socket this service might not be running okay let me see where it is running let me see the build output see here it is running on java node in java node there is no docker right service docker status okay docker is not there that is the reason it is failing but over here we have the docker right so service docker status okay it is running now i will just change the configuration so configure instead of any i'm going to use label docker build node okay this is the name right alright save now let's build it this time it should run on docker build node and it should be successful okay it's failed let's see the issue okay i think we should install git over here let me check m install git because it is trying to clone the code it is not happening yes to install now let me try to run it again build now as it is a fresh system that is the reason it didn't get the gate now you can see here it could able to clone the code now it is building an image and i will just forgot to show you darker images so no images are there once the build is successful we could able to see the image and even we can open the job yeah it is pulling the image all right you can see here it is successfully committed and if i go and check it out the images we can see the new image now i can check the same thing over in my github repository sorry docker hub repository let me refresh it we could able to see the latest image okay see here node app and it updated few seconds ago and if i open we need to see the tag it is three why because this is the third build so third build is successful even the tag also we got the node app three that is how it works so this tag will be keep updated based on the number of bills what we are doing alright that's all for this lecture hope this video is helpful if you like it please give a thumbs up and if you are new to our channel please watch our previous videos and consider to subscribe to our channel and if you feel that this video is helpful for your colleagues or friends or family members i would request you to share with them thank you and see you in next interesting video
Info
Channel: Valaxy Technologies
Views: 31,642
Rating: undefined out of 5
Keywords: aws, devops, valaxy technologies, security, automation, linux, jenkinsfile to build and push image onto dockerhub, create docker build using jenkinsfile, jenkins file to docker, jenkinsfile, jenkins master and slave architecture, jenkinsfile master and slave node, how to build image and push it into dockerhub using jenkinsfile, jenkinsjob for docker, jenkins ci job for docker, jenkins for begineers, arshankar devops, jenkins for devops, commit image onto dockerhub using jenkinsfile
Id: AgLn2xyFyTk
Channel Id: undefined
Length: 13min 59sec (839 seconds)
Published: Fri Feb 18 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.