1 00:00:07,700 --> 00:00:13,650 Welcome back to BackSpace Academy. In this lab we're going to be extending our 2 00:00:13,650 --> 00:00:19,529 knowledge of continuous integration and continuous delivery on AWS by 3 00:00:19,529 --> 00:00:27,449 integrating a code pipeline with a build and test process using Mocha and we're 4 00:00:27,449 --> 00:00:32,250 going to use Codebuild which will run the node package manager to build the 5 00:00:32,250 --> 00:00:38,160 application. Then it will run a test using Mocha and if it passes that test 6 00:00:38,160 --> 00:00:43,879 then it will then forward those artifacts over to the AWS Elastic 7 00:00:43,879 --> 00:00:49,469 Beanstalk environment to be deployed. This is what it's going to look like. 8 00:00:49,469 --> 00:00:53,250 We're going to have our pipeline and, as we've done in the past, we're going to 9 00:00:53,250 --> 00:00:57,949 have a source repository with our code in Github. We're going to have our 10 00:00:57,949 --> 00:01:04,049 environment as an Elastic Beanstalk environment but we're going to introduce 11 00:01:04,049 --> 00:01:10,530 a build and test process there or build and staging process there. We're going 12 00:01:10,530 --> 00:01:17,970 to be using Codebuild and NPM to build that and then once it's built 13 00:01:17,970 --> 00:01:24,509 that application then it will pass it on to Mocha and that will actually test that 14 00:01:24,509 --> 00:01:31,229 for us. If that Mocha test passes then the Elastic Beanstalk will have that 15 00:01:31,229 --> 00:01:36,810 deployed to it. Now our deployment package that we're going to be providing 16 00:01:36,810 --> 00:01:41,729 to Codepipeline will have some additional things in it that we'll need 17 00:01:41,729 --> 00:01:46,890 to run that build and test process. In our buildspec.yml file 18 00:01:46,890 --> 00:01:51,930 we're going to define additional steps in there and it's going 19 00:01:51,930 --> 00:01:56,430 to refer to the Mocha so we're going to actually have that in our package JSON. 20 00:01:56,430 --> 00:02:00,600 We're going to make sure that we actually set up and build Mocha. Once 21 00:02:00,600 --> 00:02:08,099 it's done, it's going to run a test which will be located in a test.js file 22 00:02:08,099 --> 00:02:13,020 That'll be passed over to Codepipeline and Codepipeline 23 00:02:13,020 --> 00:02:17,220 will pass it to Codebuild which will then run NPM 24 00:02:17,220 --> 00:02:22,730 which will install all of the packages that are defined in that package JSON 25 00:02:22,730 --> 00:02:30,630 file. Once that has been built it will then pass it over and run Mocha. 26 00:02:30,630 --> 00:02:35,430 Mocha will run that test.js, if that is successful then 27 00:02:35,430 --> 00:02:41,310 AWS Codepipeline will pass it over to Elastic Beanstalk 28 00:02:41,310 --> 00:02:47,460 and that will deploy that to that Elastic Beanstalk 29 00:02:47,460 --> 00:02:54,150 environment. Now before we start building or creating our Elastic Beanstalk 30 00:02:54,150 --> 00:02:59,660 environment what we need to do is go into the Backspace Academy Github and 31 00:02:59,660 --> 00:03:05,160 fork the repository for this lab. There is a link there in the lab notes to that. 32 00:03:05,160 --> 00:03:12,260 We just go in here first off. We can star it and then we fork it. 33 00:03:18,490 --> 00:03:23,120 Okay so now that we've got that forked what we can do is that we can actually 34 00:03:23,120 --> 00:03:33,860 download that zip file. Once that zip file has completed we need to actually 35 00:03:33,860 --> 00:03:44,600 change it so that the code is not hidden in a folder. First off 36 00:03:44,600 --> 00:03:47,410 we'll extract that. 37 00:03:54,620 --> 00:04:02,760 Okay so that's extracted and we just need to zip that back up again. Okay so 38 00:04:02,760 --> 00:04:06,959 there we've got that zipped for us and we can save that somewhere for easy 39 00:04:06,959 --> 00:04:11,640 access. Let's now jump into Elastic Beanstalk 40 00:04:11,640 --> 00:04:16,620 and create that environment. Okay so create new application. We'll 41 00:04:16,620 --> 00:04:28,050 give that a name and create. Now we go to actions create environment for 42 00:04:28,050 --> 00:04:32,789 this application. It's a web server environment. We'll leave the name as it 43 00:04:32,789 --> 00:04:40,430 is. We need to select node.js and we'll upload our code. 44 00:04:45,360 --> 00:04:49,340 We can create our environment now. 45 00:04:49,490 --> 00:04:55,889 Okay so after 10 minutes or so we've got our Elastic Beanstalk environment up and 46 00:04:55,889 --> 00:04:59,939 running. So before we jump into Codepipeline, what we'll do is we'll have a 47 00:04:59,939 --> 00:05:05,490 look at some of the changes that we've made to to integrate with the build 48 00:05:05,490 --> 00:05:11,939 and test environments. Let's have a look first at our buildsspec.yml file. 49 00:05:11,939 --> 00:05:16,169 Just have a look at that and see what's going on there. We've got some pre-build 50 00:05:16,169 --> 00:05:20,340 commands here, or we've got some install commands. We're going to be 51 00:05:20,340 --> 00:05:26,400 installing Mocha. Once we've done that we're going to do NPM install. 52 00:05:26,400 --> 00:05:32,000 It'll install all of the packages that are located in our package JSON file. 53 00:05:32,000 --> 00:05:38,819 Then we're going to be installing unit.js to run our unit tests. Once that's 54 00:05:38,819 --> 00:05:45,659 all done and we've got everything built, we can then run mocha test.js which 55 00:05:45,659 --> 00:05:52,469 will run a test using Mocha that will be located in test.js file. 56 00:05:52,469 --> 00:05:57,449 Once it is successful, then it will create all these 57 00:05:57,449 --> 00:06:04,110 artifacts and pass these artifacts over to Elastic Beanstalk. Let's have a 58 00:06:04,110 --> 00:06:10,740 look at the test.js. So that's our test. So this is not a lab on how to use Mocha 59 00:06:10,740 --> 00:06:14,940 or anything like that. It's a very simple test just creating a test dot 60 00:06:14,940 --> 00:06:20,190 string here starts with hello and then we're passing the word hello 61 00:06:20,190 --> 00:06:24,629 back to that. It's obviously going to pass. So if that test pass which it 62 00:06:24,629 --> 00:06:30,839 most definitely will then that will proceed to deliver that through to 63 00:06:30,839 --> 00:06:38,610 Elastic Beanstalk. Let's jump into Codepipeline and create this code 64 00:06:38,610 --> 00:06:43,560 pipeline. We jump into codepipeline and create our pipeline. Again we get 65 00:06:43,560 --> 00:06:52,310 there from services codepipeline. Create pipeline. We'll give this a name. 66 00:07:02,930 --> 00:07:08,320 We can use an existing service role that we've used before if we've got one. 67 00:07:12,850 --> 00:07:19,490 We just use our default location for the artifact store that will be fine. 68 00:07:19,490 --> 00:07:26,180 We'll click on next. Our source provider again is going to be in Github. We'll 69 00:07:26,180 --> 00:07:29,200 connect to our Github repository. 70 00:07:35,730 --> 00:07:39,930 Okay so we've done that we now need to get our repository name. We go back 71 00:07:39,930 --> 00:07:50,910 into our Github account and then we can select the name of that repository. 72 00:07:50,910 --> 00:07:59,040 We just copy that and paste that in and our branch will be master again. We'll 73 00:07:59,040 --> 00:08:04,890 use the Github web hooks. Click on next. We're going to have our build 74 00:08:04,890 --> 00:08:11,970 provider here. That is going to be AWS codebuild. We don't have a project 75 00:08:11,970 --> 00:08:21,660 name so it's going to create a project for us. We click on create project. 76 00:08:21,660 --> 00:08:26,610 That has now opened up another window which is going to have Codebuild there. 77 00:08:26,610 --> 00:08:30,410 We give our Codebuild project a name. 78 00:08:38,250 --> 00:08:42,959 We won't worry about a description for it. We're going to be using a managed 79 00:08:42,959 --> 00:08:50,699 image. Our operating system is going to be Ubuntu it's a linux. Our run 80 00:08:50,699 --> 00:09:00,870 time is going to be NodeJS. We'll use the latest version of that. We'll use 81 00:09:00,870 --> 00:09:10,139 version 10 of node. We'll select new service role. 82 00:09:10,139 --> 00:09:16,290 We leave use buildspec file as it 83 00:09:16,290 --> 00:09:23,000 is and we will continue to codepipeline. 84 00:09:39,040 --> 00:09:44,540 Okay so we've successfully created backspace'-eb-coidebuild in Codebuild. 85 00:09:44,540 --> 00:09:51,770 We'll click on next and we're going to deploy now. We need 86 00:09:51,770 --> 00:10:00,200 again to select Elastic Beanstalk. Select our application and our environment. 87 00:10:00,200 --> 00:10:06,890 Click on next. There we go. We've got our pipeline there. It's going to 88 00:10:06,890 --> 00:10:10,790 have our source being Github. We're going to build stage there which is 89 00:10:10,790 --> 00:10:16,000 going to be an AWS codebuild project called backspace-eb-codebuild. 90 00:10:16,000 --> 00:10:22,240 We're going to be deploying to Elastic Beanstalk. Let's create that pipeline. 91 00:10:24,670 --> 00:10:31,070 Okay so the pipeline has been created and so now it will start to build and 92 00:10:31,070 --> 00:10:36,770 test that source and hopefully it will deploy it to Elastic Beanstalk if 93 00:10:36,770 --> 00:10:47,900 there are no errors. Ok so after about 10 minutes or so it has gone through and it 94 00:10:47,900 --> 00:10:53,959 has built them successfully. It has run that test and it has also 95 00:10:53,959 --> 00:10:59,779 passed that on as a deployment. So that is great. So we've successfully created a 96 00:10:59,779 --> 00:11:07,670 full CI CD pipeline going from a Github repository all the way through to an 97 00:11:07,670 --> 00:11:12,830 Elastic Beanstalk environment. Now one last thing to do is to clean up so that 98 00:11:12,830 --> 00:11:16,339 we don't get a bill at the end of the month. The first thing we can do is 99 00:11:16,339 --> 00:11:22,360 that we can edit this. Delete it and, delete. 100 00:11:26,030 --> 00:11:31,070 That will be deleting. Successfully deleted, that's fine. We go into our 101 00:11:31,070 --> 00:11:36,410 Elastic Beanstalk. We go into actions and 102 00:11:36,410 --> 00:11:41,690 we can go into our actual application and we can delete our application which 103 00:11:41,690 --> 00:11:46,400 will delete those environments as well. Go into our application, delete 104 00:11:46,400 --> 00:11:56,990 application. Okay and if we go into this now it will see that it's terminating 105 00:11:56,990 --> 00:12:01,850 our environment for us., So that is all complete. So we won't get a bill at the end of the 106 00:12:01,850 --> 00:12:06,140 month. I hope you've enjoyed this lab it's been quite a good one and I'll look 107 00:12:06,140 --> 00:12:10,000 forward to seeing you in the next one.