Publishing to Azure From GitHub9:24 with Scott Hanselman
In this video, we'll learn how to publish an ASP.NET Core application to an Azure App Service from a GitHub repo.
All right, so we published from Visual Studios successfully, 0:00 our little ASP.NET Core application. 0:03 How would we do that without Visual Studio? 0:04 Well, one way would be to do source publishing. 0:07 We would actually publish it from somewhere like GitHub. 0:11 So here, I went and made a GitHub repository. 0:15 Didn't do anything fancy. 0:18 And remember earlier, when I had my command line created application. 0:20 This was the one where I typed dotnet new mvc, okay? 0:24 I went through the instructions, just the standard GitHub instructions, and 0:30 I pushed that up to GitHub. 0:34 It is important to note that the only thing I added was a gitignore file, 0:37 that's really important. 0:41 You don't want to check in your DLLs, your binaries. 0:42 You don't want to check your binaries in. 0:46 So I have a gitignore file that ignores Visual Studio temporary files and 0:48 things that aren't appropriate for source control. 0:54 This is a place not for my website to live but for 0:58 the source code of my website to live. 1:01 So there's no bin folder. 1:04 There's no DLLs here, right? 1:05 What I'm gonna do, I'm gonna go over here to Azure, and I'm gonna say New, Web App. 1:06 And I will make a new website. 1:16 Again, very similar dialog box to what we saw before, 1:22 except we're doing it here in the Azure portal, this website. 1:27 You'll notice the S1s and the F1s as such. 1:32 I'm gonna put that, in fact, in the same server farm as before. 1:35 Really important, so many people spending too much money, 1:39 more money than they need to, creating server farms for every website. 1:42 I am gonna exploit this virtual machine as much as I possibly can and 1:46 pay as little as possible. 1:50 So now I'm gonna hit Create. 1:51 Now go over here to App Services. 1:57 Got a couple of pants. 2:01 Here's the one I just made, superfancypants. 2:02 Let's visit that website. 2:07 That website is gonna fire up. 2:11 It's a cold website until I hit it once, and then it becomes warm. 2:12 All right, this is a nothing website, right? 2:17 This is just a HTML page. 2:19 How do we deploy our core application to here? 2:22 Well, remember it's over in GitHub. 2:25 So what I'm gonna do is I wanna set up some webhooks to allow me to do that. 2:27 I'm gonna say Deployment options, Choose Source. 2:31 There's a number of places I can pull from. 2:36 I can pull from Visual Studio Team Services, 2:38 also provides a Git deployment and the ability to store your source code. 2:41 And then when you push your application, when you update your application to 2:45 source control, it will then be automatically published to Azure. 2:49 This is why, this is the magic of why you do this. 2:52 You put your source code somewhere, VSTS, GitHub, 2:56 whatever, you say push, and then it automatically shows up on the web. 3:00 Now you can use a Local Git Repository, 3:05 but that kind of isn't what Git's all about. 3:07 You should probably use somewhere like GitHub or Bitbucket or VSTS. 3:10 I will click GitHub. 3:14 l have already authorized GitHub to talk to my Azure account. 3:15 So it's not gonna pop up a dialogue and ask me to log in. 3:19 What it's doing now is it, there you go, there's my authorization, 3:23 it's gonna ask me to choose a project. 3:26 So l can pick treehousesample and it's gonna set up a webhook. 3:28 Now, a webhook is the thing that GitHub uses to talk back to Azure. 3:33 Now I've already done this to save time earlier. 3:38 So what I'm gonna do is, I'm gonna do a little Julia Child's trick here, and 3:41 I'm gonna sneak out, and 3:44 I'm gonna switch over to a different pants that I set up earlier. 3:45 This application has been set up earlier, same exact app though. 3:49 I show you, here in GitHub, under settings, Webhooks. 3:53 I did not have to set that up, okay? 4:00 This was set up automatically by Azure. 4:02 When I said deployment options, I clicked on GitHub, 4:04 and I hit OK, it set this webhook up. 4:08 Webhooks allow external services to be notified. 4:11 This means I've published to GitHub. 4:15 GitHub then does a POST to this location and says, hey, deploy, go deploy. 4:17 That means that Azure will then go and update its local Git repository. 4:24 It'll do a fetch, pull the code from treehousesample, 4:30 and bring that over into Azure, which it has, all right. 4:34 You can see here, if I click on Deployment options, 4:39 there's my initial GitHub check in, all right. 4:42 I can actually click on that. 4:45 You can see how long it ran, you can see who the author was, and 4:46 if you want, you could even go and see all the logs. 4:50 This is an important reminder. 4:53 This looks, by the way, very similar to what we saw earlier in Visual Studio. 4:54 And I'm not doing any of this from Visual Studio. 4:59 We're doing all of this from the command line or on the web. 5:02 Nothing is hidden from you in Azure. 5:05 Sometimes it might feel like magic. 5:09 But in fact, every piece of this is available to you to see. 5:11 In fact, I'll show you a little trick. 5:15 This source control deployment here, 5:18 this is run by a system called Kudu, K, U, D, U, which is also open source. 5:20 And you can read its code on GitHub. 5:25 Now, my application is called fancypants23. 5:28 I'm gonna go here and I'm gonna type in fancypants23.scm, 5:32 dot source control management, .azurewebsites. 5:37 This is a little sidecar website. 5:42 It's a hidden little website. 5:44 Every website in Azure has a sidecar website. 5:46 Now of course, I have to login as Scott Hanselman. 5:49 This is not something that I can see if I'm anonymous, 5:51 you won't be able to get to this web site. 5:54 But it's another nice reminder that even though I'm using Azure App Services, 5:56 I'm not using cheap commodity hosting, but I'm also not using a virtual machine, 6:01 I'm abstracted away from that. 6:05 I'm thinking about my App Service plan which is a standard one. 6:07 It's nice to see that, wow there is a D drive. 6:11 I don't need to think about it. 6:14 I can just do my Git-deploy, my app looks great, everything is cool. 6:16 But, if I really wanted to see that there was a D drive, I could. 6:21 I could even go and click Debug console, go here to CMD, and check this out. 6:25 When I saw this for the first time, it blew my mind. 6:30 Site, wwwroot, and there's my stuff. 6:35 Now notice it's all DLLs though, right? 6:40 This is my website. 6:44 Which web sighted? 6:45 It's this one, right? 6:46 But I don't have controllers, right, because I didn't publish my source code, 6:47 I published the binary. 6:52 So what we did, we published the source code into here, 6:53 Kudu, brought it over into Azure, did a build, 6:57 and then dropped the results of that build into wwwroot. 7:02 And in this case, only my source, that is the Views, only my HTML is there. 7:06 Now I could make changes if we wanted to, let's do that. 7:12 I could say fancypants23 to visit the actual website. 7:16 There it is, all right. 7:25 That's the home view. 7:26 I could go in here and mess about. 7:28 Hit Save. 7:40 I'm live in production here. 7:42 And I've made a change to my application in production. 7:48 Should I do that? 7:51 Absolutely not. 7:52 Because what's gonna happen is, if I go and re-deploy, If I go back over here and 7:53 I say Deployment options, And I re-deploy, 7:58 we say, put this back the way it was, this is the shoot option. 8:04 When someone makes a change or screws up your application, you can go and 8:10 deploy that again. 8:14 That's going to get undone, 8:15 you don't want to have people making changes to your application. 8:17 So this would eventually, when that deployment happens, 8:21 go back to the way it was. 8:24 But it's nice to know that those files are on disk somewhere on a D drive. 8:26 But remember, bringing it all the way back to the beginning, 8:32 is it a D drive that I can visit? 8:36 It is not, right? 8:39 It is a D drive that is abstracted away by Azure Storage. 8:40 So, your website lives in an Azure App Service, 8:44 your Azure App Service plan lives in an Azure Virtual Machine, 8:49 the disks are hidden from you, hidden from everyone by Azure Storage. 8:53 But that is the difference between platform as a service or P, A, A, S, 8:58 PaaS, and infrastructure as a service or IaaS on Virtual Machines. 9:02 So this is how to publish an ASP.NET Core application to Azure. 9:08 I hope you continue to enjoy your experience here at Treehouse, and 9:12 thank you for letting me come here as a guest. 9:15 Again, my name is Scott Hanselman. 9:17 And you can go out and Google with Bing and find me on the web. 9:19 I hope to hear from you soon. 9:22 Thank you. 9:23
You need to sign up for Treehouse in order to download course files.Sign up