How To Deploy Machine Learning Models Using Docker And Github Action In Heroku

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys in this video i'm going to deploy a machine learning application into a cloud server like heroku with the help of dockers and github actions okay now get up actions whenever i say i'm basically talking about ci cd pipeline that basically means as soon as i commit anything from here automatically deployment should happen into the server and before that i'll also make sure that i will try to dockerize this entire application that i've actually created now right now here you can see this is my machine learning application a simple machine learning application and this machine learning application is nothing but boston house pricing data set we have basically used so whenever i dip i probably have created a front end wherever i put inputs and predict it it is going to give me the price of the house so first of all let me quickly run this and again guys i've created many this kind of project video so you can definitely watch that but here i've directly written the code you know probably done the exploratory data analysis and all so if you really also want to refer this definitely refer it from the github okay but i'm not going to implement this because i've done it many number of times so first of all uh if i just go and write python app.py here you'll be able to see how my output will look like okay so it is running let's see so for for the first time i think it will it'll take some time anyhow uh i'm just going to run this 127.0.0 here you'll be seeing that my application will look something like this okay so my application looks something like this so here i'm just going to put up some information like this okay let's say i'm putting up all the information like this over here and if i probably do the prediction and this is right nine localhost right and i'm going to get the prediction something like this okay now what i'm actually going to do is that i'm going to basically deploy this i'm first of all going to dockerize this and run it as a dockerized container okay and what is dockers and all i've already created a playlist on to that you know just understand that dockers saves a lot of time with respect to configuration setups and all right because entire configuration is basically made within a docker image and that can be run as a container anywhere let it be your operating system or something cloud server wherever you want you can basically do it okay so what i'm actually going to do again i'm going to minimize this let me just do control c now let me just show you first of all this step we will try to create a docker file now in order to create a docker file it's very very simple not that difficult to create a docker file itself all you have to do is that is within this just go and click over here write docker file and make sure that you use this same naming convention then automatically vs code will be able to determine whether it is a docker file or not now with respect to the docker file whenever we create the first thing is that understand what exactly is docker image here with the help of this file whatever information i am actually writing it actually creates a docker image okay and that docker image can be taken and it can be run within a container which we specifically say it can be run as a docker container in any operating suppose if i also want to run in my local it we can run this entire docker image as a docker container which will be interacting with the kernel of our operating system okay it is not like a virtual machine but you can just understand it is a kind of container which can independently run uh by communicating with the kernel of the operating system now in order to create a docker image first of all there are some commands that we'll be using one is from command okay now what is this from command i will discuss the next command is something called as copy command copy okay the third command is something called as work directory command the fourth command is something like run command and fifth command is nothing but expose command and then finally my cmd command now the firm command basically says that whenever now see why why docker is so super important guys suppose let's say if i don't probably create a docker with this application and if i want to give this same application for my friend to run it right so what my friend will do whatever installation i have done whatever setup i have done whatever library setup i have actually done he has to do all those steps manually right and because of this what may happen is that he may face some kind of errors or issues so that is a major problem over there like you heard this saying right when when uh q is working right suddenly let's say when developer is working in the developer in in a developer machine suddenly deploy the code into the qa machine when the queue is basically testing they'll say oh something is not working developer says that oh it is working fine in my system so what is the main issue over here there may be some kind of configuration some kind of dependencies come with some kind of hardware issue or some kind of operating systems issues also right because let's say i am running an application in windows machine suddenly i deploy that in a linux machine i may get some kind of issues over there also right so docker helps us to prevent that because here in the docker image we will make sure that we have all the base configurations set up then and there and we'll try to use that same base configuration in every machine we want to deploy it okay so first command is from now this command is basically used to select any kind of base image okay now as i said that see docker container also requires some base image base image means that okay we can have a linux operating system on top of that installed something right so suppose if i write from python uh 3.7 so what this is going to do is that i'm not going to use alpine okay alpine is again another different version okay of base image now as soon as i write python 3.7 when we are building this docker image it will go and take out the base image from the docker hub wherein it will take probably this python colon 3.7 basically means it will take a linux base image and on top of that it will try to install probably let's say a python 3.7 is installed it is going to take that particular base image and it is going to do the necessary other configuration settings so in short what happens as soon as i write from python 3.7 all it is going to do is that from the docker hub because all the images are present over there it will take that particular base image which has linux on top of it python 3.7 and then it is going to do the next step that is copy copy basically means whatever code i have in this repository see all these four files that i have in the repository i need to copy within that particular base image right all these files within that base image so for that what we will do i'll just say copy from my current location from my current location to a location which i am going to name it as app so that basically means i am going to create an app folder within that particular base image which will be copying all my local content to that particular app folder okay and then the next step is that i'll create that as my working directory so here also i have to give my same location okay this is super super important three steps from i've taken my base image i made sure that i copied all the content all all my code from here to a app folder inside that particular base image and i'm making that as a working directory now the next thing is something called as run now see guys here also whenever we learn any machine learning application there will be some dependencies in this particular requirement.txt if you are doing a javascript project you probably have to install some of the packages and all so i need to install all these things before going ahead so for that i will be using this run command now inside this run command i will write pip install minus r requirement.txt right so this will do all the installation order dependencies will get installed over here finally i will go and expose now see inside my docker image when that docker image is run as a container right in order to access the application inside the container we have to expose some port then only we'll be able to access that particular entire url right because from that portal you will be able to access that application so we are going to expose a port within that particular docker container and that port i will just write it as a placeholder which is called as dollar port why because this value when we are deploying into the cloud or server right it is going to the server is going to automatically or the cloud is automatically going to assign this particular port in that container okay so this is the next command and finally i will run my uh command which is basically used to run my web application or in this particular case my entire applications for this i'm going to use g unicorn okay g unicorn actually helps you to run the center python web application inside the heroku cloud itself so here i'm going to assign four workers workers importance is too much right workers what it does is that it whenever a request is coming into the application it will divide based on the instances okay it is let's say a thousand requests are coming so if i'm using four workers it is going to take 250 requests with one 250 another like that parallely different types of just to make that particular process uh easy right then i'm going to also bind now this ip address will be the local address in the hereku cloud and then i'm going to assign with port and this will basically be my app file along with that app file so see over here this app file is basically the file which is where i have to run my application inside this this will basically be my app name right so that is the reason why it is written app colon app app colon app basically means we are just going to take this particular file inside that we are going to run this okay so app colon app will be basically the entire process okay so we are just trying to run the first file over there and over there app is basically my file name that is present inside this okay so that is what we are going to do so this is what is the entire configuration over here what this binding is doing this is super important guys see understand about this particular binding very very important this port number whatever we have exposed in the container that will be getting binded to the local ip address whatever local ip address we will be getting in the heroku club right so that particular local ip address so it's just like a local host at a 0.0.0 i know it is 127.0.0 in our machine zero point zero zero point zero we can assign it over there and this port whatever port here is uh assigning in the container will be able to access it over here okay very much super clear very much simple g unicorn is definitely required whenever you try to deploy anything in the heroku cloud platform okay simple simple and easy okay now this is done this is my docker file now the next thing that i'm actually going to do since i also need to make sure that i have to configure my github actions okay now in order to configure the github actions whenever you want to configure github actions considering ci cd pipeline two folders needs to be created one is dot github and the other one is something called as dot workflow oh sorry workflows okay workflows now why i have created this file because as soon as i deploy i push push this entire code into the repository github repository you know when they seize this particular thing github workflow and inside this i will also create a file which is called as main.yaml file this will have the entire process as soon as i commit what all things we need to do first thing is that we need to build this docker file build this docker file basically means the entire image needs to be built and then we have to push this image in the form of a container to the heroku platform okay so the entire configuration over here will be set up in this main.yaml now guys uh this kind of main.yaml we don't uh write everything from scratch they're already available some people have already written this i'm just going to copy and paste it over here but just understand what is my workflow this main.ml will define the entire workflow okay so here i'm just going to say your workflow name this is deployed to heroku for in which branch it is basically on as soon as from here any push command goes on to the main branch then what will happen is that this entire build process will start main thing we are trying to do is build push and release the docker container to heroku okay so it will run on the ubuntu latest it will take a ubuntu operating system and do this entire process over there but here you will be seeing that you require three main information one is here email api api and heroku app name now this three information are super super important now the thing is that where do i get this specific information obviously from the heroku itself right so heroku here you can see that i have logged in let's say i want to deploy inside this boston house pricing one okay now if i want to get this information this are my secret keys that is available that needs to be provided in the github actions so if i probably go over here in just a second if i go over here and probably let's say i'm going to my hostel boston house pricing now if i go to settings okay in the settings there will be something called a secret because i have to make this as a ci cd pipeline as soon as i push my code to this github repository so i have to add some secret keys now click on secrets click on new repository secret and here i will basically write my new repository secret the first repository secret is basically let's say i want to add heroku api key okay so i will go over here copy and paste hello api key now where do i get my heroku api key just go into this dashboard of heroku go and click on account settings and here if you go down here you'll be seeing api key just reveal this copy this entire thing and paste it over here okay so i'm just going to paste it over here so this will indicate that which hiroku app is my information like i want to deploy i want to sorry this will indicate which account i'm actually using in hiraku okay so as soon as i click this a secret key is adding added but we need to still add two more secret keys so i'm just going to click on new cpr uh new secret key over here and now my second secret key will be what uh it will be hiroku email the hiroko email will be the same email id that i'm using for my heroku uh web app sorry dashboard so it will be krishna 06 at the rate gmail.com this just to give this configuration so that my deployment will happen successfully okay as soon as i do any push to the github repository so this is my heroku email now similarly coming to the third one it is heroku app name now here app name is super important because in which app i need to display deploy my code right so here i'll be writing europa app name and again i will go back to my account and let's go back let's say i want to deploy it in this boston housing pricing right so i'm going to copy this i'm going to paste it okay i'm going to paste it over here now here i will just go and add this secret so this all information is perfect uh we have added it now what will happen see we have set up the github actions that basically means as soon as now i deploy anything over here right right now you can see there is no github workflows folder only it is present over here right now as soon as this folder has been seen and whatever file is basically written over here all these things will get deployed all these things all this process will automatically happen in short the build push and release of a docker container to heroku will happen automatically from the github repository itself okay and this is super important this build push and release because there will be many people who will be working in a team right and many people may commit multiple things right and every time if a bullet build push and release actually happens then every time you'll be able to understand what error is actually happening someone may do some kind of errors over there so every time this build will be a very important step to go with right this is what we basically follow in real world industries where we are specifically moving our content from development to staging staging to pre-broad pre-brought to production you know so with this kind of containers we'll try to create and we'll try to push it okay so this is done now let's go ahead and open my terminal now as usual i'll go to my environment and now i will add everything that i have actually done so get ad if i probably see get status you'll be seeing this many number of files has been created okay and i'm just going to push this okay let's see whether i have missed anything as such no no no no no nothing um no no no no no okay uh everything is here perfectly fine okay now i'm going to just push everything oh sorry before that i need to commit the snapshot so i'll write minus m now i'll say dockers and github action uh changes commit okay because i have initiated this so this is done now all i have to do is get push from origin to i don't have to write to push from origin to main so you can see that everything has got done now as soon as i open github right now see what something amazing will happen okay if i reload this some orange color will come over here see okay now let's go and see the commit so here i will go and click it now you see this entire details automatically this entire deployment is happening okay something went wrong input required and not supplied hiroku app name so something wrong is there so let's go and see what is the thing that has gone wrong here app name i had actually provided it but i don't know what happened okay okay see app underscore name should be there right so let's do it again uh i'll add a new repository secret okay uh new repository secret i will go again back to my optional over here let's see this was the entire app name right i wrote only app underscore name okay so now here app name is nothing but house pricing dot this okay so because of that it failed see this because of that it failed right we will fix it don't no no need to worry we will fix it okay so now i will just copy this and i will add my secret add secret perfect now let's build or rerun this rerun this job rerun all the jobs okay a new attempt of this workflow we are including all the jobs yes we run these jobs okay either you can rerun it or either you can do this okay so now you can see build has actually started okay so the build has started the job is started here first of all it has taken the ubuntu whatever configuration we have given now see every steps even building of the docker will also automatically happen right every steps will probably happen over here pull commit this download verifying checksum see this copy process is again happening working directory changes is automatically happening this is quite amazing guys this pip install is basically happening and all the steps are happening you can see over here right all the requirements are getting installed see this build process you did not do much anything right automatically these things are happening that is the power of cicd pipeline that is the reason why devops and mls jobs are heavily required in every companies you know this process with respect to every project you have to do right so this is going to take some time anyhow i will just uh wait till all this installation will take place and then we will again start the installation okay sorry we'll we'll automatically see at the end of the day when this entire thing will happen it will get pushed to this particular housetown uh hosting uh sorry boston housing price app itself and then once you open the app they will be able to see the output okay so let's see okay still happening layers already exist pushed pushed pushed that is going to probably take some time because there are many files many installation will take place this entire process will get run if you get any errors you can again rerun it try to always get errors if you get errors that basically means you will be and if you are able to solve it trust me you are able to learn in an amazing way okay so post post post now i'm just going to pause it and once it is pushed we will try to see the application okay so i will just come back in some time until then i'm going to pause oh see okay releasing container okay releasing container all the steps you'll be able to see and please note down all these steps guys these steps are super important whatever things we have written in docker everything is happening because this is now getting created as a container now finally you can see my job is completed i'll go over here open the app let's see still nothing is working okay you can also check logs if you are probably finding any issues in boston house pricing okay and ta-da it's here and let's now go and execute it okay let's go and execute it here you go here you go here you go here you go and now this entire thing is running in a docker container if you don't believe me i'll show you that also i'll show you that proof once i predict it this is my output it's working absolutely fine if i probably go over here into personal here you'll be seeing now it is running as a container see before if you just deploy a python application it will look like this but if you are deploying it as a container you will be able to see like this okay so i hope you like this particular video of deploying your data science application into heroku cloud with the help of dockers and github actions try in this particular way and please let me know whether you want a complete series of videos with respect to dockers and github actions i will try to upload it but for that i require 1000 likes for this particular video so yes this was it from my side i'll see you all in the next video thank you bye take care
Info
Channel: Krish Naik
Views: 46,004
Rating: undefined out of 5
Keywords: yt:cc=on, how to deploy data science app using dockers, github action tutorials, machine learning deployment using dockers and kubernetes, ci cd piplines in data science, deploy ml model as rest api, deploy ml model on heroku, github actions deploy docker compose, ml model as api, use docker container in github actions, krish naik dockers, krish naik github action
Id: Gs15V79cauo
Channel Id: undefined
Length: 21min 56sec (1316 seconds)
Published: Mon Jul 25 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.