Setup CI/CD on AWS for NestJS(NodeJS)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in today's video you will learn how to set up CI CD on AWS for your nest.js project so let's get started [Music] before we dive into the technical details it is crucial to emphasize the significance of cicd in modern software development workflows CI CD enables you to automate the process of building testing and deploying your code reducing errors enhancing collaboration and accelerating your software delivery process to implement the ICD for an sjs projects we will Leverage The Power of AWS code pipeline code build and elastic Beanstalk these Services work seamlessly together to create a streamlined deployment pipeline keep in mind that the steps mentioned here also works for other node.js projects that don't use nest.js but in this case you have to adapt the code build script for the specific library or framework that you're using so how this project is going to work you as a developer you write the code on your computer using your favorite IDE like vs code for example and once you write the code you push the code to GitHub and once the code reaches on GitHub AWS code pipeline listens to this push event and then it starts the execution and once the AWS code pipeline starts the execution it reads the code from GitHub and sends the code to code build so code build is responsible to install the node modules packages that we have in our project and since we're using typescript it also converts typescript to JavaScript and besides this code build will be also responsible to run the tests that we have in our project and if if everything succeeds the AWS code build generates the final artifact which is the JavaScript code which was generated from the stall and build process and then code build sends this final artifact to elastic Beanstalk and that's pretty much it now that we know how the project is going to work let's dive into the configuration for it before we proceed if you like this kind of content just give me a thumbs up share this video with your friends and subscribe to the channel so we can learn more more about nest.js and AWS and don't forget about it the more you learn the better you'll become and more value you can provide so let's do this okay great so the first thing that I'm going to do is to create the elastic Beanstalk project if you can't see your last a big stock here just search here on the search bar for elastic Beanstalk okay great so the first thing you don't need to do on the elastic B stock console is to create the application so we click here then in this case actually we're going to create the environment directly so it's going to be a web server so I'm going to call this npcsj test cicd object it's up to you to define the name for the application and the environment and then for the platform is going to be node.js using node.js 18 and the platform version the latest one recommended by AWS so for the preset I'm going to use the default SQL instance here but if we prefer you can customize your your environment I'm going to keep the default one to make it more simple then I click on next for the the service rule I'm going to use the default one then click on next I'm going to keep on the default VPC so I'm not going to change this next default container I'm not going to change the security groups I'm going to keep it as a single instance to make it more simple but if you prefer you can use a load balanced environment for the architecture I'm gonna use a T3 micro so I'm gonna attach another Link in the description for you for website so you can see the capacity for each instance which is this one foreign [Music] so here you can see many different kinds of easy choices so you can filter here for the instance type so you can see the specifications for it how many virtual CPUs how many how many gigabytes per CPU of ram per CPU and so on I'm gonna attach the link in the description for you so you can see the specifications for every type of ec2 instance so in this case I'm going to use a T3 micro and next for the monitoring I'm going to I'm going to use a basic one and I'm also going to disable the managed updates before production environments I highly recommend to you to use the enhanced mode and the the manage platform updates and that's it and then we just click on next so here we can review the whole process the whole application environment that we are creating and then we click to submit and that's it in a few minutes we're gonna have our last day Beanstalk environment which is which we're going to use to deploy our application [Music] okay great now that we have our elastic Beanstalk environment let's set up code Pipeline and code build so I'm gonna search here for code pipeline click here and then let's create our pipeline project so I'm going to create here click here to create a new pipeline so I'm gonna call this um test nest.js project pipeline and then you click on next and then here we need to select the source provider which is where called pipeline will read the code since we're going to use GitHub in our case then I'm going to select here GitHub so let me show to you the project that we're going to use so in my case this is the project that we're going to use this is the stable diffusion sjs integration which is on GitHub so I need to select GitHub version 2 do not use version one use version 2 and then here you need to set up a connection with GitHub if you already have a connection then it will show up here in the list if you don't have a connection you need to click to connect to GitHub and then you need to set up a new connection so I'm gonna say I'm gonna call this GitHub connection one it's up to you then click to connect to GitHub and then we authorize AWS to access our GitHub account and then that you set up here the GitHub apps and then click to connect okay perfect so called pipeline so if you select here now code pipeline is already using the connection that we just created and here code pipeline can see all my projects on GitHub so this is the stable diffusion sjs integration oh sorry let me put this here by the way if you want to see how to set up nest.js and stable diffusion create and rest API I'm gonna attach the video link for you so you can check it out so let's keep going the branch name is going to be the main so if you want the code pipeline to start whenever push the code to the main range so keep this flag activated and that's it so this is the step just to connect code pipeline to our project and then to the branch that we desire to use and then you click on next now I need to set up a build provider so code pipeline allows two options called build or Jenkins but in our case I'm going to use code build so I click here if you don't have a good good project then you click here to create a new project I'm gonna say that this is the The Nest JS cicd project and then for the environment I'm going to use the Amazon Linux 2. the default is standard runtime and the image so since our project is using an x86 machine so we're going to use an x86 version so I'm going to use this one x86 64 Standard Version 5. if you're using a r machine then you need to use the this ar64 one of these two options so both my KCC series x86 that I'm gonna use this one it's a Linux environment I'm going to enable enable this for elevated privileges for sudo commands foreign you can pass the path for the file or you can select you can insert it here directly so here we need to specify our commands so the first thing that I'm going to do here on the phases on the install phase I'm going to enable this and then for the runtime version I'm going to use the node.js 18. so if we go here code build [Music] runtimes versions I'm going to attach the link for this page as well so you can see the available runtime versions for code build in our case we're going to use node.js version 18. so I'm gonna copy this and then paste it here perfect and then for the commands on the install phase we're going to do I'm going to install because I need to set up the machine so I'm going to install using npm I minus G I'm going to pass yarn yarn I'm also going to pass typescript and I'm also going to pass the nest.js CLI so depending on your library or framework they're using for node.js then the commands either need to stop might be different so here we are installing these libraries on the machine to build the application [Music] and then for the actual build what we need to pass here so I'm gonna pass just yarn to start the node modules packages and then we run yarn pre-build and then yarn build so we can check here on vs code this is this is the project that we're going to use so what I'm doing here the first command is to install the packages the node modules and then we run the pre-build for an sjs [Music] which is this command here and then we run the build and that's it after this we're gonna have the dist folder and the little modules on the machine [Music] for post build what we need to do is we want to test the application here as well so I'm gonna run yarn test and yarn test end to end so we can run the test script and the test end-to-end so if the test succeed along the build then on the artifacts section what we need to do we need to pass all the files that we're going to Pat that we're going to send through the elastic Beanstalk machine and then that's it this is our build spec file so let's keep going here I'm going to create a cloud watch group so we can see the logs for the build stage so I'm gonna say that this is the nest Js CI CD project logs actually build logs and then here just the same thing but with the stream in the name so the group name this is the stream name and then I click to continue to code pipeline perfect now the cold build project was successfully created let's click on next you can see here the green message saying that the code build project was was created let's click on next and then here we need to Define where we're going to deploy the code so in our case it's going to be elastic B stock the Oregon region and this is the project that we created previously this is the environment that we also created let's click on next here we can review the whole process for code Pipeline and code build and then I'll click to create a pipeline so for now since the project is not running yet if we click here on this link you can see the default project created by elastic Beanstalk but in a few minutes we're gonna see our code into elastic Beanstalk there's something that I forgot to mention is that since we're using sjs for the project to be built once we build a project we generate this dist and the node modules folder that we're going to send to the last admin stock machine but we're not going to install nest.js directly on the machine since we are building the whole code on code build so for using the JavaScript version what we're gonna do I also had to create into this project this proc file so instead of using the default start command for node.js projects we're going to use the start column prod which is test command here for starting the project so this way we don't need to install Nest into the final machine we can use this as a simple node.js JavaScript project as a recap for using the the JavaScript code without having to install nest.js yarn and typescript on the final machine I also added this proc file to update the start command to be this start broad which is this command load this man which has no reference to typescript to Nest to execute the project and besides this if you want to see what's happening inside cold build you can click here [Music] and then you go to tail logs so we can see the execution in this case you can see that right now it was running the test command and you see that it passes the tests so basically here code build is is running our build spec file [Music] and now it's sending all the files to the final machine on the last big slope so you can see here that the project succeeded now it's sending the code to elastic Beanstalk here if we click here you can see that it lasts the big stocks started to upload with our code [Music] okay perfect after a few minutes we can see that everything succeeded so if you click here to this link you can see our message from our application which is this one hello world V1 let's update this message to see if everything works I'm gonna make one small experiment into my tests my test file you can see here that I have this test that checks if the message is hello world view one so because of this test when I run the code build project it will fail because the tests won't pass but let's run the experiment anyway so I'm gonna just this get add get commit I'm gonna use I'm gonna pass a message here update hello world message and then an emoji and then get push okay great let's go back to code pipeline you can see here they was triggered because we pushed the code to GitHub with our changes but in this case code build will fail because of our test script since the since this test checks if the message is Hello World V1 and we updated to be hello world V2 then the code build will fail and the whole pipeline will stop the execution okay great after a few minutes you can see that the code build project failed and then if we check it here why it failed we go to tail logs we can see that the test failed the command yarn test failed because of this message expected V1 received V2 so let's fix our tests and run it again I'm gonna pass you hello world V2 and I also have an end-to-end test that checks the same message this one so let me update here too and now let's push the changes I'm gonna say fixed tests and then we push let's go back to code pipeline you go here Pipelines so back to our code pipeline project you can see that it's running here and it's running the build project again okay great so in this case you can see that our build succeeded and we also can see our commit message here test fix test you can see that in this case it worked so now cool pipeline is deploying our code into velocity Beanstalk so let me close the Old Link here you can see that it is running and apparently it all it already succeeded [Music] yes it already succeeded so if I click here you can see the new message hello world video okay great now you'll learn how to set up cicg on AWS for your nest.js project if you like this kind of content just give me a thumbs up share this video with her friends and subscribe to the channel I hope you liked it and I see you in the next time
Info
Channel: Mpcsj Tech Tips
Views: 2,266
Rating: undefined out of 5
Keywords: aws, devops, continuous integration, nestjs, nodejs, code pipeline, code build, elastic beanstalk, ci cd, ci/cd, continuous deployment, continuous delivery, sofware engineering, software
Id: k731RVoQioU
Channel Id: undefined
Length: 20min 26sec (1226 seconds)
Published: Fri Jun 23 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.