.NET 7 💥 - Upload API to Azure Container Service

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
foreign thank you for watching this video I am Muhammad and today we're going to be exploring how we can actually deploy our web application and web API into Azure we're going to be utilizing as a container service as a container registry Azure devops as well as GitHub in order for us to be actually deploying the web API into Azure there's a lot of different way where you can actually do that but today we're going to be actually exploring the cicd pipelines we're going to be creating a Docker file so on so forth if you like this video please like share and subscribe it will really helped the channel as well if you'd like to support me please consider supporting me on patreon or buy me a coffee now grab your cup of coffee and let's get started so the first thing that we need to do is we need to create our web API and it's going to be a very minimal web API where it's going to be like very limited functionality we're going to just be utilizing the the default weather endpoints that they're going to be providing us but we're going to be actually containerizing it and actually creating a Docker image out of that API so let's see how we can do that so first of all I want to check my latest version of my.net SDK so.net version just to make sure that I have installed it correctly and as you can see here I'm running on the latest one but you can basically utilize any version of not occur as long as like it's after the version 2.1 and then what I'm going to be doing is I'm going to visualize and not new web API Dash name I'm just gonna call it a sample water API as simple as that I know that it has ranked successfully all I'm going to be doing is I'm just going to CD into it that I'm gonna open it in Visual Studio code okay so now that my application is actually opened in Visual Studio code all I'm going to be doing is just going to open a terminal window and inside my terminal and all I'm gonna do is just stop not but just to make sure that everything is running as it should be okay perfect now now the next step for me is I'm gonna be basically creating a Docker file and within the docker file I'm gonna be basically containerizing my application so let's see how we can do that so on the left hand side what I'm going to be clicking on is that it's a new icon and I'm just gonna put Docker file that's it once we do that you should be able to see that we have a whale icon here and we need to make sure that Docker is running so let me go back to my web browser and all I'm going to be typing here is Docker download and all you need to do is just go to this website docker.com and make sure you download a Docker and make sure you select whatever version is actually based on your computer so if you're running on an Intel chip download the Intel version if you're running on Apple chip download the aperture version so on so forth because if you try to download like an apple chip on Intel it will not work so once you make sure that you download the right version just install it and once it's installed you'll kind of able to see you have a whale icon and you're going to be seeing that you have once you open your dashboard I'm just gonna bring it here and you're gonna be able to see that you have some this green icon here or the screen color it says engine running which means Docker has been installed successfully and it's running as it should be so let me close docker and once we have done all of that let's go back to our Visual Studio code and the first thing that I need to do in order for me to containerize my application is I need to specify the base image of I need to utilize so I'm going to put the from MCR dot Microsoft .com forward slash dot not forward slash 7.0 SDK 7.0 and then here I'm gonna say it's as build Dash environment and then once I have specified that I'm going to specify the work directory and it's going to be always forward slash up then I'm going to be exposing some of the ports Expose and it's going to be Port 80 and expose Port 443 so the port 8 is going to be for normal HTTP calls and Port 443 is going to be utilizing for SSL so once I do that the next step is I need to copy my CS approach so for that I'm going to put copy start dot CS pros and basically here is kind of map anything that has a DOT cs plus file and in my case right now it's going to be the sample weather API and I'm gonna say just copy it to the root folder and then once I do that all I need to do is just run.net restore and this means basically that my application is going to be restoring my CS approach and basically making sure that all of my packages are installed successfully once I do all of that the next step for me is I need to copy everything basically I'll copy everything from my root directory inside my container and I run .net publish Dash C release dash out which will be here I'm publishing my application into release mode I'm publishing it into a uh into an output file or output folder called out I can code whatever I I want for simplicity's sake I'm calling it out so once we have done all of that the next step is I'm gonna just reutilize this I'm basically going to create another build image and let me remove this and here all I'm going to be doing is specify a work directly inside this color code is probably slash up and then from here I'm gonna just put copy does this from and it's going to ask me from where do I want I want to copy it from the build environment image that I have and then it's going to ask me what do I want to copy and here it's gonna be basically telling it that I want to copy everything from folder up Dash out into my empty route directly so basically what I did here is I created first a a development container where basically I restored my packages I built my image and I published it and then I created another container or basically another image and then from there what I thought what I did is basically I copied only the published image from the first container into it so I don't really need all of the orchestra file and the reason to do that is uh when I publish it or basically inside and inside a container and put it inside another all of the dependencies are gonna be based on the same configuration for these two containers on the other hand if I publish it on my computer and copy it in case there is any dependency which is which is heavily based on my computer it's not uh it's not available within the container the build is kind of failed because basically it's not going to be available there so it's always better to do everything inside with one development container or the one development image excuse me and then basically copy paste it into the new image that you want to actually utilize so once we have done that the last thing that I want to do is specify an entry point and here it's going to allow me to basically run my application and from this I'm gonna just put the nut let me remove these Extra Spaces and here we need to know what the dll name so if I come here to bin I'm able to see that my DL and dll name is going to be sampled whether API dot dll so put that here okay perfect and now let's just run my application first of all I'm gonna do dot not build we can see it built successfully then I'm gonna put docker build that t I'm gonna tag this image but I call it Twitter API I'm gonna put the dot in order for it to actually find where the docker file is and I'm gonna be running it now and we can see it's doing some work downloading my uh dotnet SDK image in order for it to actually build on top of that a few moments later okay once I've done all of that we can see it's actually going through my application creating the directory is copying it now it's publishing my code and now we can see that I have a new um other API image so if I go back to my actually if we come here you can see that I have already an image available for me which is called weather API and you can see here that this is the latest version that I have so hello this is Muhammad while editing the video it's still very early morning and I missed something here to mention she's realizing the extension that I utilize within Visual Studio code in order to see the docker images that I have you if you go to the extension within a visual studio code and choose a Docker you'll be able to have a Docker extension where you'll be able to see all of the local images that you currently have as well as all of the containers which are running something I forgot to mention I just thought that it might be of interest to someone okay back to the video now okay great so in order for me to publish this image that I have just created into my other containers and the first bottom as a container registry and from there into a contender app uh I have two options either what I can do is directly push it from my local machine up to other container registry and from there create a new container service utilizing the container registry or I can rely on a devops platform like other devops in order for it to actually create a pipeline where it actually built this image for me so what I'm going to be doing right now is I'm going to be relying on the other devops pipeline in order for me to build it just a way to give you a way where you can actually utilize the pipelines in order for you to create your containers you can do whatever you want this is just like a recommendation to utilize the Azure devops Pipeline and what I'm going to be doing is I'm going to be creating the Azure container registry directly through our portal although if you're interested to learn how you can actually utilize terraform in order for us to create those services on other also please comment in the comments down below and we'll be able to create a video around that so for now all I'm going to be doing is just opening my Azure portal creating a container registry creating a dove sorry container service and then I'm gonna be going to my devops pushing first of all pushing my code into a GitHub repository connecting to my devops and from there once I connect it to my devops I'm going to be creating the pipeline and we can see my uh my container from there so first of all so first of all well this is my GitHub account if you're not following me there please make sure that you follow me all I'm going to be doing here is I'm going to put a new uh create a new repository I'm gonna select myself as an owner and I'm gonna call this repository weather API let's make it private I'm going to keep everything the same okay great I'm just gonna copy this go to my terminal let me go to my open a new tab let me zoom in actually let's utilize this one here uh all I'm going to be doing is I'm just going to put just make this a bit smaller so it will look good on the screen okay so all I'm gonna put here is go back to my desktop and inside my desktop I'm just gonna create a new folder see the uh I'm gonna call it get no let's call it publish actually make the Creator folder publish and let's go to it and then I'm gonna just clone my application perfect that now that I have closed my application all I'm going to be doing is just copy everything from my other from One Directory to another so basically I'm going to be copying it from here to here so I'm just going to put it here and we can see I have copied it successfully let's copy this okay excuse me so now that I have copied that all I'm gonna be doing is just put alas I can see that my other API folder is there and if I go there I type I us we can see that it's uh the latest one and what I'm going to be doing here is uh let's open it Visual Studio code and you can see here that I'm gonna see my entire application so the first thing that I want to do is I want to add a DOT get ignore so we don't uh push any stuff that we don't need perfect now it's saved now you can see that my bin and my object are basically uh fade out so let me go back to my terminal again all I'm going to be doing is I'm going to put git add I'm adding everything that I'm going to put get commit Dash um I'm gonna put initial requirement and all I'm gonna do from the after that is get push okay great now that has been pushed if I go back to my uh application let me go back and here you can see that this is my other apis being uploaded to my to my repo and you can see here it's basically contained the initial commit perfect so now that I have created my repository the next step is I need to create my con my container service and in order for me to do that I'm gonna go back to the other portal and uh just for privacy sake I'm just going to a different page and we can do it from there okay let me just scroll this down right now so here what I'm gonna be doing is I'm just gonna be creating a resource Group I'm gonna call it demo weather so I can delete it either later on I'm gonna choose the region that I'm currently in and for the simplicity's sake I'm just gonna be utilizing oops uh where is your UK South okay UK South I just saw it and then I'm gonna put next and create and review I'm gonna create it so all I'm gonna do is I'm gonna click on the create and the first thing I want to create a container registry see how this how this is looking okay let's make it a bit bigger so it will look better and I'm gonna say container registry and this is the one that I want I'm gonna create a new container which is three and everything is under double water I'm just gonna call it whether the service Dash demo let's remove this okay perfect then I'm gonna go to the same location and oops UK South I don't need any availability zone right now and I just need the basic functionality so let's create this perfect no it's creating it okay great go to resources and basically now I have my container registry created and the last thing that I want to do here is I want to go back to my Resource Group I'm going to create a new container service Contender instance and this is going to be it it's going to be create instance I'm going to specify this one I'm gonna call it whether Dash API demo and I'm gonna put the same configuration as I put in the other one which is going to be UK South no availability zone I'm gonna be relying on a container let's just say Okay so before I do that let me just go to my other devops and start building that image directly from my GitHub repo so this is my other uh devops let me check how this is looking okay let me close this I don't need that so this is basically my Azure devops pipeline I have already one pipeline for one of my other applications so all I'm going to be doing is inside of this I'm going to click on new pipeline and it's going to ask me where is my source code available and for this I'm just going to be choosing GitHub and from here it's going to require me to authenticate and I'm gonna authenticate with it and here I'm gonna be choosing okay let me just finish the authentication process and here it's going to ask me which one I just chose my water API I need to add my authentication code and now here is going to ask me if I want to actually approve this and I'm going to be like yes approve and installed same account that I have and now basically it's going to ask me what do you want to do and all I'm going to say is for this directory I don't want it to basically create a Docker image and basically push it to another container registry it's going to tell me choose your subscription continue what is the container registry that you want I just want to put this weather demo service and this is going to be the image name I'm just going to call it weather API and this is where the location of my Docker file so it's automatically actually it went to my GitHub repo it checked where a Docker file is and it actually pulled it all of that was done automatically for us I did not have to do any of that and then all I'm gonna say is validate and configured and now here we can see that my code has been generated as an Azure pipeline All I'm gonna be saying is save first of all I want to save it so I'm just going to call this pipeline I'm gonna commit to the main branch directly so now it's being saved and now if I go back to my GitHub repo and I refresh we should be able to see that this exists there right now and here you can see that I have my other pipeline just created and this is the commit message and this is committed just right now and all I'm going to be doing right now is just first of all rename this so I'm going to rename this oh actually let's keep it the same I'm gonna put just run pipeline it's going to ask me if there's anything that I want to change and for this case I'm going to keep it odd as is I'm going to click on run and we can see it actually started to build what it's doing here is actually it's taking my code at the docker file from my repositories actually all building it and we can see here the build stop as it goes so we can see it started to build it basically first started to check out my source code and then it's actually taking now my Docker file that I already have created and it's basically trying to build it for me we can see here it's actually doing all of the building process that I have okay perfect now it's actually pushing this build image after it has finished it into my container registry and with wireless this is finishing let's let us showcase one more thing so if we go back actually it finished already okay so now it's just doing some final job and if I go back to my container registry and while this is running I'm just going to open this in a different portal a different tab to my container registry and now if I click here on the repositories we should be able to see that what their API is there and if I click on it you can see it has just been created at basically 540 5 44 am at this amount of time exactly and you can see it gave it the tax oven if I click on it we can see this oh this is my container information so now if I go back here and it's asking me to choose a container registry I'm just going to utilize the water one okay that's fine so all I need to do here is go back to my Repository and basically I need to enable it here that's why I'm going to delete it either way even if you see in the password so now it's enabled and now all I need to do is just click here and click back let's refresh that you have to click save somewhere nope let's refresh this one must choose the demo other one demo API oh okay that's working container registry that shows that registry perfect now you can see that automatically got my image loaded and now if I want to change just make it the smallest one and I'm gonna go review and create and now I'm just going to click create okay now that has finished I'm gonna go go to resource and now I can see here that if I go to containers and we can see that it's running and I can see the log it's actually running as it should be so now it has been created successfully if I need to access it all I need to do is go through this IP and execute my request and basically this is a very quick overview of how you can actually deploy a not 7 API into Azure container service utilizing the other container registry and how you can utilize actually devops in order for you to do that I hope this video was helpful this is just a very quick overview if you'd like me to jump more into details of every single step please let me know in the comments down below and I'll make sure I'll cover it as well please like share and subscribe if you like this video it will really have the channel have a great day
Info
Channel: Mohamad Lawand
Views: 2,723
Rating: undefined out of 5
Keywords: .net 7, .net, api, beginner guide, step by step, dotnet, code with me, asp.net core tutorial, .net core, asp.net core, dotnet api, dot net, docker tutorial, docker tutorial for beginners, azure container apps, azure container docker, azure container service, dotnet dockerfile, dotnet docker tutorial, dotnet docker, github, azure devops, azure devops tutorial for beginners, azure pipelines tutorial, azure pipelines, azure container registry, docker image creation tutorial
Id: kb6v24isc7Q
Channel Id: undefined
Length: 24min 49sec (1489 seconds)
Published: Fri Feb 10 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.