1 00:00:00,360 --> 00:00:02,400 ‫Okay so back at it we need to fix 2 00:00:02,400 --> 00:00:05,010 ‫that YAML file error because our build spec 3 00:00:05,010 --> 00:00:06,690 ‫dot YAML file does not exist. 4 00:00:06,690 --> 00:00:08,810 ‫So let's go to CodeCommit and we're going 5 00:00:08,810 --> 00:00:09,643 ‫to create a file. 6 00:00:09,643 --> 00:00:12,060 ‫Obviously we could do this using the Git 7 00:00:12,060 --> 00:00:14,000 ‫command line but this is going to be easy to do 8 00:00:14,000 --> 00:00:16,360 ‫in-browser and just for the sake of this demo 9 00:00:16,360 --> 00:00:17,490 ‫this is just fine. 10 00:00:17,490 --> 00:00:21,540 ‫Okay, so now we need to add this file content. 11 00:00:21,540 --> 00:00:24,650 ‫So the file name, first of all, is build spec 12 00:00:24,650 --> 00:00:27,470 ‫dot YAML, okay? 13 00:00:27,470 --> 00:00:28,640 ‫Now, for the file content. 14 00:00:28,640 --> 00:00:29,650 ‫I'm not going to type it out. 15 00:00:29,650 --> 00:00:31,460 ‫I'm going to copy it straight from the code 16 00:00:31,460 --> 00:00:32,500 ‫you've downloaded. 17 00:00:32,500 --> 00:00:34,420 ‫So right here and I'm going to describe to you 18 00:00:34,420 --> 00:00:35,720 ‫what this means. 19 00:00:35,720 --> 00:00:39,810 ‫So this is a YAML file and a YAML file is made 20 00:00:39,810 --> 00:00:41,680 ‫of text and colons. 21 00:00:41,680 --> 00:00:43,650 ‫It's a key value pair type of file. 22 00:00:43,650 --> 00:00:45,190 ‫And you need to get used to this format 23 00:00:45,190 --> 00:00:46,770 ‫but it's quite human-readable, and that's why 24 00:00:46,770 --> 00:00:47,760 ‫people like it. 25 00:00:47,760 --> 00:00:50,060 ‫And so two separate sections. 26 00:00:50,060 --> 00:00:54,660 ‫You can add spaces or tabs and this will indent your thing. 27 00:00:54,660 --> 00:00:57,710 ‫Okay, so now let's look at this YAML file. 28 00:00:57,710 --> 00:01:01,100 ‫The version of our build spec dot YAML is 0.2 29 00:01:01,100 --> 00:01:03,310 ‫and this comes straight from the reference 30 00:01:03,310 --> 00:01:06,520 ‫documentation for this build spec dot YAML file. 31 00:01:06,520 --> 00:01:09,230 ‫Now we have phases and I just added a bunch 32 00:01:09,230 --> 00:01:12,320 ‫of commands into each phase to show you how they work. 33 00:01:12,320 --> 00:01:15,070 ‫So the first phase is install and here we specify 34 00:01:15,070 --> 00:01:19,370 ‫the runtime version for our CodeBuild environment. 35 00:01:19,370 --> 00:01:22,870 ‫So here we have node JS and we use version 10. 36 00:01:22,870 --> 00:01:25,280 ‫We can also insert commands that will be run 37 00:01:25,280 --> 00:01:27,930 ‫while CodeBuild does its test. 38 00:01:27,930 --> 00:01:30,910 ‫And so here during the install phase just echo, 39 00:01:30,910 --> 00:01:33,830 ‫which means print to the screen, installing something. 40 00:01:33,830 --> 00:01:36,930 ‫And so it's indeed installing node JS 10. 41 00:01:36,930 --> 00:01:39,560 ‫Okay, pre-build. 42 00:01:39,560 --> 00:01:42,670 ‫Before the build happens we can also do a bunch of commands. 43 00:01:42,670 --> 00:01:45,040 ‫So we can do commands everywhere and I will just 44 00:01:45,040 --> 00:01:46,150 ‫say again, echo. 45 00:01:46,150 --> 00:01:48,200 ‫We are in the pre-build phase. 46 00:01:48,200 --> 00:01:50,300 ‫Now, while it's building this is where 47 00:01:50,300 --> 00:01:51,480 ‫the important commands are. 48 00:01:51,480 --> 00:01:54,050 ‫This is where you're going to test out your code. 49 00:01:54,050 --> 00:01:55,960 ‫So here you can set up a bunch of commands. 50 00:01:55,960 --> 00:01:58,467 ‫So I said, "We are in the building block. 51 00:01:58,467 --> 00:02:00,080 ‫"We will run some tests." 52 00:02:00,080 --> 00:02:01,850 ‫And here this one command right here, 53 00:02:01,850 --> 00:02:02,980 ‫don't need to be a Linux expert, 54 00:02:02,980 --> 00:02:04,080 ‫I'll just tell you what it does. 55 00:02:04,080 --> 00:02:07,750 ‫Grep minus FQ congratulations index of HTML 56 00:02:07,750 --> 00:02:11,210 ‫will look at this index dot HTML file 57 00:02:11,210 --> 00:02:14,640 ‫and see if the text congratulations is in it. 58 00:02:14,640 --> 00:02:16,520 ‫If it's in it, it's going to succeed. 59 00:02:16,520 --> 00:02:18,300 ‫So this test is going to pass. 60 00:02:18,300 --> 00:02:21,380 ‫But if congratulations is not found in it anymore 61 00:02:21,380 --> 00:02:23,143 ‫this is going to crash and fail. 62 00:02:24,350 --> 00:02:25,480 ‫So this is our test. 63 00:02:25,480 --> 00:02:27,920 ‫Then we have post-build and we could just echo. 64 00:02:27,920 --> 00:02:29,870 ‫We are in the post-build phase. 65 00:02:29,870 --> 00:02:32,070 ‫Okay, so this is the kind of files 66 00:02:32,070 --> 00:02:35,040 ‫that you'll build over time and you'll get used to it. 67 00:02:35,040 --> 00:02:36,710 ‫Okay, so build spec dot YAML. 68 00:02:36,710 --> 00:02:39,120 ‫The author name is Stephane and the email 69 00:02:39,120 --> 00:02:42,140 ‫address is stefane@example.com, and the commit message. 70 00:02:42,140 --> 00:02:47,140 ‫I just added build spec dot YAML at the root 71 00:02:47,870 --> 00:02:50,420 ‫of our directory. 72 00:02:50,420 --> 00:02:51,640 ‫So this is super-important to say 73 00:02:51,640 --> 00:02:53,640 ‫that it's the root of our directory 74 00:02:53,640 --> 00:02:57,160 ‫because this is where the file is expected to be. 75 00:02:57,160 --> 00:02:59,640 ‫We'll commit the changes and now build spec 76 00:02:59,640 --> 00:03:01,230 ‫dot YAML has been committed. 77 00:03:01,230 --> 00:03:02,063 ‫Excellent. 78 00:03:02,063 --> 00:03:03,450 ‫So if you go back to our my node JS app 79 00:03:03,450 --> 00:03:06,170 ‫we see that build spec dot YAML is here. 80 00:03:06,170 --> 00:03:09,950 ‫So now if we go to CodeBuild, go to our build project, 81 00:03:09,950 --> 00:03:12,530 ‫go to this one and have a look. 82 00:03:12,530 --> 00:03:14,850 ‫Okay, the build history has failed but now 83 00:03:14,850 --> 00:03:17,940 ‫what we can do is start a new build. 84 00:03:17,940 --> 00:03:20,140 ‫And okay, the same configuration as before. 85 00:03:20,140 --> 00:03:23,160 ‫Start the build but now hopefully this build 86 00:03:23,160 --> 00:03:25,480 ‫should pull that file that we've created, 87 00:03:25,480 --> 00:03:28,310 ‫build spec dot YAML, and run our build. 88 00:03:28,310 --> 00:03:30,880 ‫So let's wait and see what happens. 89 00:03:30,880 --> 00:03:33,610 ‫And this time the build has succeeded. 90 00:03:33,610 --> 00:03:35,370 ‫So let's look at the phase details. 91 00:03:35,370 --> 00:03:38,810 ‫So we can see all the phases that have happened 92 00:03:38,810 --> 00:03:39,840 ‫in our build. 93 00:03:39,840 --> 00:03:42,130 ‫And it goes all the way from submitted to queued, 94 00:03:42,130 --> 00:03:44,110 ‫provisioning, download source, install, 95 00:03:44,110 --> 00:03:46,540 ‫pre-build, build, post-build, offload effects, 96 00:03:46,540 --> 00:03:47,710 ‫finalizing, and completed. 97 00:03:47,710 --> 00:03:49,320 ‫Oof, I said them all. 98 00:03:49,320 --> 00:03:52,500 ‫And we can see how long each phase did take, 99 00:03:52,500 --> 00:03:54,450 ‫okay, with a start time and the end time. 100 00:03:54,450 --> 00:03:56,250 ‫So this is a really good visibility into what 101 00:03:56,250 --> 00:03:59,050 ‫could be taking a long time if we ever have a timeout. 102 00:03:59,050 --> 00:04:01,370 ‫Okay, now let's go into the build log 103 00:04:01,370 --> 00:04:05,250 ‫and this is showing the 10,000 last line of the build log. 104 00:04:05,250 --> 00:04:07,950 ‫But we can view the entire log if we clicked on this. 105 00:04:07,950 --> 00:04:10,270 ‫And this would take us straight into the cloud 106 00:04:10,270 --> 00:04:14,600 ‫watch logs UI to see all the logs. 107 00:04:14,600 --> 00:04:16,100 ‫So let's look at them from here. 108 00:04:16,100 --> 00:04:17,360 ‫This is pretty interesting. 109 00:04:17,360 --> 00:04:20,940 ‫So here it says entering phase install 110 00:04:20,940 --> 00:04:23,610 ‫and is going to install node JS version 10. 111 00:04:23,610 --> 00:04:24,930 ‫So it says that, okay. 112 00:04:24,930 --> 00:04:27,130 ‫This is the version we specified from before. 113 00:04:27,130 --> 00:04:29,160 ‫Then we echo installing something which is just 114 00:04:29,160 --> 00:04:31,760 ‫our little debug to see what happens. 115 00:04:31,760 --> 00:04:33,740 ‫Then the install phase is succeeded. 116 00:04:33,740 --> 00:04:35,410 ‫Then we go into the pre-build phase 117 00:04:35,410 --> 00:04:36,940 ‫where we are in the pre-build phase 118 00:04:36,940 --> 00:04:40,160 ‫so this is returning right here, again as a log line. 119 00:04:40,160 --> 00:04:40,993 ‫And then we succeeded. 120 00:04:40,993 --> 00:04:42,840 ‫We go into the build phase. 121 00:04:42,840 --> 00:04:43,730 ‫And we're in the build block. 122 00:04:43,730 --> 00:04:45,550 ‫We're going to run some test and we run 123 00:04:45,550 --> 00:04:49,080 ‫the command grep minus FQ congratulations index HTML. 124 00:04:49,080 --> 00:04:50,470 ‫And this passes, this succeeds, 125 00:04:50,470 --> 00:04:52,430 ‫so the build phase is succeeded. 126 00:04:52,430 --> 00:04:54,790 ‫And finally we're into post-build and we echo. 127 00:04:54,790 --> 00:04:56,280 ‫We are in the post-build phase. 128 00:04:56,280 --> 00:04:57,880 ‫So we get the access through the whole log 129 00:04:57,880 --> 00:05:00,236 ‫either from CloudWatch logs or again directly 130 00:05:00,236 --> 00:05:05,236 ‫from the CodeBuild UI and we can see the exact same thing. 131 00:05:05,730 --> 00:05:08,070 ‫Okay, so this is a good news. 132 00:05:08,070 --> 00:05:11,960 ‫Now how do we integrate this build project 133 00:05:11,960 --> 00:05:14,160 ‫into our code deploy? 134 00:05:14,160 --> 00:05:14,993 ‫Pretty easy. 135 00:05:14,993 --> 00:05:16,510 ‫So let's go to our deploy, not a go to deployer, 136 00:05:16,510 --> 00:05:17,850 ‫go to pipeline obviously. 137 00:05:17,850 --> 00:05:19,430 ‫I'm getting ahead of myself. 138 00:05:19,430 --> 00:05:22,030 ‫So let's go to my first pipeline. 139 00:05:22,030 --> 00:05:25,940 ‫And here between source and deploy I want to test. 140 00:05:25,940 --> 00:05:28,617 ‫So I'm going to edit my pipeline and I'm going 141 00:05:28,617 --> 00:05:29,740 ‫to add a stage. 142 00:05:29,740 --> 00:05:32,140 ‫And I'm going to call it build and test. 143 00:05:32,140 --> 00:05:34,200 ‫But here we're just going to test, okay 144 00:05:34,200 --> 00:05:36,330 ‫but we could build as well if you wanted to. 145 00:05:36,330 --> 00:05:38,000 ‫Okay, within this we're going to add 146 00:05:38,000 --> 00:05:42,290 ‫an action group, call it test for congratulations. 147 00:05:42,290 --> 00:05:45,780 ‫And the action provider is going to be CodeBuild. 148 00:05:45,780 --> 00:05:49,790 ‫In this region, input artifacts is the one from the source. 149 00:05:49,790 --> 00:05:52,210 ‫The project name is my build project 150 00:05:52,210 --> 00:05:54,540 ‫and for the output artifact we can just choose 151 00:05:54,540 --> 00:05:55,900 ‫a name for the output of the section. 152 00:05:55,900 --> 00:05:59,440 ‫We'll call it output of tests. 153 00:05:59,440 --> 00:06:00,770 ‫Okay, excellent. 154 00:06:00,770 --> 00:06:03,010 ‫Click on done and here we go. 155 00:06:03,010 --> 00:06:07,730 ‫We have added our CodeBuild into this entire pipeline. 156 00:06:07,730 --> 00:06:10,880 ‫So I'll click on done and we are done here. 157 00:06:10,880 --> 00:06:11,713 ‫It looks like it. 158 00:06:11,713 --> 00:06:14,490 ‫I'll save this and save that. 159 00:06:14,490 --> 00:06:16,530 ‫Okay, so now we have a new pipeline. 160 00:06:16,530 --> 00:06:18,550 ‫And so we should be testing it, right? 161 00:06:18,550 --> 00:06:19,540 ‫So how do we do this? 162 00:06:19,540 --> 00:06:22,240 ‫Well, we go to CodeCommit, for example, 163 00:06:22,240 --> 00:06:24,530 ‫and we go to our index dot HTML file. 164 00:06:24,530 --> 00:06:26,610 ‫We're going to scroll down and find 165 00:06:26,610 --> 00:06:27,800 ‫this congratulations text. 166 00:06:27,800 --> 00:06:28,960 ‫And we're going to edit it out. 167 00:06:28,960 --> 00:06:31,550 ‫So I'll click on edit and I'll scroll down 168 00:06:31,550 --> 00:06:33,570 ‫to congratulations, and I'll change it 169 00:06:33,570 --> 00:06:35,970 ‫to something like horrible. 170 00:06:35,970 --> 00:06:40,827 ‫And I'll say, "Okay, this is Stefan, stefan@example.com. 171 00:06:40,827 --> 00:06:45,120 ‫"Change text from congratulations to horrible." 172 00:06:45,120 --> 00:06:47,120 ‫And the reason why I changed this congratulations 173 00:06:47,120 --> 00:06:49,710 ‫text away is to horrible, I could have said whatever, 174 00:06:49,710 --> 00:06:52,880 ‫is because we want to have the text fail. 175 00:06:52,880 --> 00:06:56,290 ‫So I'll commit my changes and changes have now 176 00:06:56,290 --> 00:06:57,740 ‫been committed to master. 177 00:06:57,740 --> 00:06:59,920 ‫So back into my code pipeline. 178 00:06:59,920 --> 00:07:04,030 ‫Very soon I should start seeing my CodeCommit to succeed. 179 00:07:04,030 --> 00:07:07,393 ‫So let's wait a second to see if things get started. 180 00:07:08,250 --> 00:07:11,470 ‫Okay, so here at my source data was just pulled. 181 00:07:11,470 --> 00:07:13,400 ‫And then we went straight into the build 182 00:07:13,400 --> 00:07:15,210 ‫and test, which is in progress. 183 00:07:15,210 --> 00:07:17,660 ‫So I can click on details to see what's happening. 184 00:07:17,660 --> 00:07:21,840 ‫So it takes me straight into my CodeBuild UI. 185 00:07:21,840 --> 00:07:23,000 ‫And this has failed. 186 00:07:23,000 --> 00:07:24,640 ‫Okay, so my build has failed. 187 00:07:24,640 --> 00:07:27,397 ‫And if we scroll down and see why it says, "Okay, 188 00:07:27,397 --> 00:07:31,037 ‫"This grep minus FQ congratulations index of HTML 189 00:07:31,037 --> 00:07:33,227 ‫"has failed because it did not successfully 190 00:07:33,227 --> 00:07:35,840 ‫"find congratulations in my index dot HTML file," 191 00:07:35,840 --> 00:07:38,270 ‫which is exactly the behavior we wanted. 192 00:07:38,270 --> 00:07:42,180 ‫So this has failed and so therefore my bad code 193 00:07:42,180 --> 00:07:43,820 ‫has not been put into Beanstalk. 194 00:07:43,820 --> 00:07:48,210 ‫Beanstalk still shows the congratulations text. 195 00:07:48,210 --> 00:07:50,550 ‫So how do I make this pass, the test suite? 196 00:07:50,550 --> 00:07:52,730 ‫I'll go back to CodeCommit and I'm going to fix 197 00:07:52,730 --> 00:07:54,260 ‫obviously my mistakes. 198 00:07:54,260 --> 00:07:58,130 ‫So I'll say, "congratulations CodeBuild." 199 00:07:58,130 --> 00:08:00,570 ‫We're just going to add a little funkiness to it. 200 00:08:00,570 --> 00:08:05,570 ‫And I'll say, "Stefane," same address, 201 00:08:05,620 --> 00:08:09,427 ‫and then I'll say, "Fixed the congratulations texts." 202 00:08:11,000 --> 00:08:13,580 ‫Commit my changes and here we go. 203 00:08:13,580 --> 00:08:15,060 ‫It's been committed to master. 204 00:08:15,060 --> 00:08:18,760 ‫So now very soon my source should get started 205 00:08:18,760 --> 00:08:21,870 ‫to pull the new code from CodeCommit. 206 00:08:21,870 --> 00:08:25,440 ‫And hopefully now this time build and test will pass. 207 00:08:25,440 --> 00:08:27,840 ‫And then this change will be deployed into Beanstalk. 208 00:08:27,840 --> 00:08:30,600 ‫So let's wait a little bit again to see this. 209 00:08:30,600 --> 00:08:32,570 ‫Okay, so this time the source has passed. 210 00:08:32,570 --> 00:08:34,360 ‫The build and test has succeeded 211 00:08:34,360 --> 00:08:35,970 ‫so my test suite has worked. 212 00:08:35,970 --> 00:08:37,810 ‫And has been deployed, and so if we go 213 00:08:37,810 --> 00:08:40,577 ‫into Beanstalk and refresh we now see, 214 00:08:40,577 --> 00:08:41,440 ‫"Congratulations CodeBuild." 215 00:08:41,440 --> 00:08:43,740 ‫So CodeBuild did its job correctly. 216 00:08:43,740 --> 00:08:45,680 ‫So I hope you can start seeing the power of 217 00:08:45,680 --> 00:08:48,680 ‫CICD right here, how easy it is to change things, 218 00:08:48,680 --> 00:08:50,940 ‫test for them, and then push them eventually 219 00:08:50,940 --> 00:08:53,500 ‫to whatever environment you need to push them into. 220 00:08:53,500 --> 00:08:56,230 ‫So back to CodeBuild, we have our build projects, 221 00:08:56,230 --> 00:08:59,060 ‫we can look at our build history and see how long 222 00:08:59,060 --> 00:09:00,770 ‫each build was, when it was completed, 223 00:09:00,770 --> 00:09:03,360 ‫if it succeeded, why it was invoked, and so on. 224 00:09:03,360 --> 00:09:06,563 ‫And so overall with, I think CodeBuild 225 00:09:06,563 --> 00:09:09,430 ‫is a really awesome tool to have, lots of different options. 226 00:09:09,430 --> 00:09:11,630 ‫But you've seen the main ones going into the exam. 227 00:09:11,630 --> 00:09:12,870 ‫So I hope you like this lecture 228 00:09:12,870 --> 00:09:14,820 ‫and I will see you in the next lecture.