GitLab CI CD Tutorial For Beginners | Continuous Deployment of Node JS app with GitLab CI

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] so [Music] hello friends welcome back to my channel and today we are back with another exciting tutorial on gitlab ci cd so this will be a continuation of our gitlab cacd tutorial for beginners so if you have seen my previous tutorial we have gone through multiple lectures on gitlab ci cd like how to who knows set up runners how to build the gitlab you know pipeline to build your image and push it to gitlab container registry so this will be a continuation of that and in this tutorial what we will see is like you know how to set up your gitlab ci cd pipeline for a node.js application so when we talk about ci cd pipeline it should it will be end-to-end pipeline starting from how to build your application test it release it and then even for the deployment into actual production environment so that would be our complete uh pipeline for this so uh let's discuss on a pictorial way like how our pipeline would look like okay so for example if you're a developer you will have your code you know put it into your gitlab so we will show you like a sample node.js project which i'll be putting into the gitlab you know our repository and from gitlab you know we will use our ci cd pipeline so whenever you make a changes in your application it will uh build your pipeline so we will write the complete pipeline code so i will show you and i will share that as well in the link so you can download that and you know what we will do like we already seen in our previous tutorial how to build our image using docker build command right so we'll be using a gitlab runner for that and basically it's it's going to be not js application and we are going to use a docker in docker concept which we already discussed and how that will make use of you know uh the docker in docker concept to build your image and pushing into the container registry so we'll push that into the gitlab container registry so till this point you already aware in our previous tutorial so what we will do from here is like we will have a test so we will test our node.js application so we create the image so we will once we create the image we will test our node.js applications so once we test it if it passed the test then we will deploy our application to our docker container so that means using our image we will run our application as a container so these are all will be uh you know a pipeline script so once you click uh or make some changes in your code this will automatically happen and your application will be running as a no docker container so we will see all those things so let's discuss little bit more like what would be the each individual step which will be doing it in as part of our continuous deployment of our node.js application so what as i said what we will do is first we will have a node.js application in our gitlab repository so we will commit that so i already have it so i will show you so you can make use of your application for that and we will build the docker image for your node.js application and you know once we build it we will push the docker image to your gitlab container registry and this image we will mark it as a test image okay so it's not the actual uh release image so we can name it something test or some uh you know variables then we will mark this image as a test image then we will run a test on the node.js application using this test image if the image you know uh this application is passing the test then we will rename or you know we will tag the test image as a release image and push that into the container registry again so then we'll have two images one for test and once the release because once the test is passed then that will convert into a release image so once we have the release image means like we have a standard or application which can be deployed into your i know uh production environment then we will use uh docker commands to deploy our application as a docker container using this release image so that we'll have four stages in our pipeline one will be for build one will be for test and one will be for release and one for deploy so there will be four stages and there will be four jobs running so i'll show you the complete pipeline script how to write that and i will also share that so you can make use of that and once we deploy it we i'll show you like where the container uh the container will be running because we'll have our own uh server running for running this container and rest of other action we will use our shared runner for that so before i get into the actual demo of the process i would request you like if you're new to my channel or if you haven't clicked on the subscribe button please click on the subscribe button also click on the bell icon so also like my video share and comment so let's get started so if you see i have a node.js application so if you see the index.js it's pretty simple there are two routes one for slash build so there is no home page which i have put so it's uh if you go to your application and slash well you get a response like response hello world and if it's good slash ready it should be like this and it's running on the port uh 3000 and if you see there is also uh one uh test uh running so because if you see i have a test.js and that will check the test so you know it's using uh super test and the mocha so uh it's all defined in our package.json so if you see the package.json you have a npm start for index.js and npm test for running this test.js file right so that's how the whole uh configuration is there and you can also check the docker file we also have a docker file now if you see the docker file you know this also we have discussed in our pre a lot of tutorials like how to write your docker file for your node.js so you have a base image and we are copying uh making the default directory and we are copying the package.json to this file and we are installing the npm and we are copying the rest of the other files and then we are exposing the port and we are starting the index.js so that's the overall uh npm file and docker file as well so if you don't know you have to check my previous tutorial on that so that's the overall uh you know uh application what we have it and we have this gitlab.yaml file so before that let me show you uh let me show you the we have to one runner set up so if you see there is a runner which is active this runner we will use it for running our docker container rest of things we'll have in our shared runners okay so that's how it will be so now this is the machine which i have set up as a runner and if you see uh docker psiphon hey i don't have any containers running so the deployment will happen on this machine so once we run the whole pipeline the deployment will have a container running and we should be able to access our application using the ip address or the host name for this machine okay so let's talk about the whole cicd pipeline dot yaml file which will use it in the gitlab so where we'll have this dot gitlab dot uh cca hyphen ci dot ml file okay so what we will do is like let's go through the end to end process so you can write you know you or use the same method to build your and deploy your application so now if you see we are starting with the base image which is a docker image this is because we are using docker in docker concept and we are defining the service right and as i said we have four stages one for build one for test and one for release and one for deploy and we are setting this variable so we are using a test image as i told like we'll have two image one for test and one for release so the test image we are using the variable like uh container registry name and tag you know commit reference slack and if you see the release image we are using the same container registry image and the s so that's how we will use it uh you know as variable if you want to use a different variable that's also fine okay but this is a default variable from uh gitlab which will use the registry uh no values for for that and we already spoke about these uh variables for example uh we spoke about like uh to log into your gitlab container registry you need to have a user id and password for authentication right so rather than using a hardcore password we are using the registry uh variables right for the container registry variable this is the ca register user and password and this year registry and this will be you know created uh you know in every job so you don't have to uh make an order of this because this will takes default from your job so um we spoke about different ways you can do it so this is one of the way you can write your script so why we are giving this before script means this is happens on before every job so otherwise if you want to run it within job you'll have to put it inside the job now if you see the first job is for us is built and we are also defining the stage as built okay so this stage comes from here which stage it is and the script uh is like we are going to build our application so we are going to build and we are going to name it as a test image and we are using the docker file from our source location and we are going to push the test image using docker push right so we can see this docker push contain so this will be pushing our image to our gitlab container registry for this uh uh project so now once this is done we are going to test our application so we are going to use a job as test you can name it anything but uh no just i'm using test and the stage will be test and you know uh the commands what we have to do is now we have to make use of this test image so i'm going to pull this uh test image then i'm going to run the command docker run and the image and i'm going to call the variables which is our argument so i'm going to use npm test because this i already defined in my application what npm test will do right we have i have already shown you like there is a test.js file and we already defined the what test inside the package.json right so if this is passing uh this test face then it will go to release image so i'm going to call this job as release image and i'm going to put it under the stage release and in this stage what we will do is we will pull the test image and we are going to tag it as you know release image because now it has passed the test if he has failed the test it will stop brush stop it there itself now we are going to you know rename or tag the test image as a release image and then we're going to push it to the container registry again so now we'll have a release image available in the container registry which is ready for deploy and in the deployment job we i'm going to put it on the stage deploy and i'm going to give the tag because my gitlab runner or the local server which is uh tagged on the local docker where we will be running this commands to in run our application so if you have given a different tags you can use that okay because if you run the shared runners we will not be able to get our application we'll it will finish this job but you know to access our application i'm using my local server now here you know what we are going to do is we are going to pull the our release image and i'm going to run the docker run command uh with the hyphen d detached mode and uh hyphen p where which is the port which i'm mapping into the port 3000 for application from the host and also from the uh image now uh you know the container image which i'm going to use is the release image which is already tested and pushed into our gitlab registry so this is the overall process so it'll be four stages where we are going to run our applications now if i go back to my you know gitlab project now if you see i already run it once and i have four stages all are passed okay so now let me run it again so let me go back to the editor so i don't have any changes to be done so i will go just from the pipeline again so now we can see the pipeline has started so it's starting with the build face so if you go to the build you should be able to see what it does it's using the docker in docker uh image right so it uses that concept the whole process makes some time depending upon the image it has to pull because if you see it's pulling and building our image you can see you know it is pulling the image and it's uh logging into the container registry then it's building our image then it will be pushed so you can see it's doing the whole process uh step by step so it may take some time based on how much times it takes you know to build the image and pushing into the container registry now you can see this job has succeeded and it has pushed the you know image the docker container registry so let me go back to the pipeline let's see it's running it's running the second stage now so we can go to the test and it will use the image which we pushed the container registry to run that test as you can see the npm test has been also job succeeded so what it has done it is has pulled the test image and it has run the docker run npm test so let's go back to our pipeline and we have our third stage running so which should be for release image so let's go back and check that as you can see the third stage is also succeeded so what it has done is it has retagged the test image as release image and it has pushed to the container registry so let's go back to our final stage which should be on deploying it so that should be our final stage where it has to deploy our application so now we can see it's going to run it on our machine so you can see that is also succeeded so you can see whole uh process is done and let me go back to this machine so if i go back to docker hyphen ps yep now you can see we have our email container running and if i go back to docker images you should be able to see our latest image over here just four minutes ago right so our container is also running uh of our application so what we can do is we just need to access this machine uh access this application using our ip address and the port 3000 so let me use this ip address and let me go to a browser if i if i go to the ip address with the port 3000 and slash wheel you can see the response we are getting hello world right and we have one more route which is uh slash ready and if i go if you see we are getting uh it works so our application is running fine now and because we it's running it as a docker container now right so you can see docker hyphen ps it's running using our image which we deployed into our application uh docker container registry so that's the overall uh csd deployment process so if you see the uh pipeline file which we have created it's not that complicated it's pretty simple but you need to understand the concept what we have done so how to build your image how to push that to container registry how to test your application then if you want to build it as a release image and then how to deploy it as a docker container so this is the way we are doing uh as a docker container if you want to know like how to build your application without as a docker that is also possible you can test your application you can then copy the contents into a you know a server and then you can run it uh from there as well so that is also possible if you want that to be you know created as a video i will do that as well you can give your feedback on the video or in the youtube so you can give a comment section you can give your request then i can create a video based on that as well since most of our application now running as a docker i thought this will be helpful for you guys so that's all for this tutorial so if you want to get all this information check out my video tutorials and also i will link my github into the video link so you can refer the code there and the ci cd pipeline that as well so for watching more videos like this i hope i know i hope you'll be interested to watch that so i would request you to subscribe for more videos and also support me by giving your feedback and also liking my videos and sharing with others okay so thank you for watching [Music] you
Info
Channel: Thetips4you
Views: 3,537
Rating: undefined out of 5
Keywords: gitlab ci cd nodejs, node js ci cd pipeline, nodejs pipeline, node js deployment, full node js deployment, deployment of node js application, node js project deployment, node js production deployment, node js deployment with nginx, node js express deployment, gitlab ci node js, gitlab, cicd, ci cd, node, node js, thetips4you, how to, howto, create, tutorial, deployment
Id: j1cj5oK8t6c
Channel Id: undefined
Length: 18min 15sec (1095 seconds)
Published: Mon Oct 18 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.