Learn how to use Gitlab CI/CD building a Flask API

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so we're going to build a simple flask API and dip and use people up due to continuous CI and probably deployment so let's begin by creating a simple update py file which is going to house our flask hub so I've already installed flask in white um so we shall just import from blossom with that we can create a simple app such we have that we can add a route this world will simply I will simply return hello okay so let's try to run that they funded they've enacted p1 you kill that should be running however you judge bought this as the flask up and use flask the Tran look at the addresses already news let's see let's kill all the instances six seven zero six let's run the flash cutter again so we now see a flask uh 24 2012 jack localhost 5000 should be getting hello okay so that's good one more thing we ought to make our environment [Music] development so that we can have auto reload let's first kill this stamina export the flask up again update py and also add another environment variable for the flask environment which we shall see just development only that we can run the flask up again so you do now see that our environment is development meaning we can get factories whenever the scale change now the purpose of this is to show you how to have Auto CI built into our project using it up with that we need to automate some tasks and in this case we're going to automate our testing it's just a monkey so if we're to run tests let's use that in build tests Rana give me tests create a class called tests which made from unit tests that testicles so we can start adding artists method here so we're going to add an in point where a user a user passes where a user passes two numbers and the end point returns the summation of those two numbers the sum of those two numbers so we shall call this testament at test son last night [Music] you let's try to do something yes of +5 that time should be good name so let's open another terminal tray drag that test you do if it'll turn you dr. Khanna an artist and we see how a test is running so we've set up artists early let's proceed an ad with this given movement we'll expect to have probably a method called Sam in our now update py that method expects to receive two values and returns to summation so if we run this test again it fails because we do not yet have a that method implemented in after di so if we're going to update UI we add that method and XP so should we run a test now it passes okay so that's good next thing is to add an endpoint called calc so with this I shall make this this endpoint of post make it a possible gate let's make it a gift whether request AG arguments and we so we will pick we'll pick our values from the axe so expect an argument in there and we expect to find every argument an argument past old P once we have that we can sum the two values and return the answer so with that let us test see box you and be use six it's called and coke okay so we do see here it just concatenates so I want to make sure it actually adds so I shall make this int last this we try this again okay not a valid response why the view function the return type must be scale digged up low but it was I need let's make sure that our return type here with string so there we are once you pass to a dimension a and B result is some the the values are summed and the result is returned as a string okay so that is good now let's let's consider this as our API and let's start adding its that adding some functions that we're going to ultimately not get lab CI for example lips so you've noticed that we are running our tests using Python this dot py let's push it another gitlab CI 2 TM so I'm writing it get labs EMF and start with the stages expect to have so here we'll have one stage which is called test then you go stitch down here so with each stage you can either choose to use one image for all the stages or you could have an image pass stage since gitlab CR and Italian no compiled and on dopa images so in this stage you're going to use the latest python image the latest - toca image stage man is we have a job essentially a CI file consists of it trans a sequence of jobs and those jobs can be can be broken down into stages so we have a job yeah called just let's call it a stab and it will be under the test stage so we could have had another stage here probably called lint and maybe we will have probably linked up here a job called lint up and then something under there but let's first deal with the tests so we decided we will have a test stage and we are going to have a job called test up so before we ran our before we ran our Python test to see why certain things we need to do still do this print out the Python version that's for debugging in case something goes wrong and let's install our batch Oh F with that installed we create a batch around activate it that install install flasks name-brand our just to 2py now this is what will happen when Gillibrand our CI 5 now that we have that we need to make this a repository let's do get in it let's add it it ignore file get it there's certain things we need to ignore here like that be as good folder which is specific to my local report a valve holder it's the virtual environment one can always install the virtual environment and their machine so if you notice every every fold our ignore will be grayed out here in vs code so that's one trick to notice once we have that if we do get status you will see that we have the following files that are untracked now there is also this pie cache folder which sugars a big nod I'll get status and it shows us ticket ignore update py get labs GI file on test so let's proceed let's go to get lag and creating a project so if you haven't signed up to get lab it's easy to sign up you can even easily do that using your Google account or github account so let's call this flask API Simcoe last KP I will make that public then we'll create a project so as we had that it lab showed us how we can too an existing repo take this and we add now a local copy so now let's first add every file that's unlocked with an initial commit and push so very chain master so if we refresh yeah [Music] okay why isn't our pipeline running oh yeah this keeps lab dot CI file is actually supposed P dot it labs the a file so let's change that let's commit fix and get clogged CI we are not file naming let's push okay we need to do the second push origin master refresh here see a build has been set off because you now have the CI file correctly named in our repo let's take a look at this a pipeline is a bill that is set up whenever you push a commit to get lab and the pipeline consists of a sequence E of jobs so in this case we only have our one job running you take you get LeBron is the application that runs our jobs and here it's using the toka image that is specified in our test stage Python latest so it's collected the voucher and it's treated a voucher and it's activated it it it's better installed flask and it has run our command to run the tests now up on the job has succeeded so see we have a green pipeline has passed that's how you can easily add automation for your get lab CI repos
Info
Channel: Albert Luganga
Views: 5,094
Rating: undefined out of 5
Keywords: .gitlab-ci.yml, gitlab, gitlab-ci, flask, testing, API, ci, ci/cd, cd, cicd
Id: 72mJRniDEpg
Channel Id: undefined
Length: 20min 43sec (1243 seconds)
Published: Mon Sep 16 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.