Intro to Azure DevOps - Build and Deploy Python Web Application

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello my name is russ maxwell and this is my first devops video where i'm going to talk about how to build and deploy a python web application to azure so we're going to use a combination of different of different components we're going to use vs code we're going to use git we're going to leverage a repository in github we're also going to leverage azure as well as azure devops feel free to subscribe to my channel as i will be publishing additional sessions around devops in the near future let's get started so the general idea behind this video is talk to talk of course about each of those components i just mentioned but also show you a flow of how these different technologies work together in order to produce a solution uh within azure and so as we move along in this video series as i create additional videos this high level flow will kind of get you familiar with some of the deeper level conversations that i intend to have in future videos so in this video what we're going to do is we're going to grab code from a repository on github that represents a python web application we're going to make a change to that locally and then we're going to push that code up to a new repository in azure devops and then finally within azure devops we're going to build a pipeline to build that code into a web app and then deploy to azure so pretty cool stuff to see how all this works together and the best part is this is pretty much all going to be demo based and i will include a references slide at the end but let's get started so the very first thing i want to kind of mention is your local machine is is in this case a fairly important part of of this particular scenario because in a version control a distributed version control environment what's happening is your developer your development team they're actually doing most of their coding locally on their local machine and they're pushing those changes up back up to whatever repository that that they're designating whether it be github or azure repositories or some other repository out there because my azure repository is git based that basically means that i'm using distributed version control and so because of that i need my local machine set up with git with vs code and optionally if i'm doing any python development i'm going to want to download and install python uh and then of course within bs code if i'm going to be working with python i probably want the extension installed and so these are the different links to download and install those for windows 10 machine and most of these are cross-platform so you should be able to find the download links for different platforms if you'd like so i'm in vs code and i want to show you that i do have git for windows installed and in order to do this validation i simply launched bash in a terminal shell and bash is included when you download and install git for windows so i'm just going to run git and you can see i have results back so it's all set there so i think i'm ready to roll what i need to do next is to choose a repository on github that i'm interested in and in this case this is my own repository and this is a sample python web application very very basic and what i need to do is i need to clone this repository which is a fancy way of saying i need to basically copy it down locally and so what i need to do is hit the pull down for code and i need to copy this url which will be used by git to retrieve this so that's copied i'm going to come back here to vs code notice the folder you're in is important so right now i'm in d projects and because i'm running it from the projects this is where the repo by default this is where it's going to be stored this repository so so i'm simply going to run git clone all right so good news it is present if i go to my d projects folder i have the repository now there and it does look like it's initialized with git because i have the dot get folder present so good news all right next up i'm going to open the folder so in vs code i'm going to open the folder i'm going to select projects and my repository i just cloned all right great let's open up a new terminal session there we go and one way to know this is uh initiated as a as a git repository so i can do git status and you can see i'm on main branch and so so that's how commits are stored they're stored in branches and you always start with what's called the main branch used to be called trunk but in this case i'm in the main branch locally and because i'm receiving that message and not a fatal error i know that it is successfully initiated as a good repository okay so step one is completed uh so i've cloned a repository from github locally and now i need to set up things on the azure side so i need to set up an azure web application and then after that's set up i need to go into azure devops and set up my project which comes with a repository and so i'm in azure currently manager portal and i'm in my resource group and i'll click add and choose azure web app it looks like the web apps here okay i like the rg it's in i'm going to call this rust max 7 it will be published with code and of course for this i'm going to select in this case i'm selecting python37 and i'll select the same a region as the as the resource group actually i just want to do devtest so i'm going to go with the free plan all right so it's creating all right it's completed let's take a look so good news it is running i do have a url which you're always going to get a url by default of whatever whatever name you entered for the web app plus azurewebsites.net so i'm going to click on that make sure i've got a good response here all right so this is the sample site there's some good stuff here in terms of quick start and and kind of getting things prepared and getting your feet wet with python but this is fantastic so now we've have a python based web application spun up that we're going to end up deploying to in azure and now i'm in the azure devops portal so dev.azure.com i'm in my organization and i've already spun up a few projects the one i'm interested for this particular project is here russ max demo so i'm going to click on it and you can see on the left i've got a bunch of information so each project you create comes with an overview boards repos pipelines test plans and artifacts for this session i'm interested mainly in showing you repos and some information about pipelines and so the cool thing here is that if i click on repos it's not initialized yet but i do have a default repo that's available to me if you don't want to use the default you can always come up here and create your own repo in my case i'm perfectly okay with using the project paste repo and again this is going to store my source code and so what i want to do here is i need to push my code to it from from vs code and let's go ahead and do that now let's make a change in vs code to my python web application code and then i'm going to push that package up to this repository all right so i'm back in vs code on my local client i've got the project opened and i'm going to make a change and notice at the top of this python file i don't expect you to be well versed in python i'm taking that approach here if you are then this should be pretty basic but i've i have the flask framework i'm using the flask web framework and it is a python web framework and it's small but robust so i'm going to utilize it and so i had to install it so i did a pip install flask so very similar to something like this to get it installed and after i installed it i was able to reference it from line one here create the object and then have just some some just a easy response when i hit the page uh and so i want to change this right because this is the code that was pulled from github and i want to change that to this code was updated locally and pushed to azure [Music] devops repo okay because that's what we're doing what we we've already cloned this right so we want to make a change to it and that's what we're doing we're making a change to the code so i'm going to go ahead and save that and you do have some source control directly within bs code if you'd like to use that i'm not going to discuss that i'm just going to show you through just the command line using git on how to take these changes and get them committed and merged into the local main branch so if i were to run git status that shows you where things add and you can see i've made it actually i removed the a pipeline yaml file i'll talk about that in a moment i removed and then i changed a couple files so again this is not really geared towards ramping you up from a python perspective it's just kind of showing you how things flow together uh from from more of a infrastructure standpoint so cool so i do have some changes and i need to the first step is i need to push those changes into whether what's called staging it's in order to do that to add to these files or these changes i can just do git add and then dash a and now if i were to run git status again you can see they're now on staging and what's what's powerful about git is the fact that i can come in and make a change to a file and it'll detect that change you can see it's modified it i'm going to go ahead and commit that to my to my main branch i'll call first commit and so now you can see that there was uh some deletions that i because i deleted that yaml file but those modifications including the modification i'm interested in which is the return statement has been updated so if i were to do git status i'm in a clean tree so great so i'm in my main branch i'm in the clean tree uh cool so the code was updated so this is good we've we're about halfway there so we've basically cloned a project from github we went over to azure we created our web application which we're going to eventually deployed to and we also went back to our our code locally we made a change to it and now we're ready to push that change up to our azure devops repository so let's go let's go ahead and grab that url and so we're going to use this right push an existing repository from command line because that's exactly what we have and so i'm going to use these commands and let's go ahead and begin let's go back to vs code the first thing i want to do is show you this get remote dashb and notice whenever you do a a clone from a different repository it's going to maintain that origin url and so right now it's for fetching and pushing it's going to that github repository that i used originally to pull down that code i want to change that right because i want to push this code up to my azure devops repository so in order to do that uh there's a command i can run for that it is git remote set url origin and i'll paste in the path that i copied from the repository ah i misspelled remote sorry about that okay that's finished and so now if i run git remote v you can see that now i'm fetching and pushing to this uh new repository so that that's actually really important is that if you're if you're playing around and you're cloning from different repositories and then you want to make changes and then push that code to a different repository somewhere else you'll need to know how to do this and so now that that is set correctly now i can actually go ahead and push my local branch containing my updated code change up to my azure devops repository so i will run git push u origin main and main stands for main branch notice it's having me authenticate and so i'm going to authenticate to manage your devops repro and notice it is being pushed up so cool so it's finished let's take a look so remember when i said this wasn't initialized now that i've pushed my code to it you can see it's now it now has my code and this is pretty cool right uh so we've almost come full circle so now we have the code sitting on a repo repository i'm just going to start saying repos it's easier but now we have that code sitting in a repo in my azure devops project so i do want to stress again this is very high level i do plan on getting more into the weeds and in future videos on different things about azure devops because it is there's a lot you can do with it and uh let's move on so so next up we're going to basically build and we're going to deploy this python web application to azure and in order to do that we're going to use pipelines to do that and so i'm going to go to pipelines i'm going to create a pipeline this is a really easy way to do it because you can go through this wizard and it'll pre-populate what's called a yaml file and i will do a video on deep diving a yeml file so you feel comfortable with those but in any event let's go ahead and fill this out so where is our azure repo right it's git based and it's going to be in azure and notice it has my repo already present it's already done some detection and determined that it was python it's a python web application and i want to deploy that to a linux web application in azure so i'm going to select the second option notice on the right it pops up with my subscription information so this azure devops portal is tied with my tied into my subscription and so i'm going to select that i'm going to hit continue and i need to authenticate into my azure subscription so i'll do that now okay i just finished that [Music] cool so now i get to select the web app and so i'm going to choose that azure web application that i provisioned earlier which is restmax 7. now validate and configure and this is going to automatically generate that yml file i talked about could i do all these tasks manually within the yaml file yes i can is this a lot easier absolutely but it's important to note that i can make a lot of changes to this yaml file if i need to tweak it or add functionality to it but essentially what this is going to do is it's going to build the web application and you can see it's in stages i'll talk about stages later on in a different video but but it's going to go through what's called a build stage and it's gonna build build this uh project into an application and it's then gonna deploy that application to my azure web app so again not gonna get into too many details the only thing i will talk about here is trigger the trigger is bait is a pretty important piece to an azure pipeline so so if i make a change to the main branch for example i'm going to change out to main right because it's my main branch but anytime there's a change made to my repo in in azure my devops repo if there's a change made like if i were to make a change locally and push that change this trigger means that every time that change is pushed to my azure devops repo this pipeline is going to run so that's where you get into those terms you might have heard before like continuous integration continuous deployment again i'll dive into that like in future videos but i want i do want to stress that the trigger main is important so the end result here is when i click save and run on this file it's going to put this pipeline azure pipelines yaml into my repo i'll show you that and i'm even going to rename it so it's cool as you can rename this stuff so i will call it rustmax hyphen pipelines okay what's going to happen is when i click save and run it's going to it's basically going to kick off and i can do a commit message and notice commit directly with the main branch that's what i want to do save and run and now you can see under pipelines my pipeline is currently it's about to be triggered right right now it's not started but what should happen is this pipeline will kick off but let's go over to repose so i can show you that file is present so notice my pipeline gamble is now there so when i make a change to this code locally within vs code and then i go through the process using git i push that into this branch this is going to kick off that pipeline okay so let's go back to pipelines and notice it's still running here let's see still going what's cool about these jobs are these jobs you can get some detail while it's running and see where you're at so it looks like the build stage has completed successfully it's just about done and then the next step is obviously going to be to deploy that to my azure web app ah it's cool it's finished and one important thing is during the pipeline run notice it creates this artifact and that's actually it's it packages the application and into a zip file and now it's deploying let's take a look all right great it finished let's take a look so green checks are good if you do get errors don't get discouraged uh what i would recommend is to go ahead and look at uh details around that error and go use being and figure out why or google and figure out if others have experienced those errors and and keep at it but in any event it deployed successfully so let's go to azure and and test this out and see if it actually works so this is the original url uh for this azure web app and what i expect to happen is when i hit refresh it should actually show me the new page with with the return statement that i had and there it is so cool so hello this code was updated locally and pushed azure developer repro so awesome so we've come full circle if you follow follow along uh definitely recommend it get your hands on this get get used to it but but essentially this is going to take you through that whole process i mentioned getting cloning that particular repository from github or wherever you want getting that local make your code changes pushing those code changes into an azure devops repo and then creating your pipeline and i will go into more detail into future azure devops uh sessions and you'll see why azure devops is such a great solution for managing code and and ensuring that your development project teams work together in a cohesive manner okay that brings us to a close here are some resources and i'll see you next time you
Info
Channel: Russ Maxwell
Views: 7,605
Rating: 4.9370079 out of 5
Keywords:
Id: fUlJU_frxl0
Channel Id: undefined
Length: 25min 57sec (1557 seconds)
Published: Sat Nov 07 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.