Azure Pipeline to Create Docker image & Upload into ACR | Azure Pipeline Upload Docker image to ACR

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
we are going to learn how to build azure build pipeline in order to build the docker image and then push the docker image into azure container registry so if you look at this diagram i have my source code set up in github this is a sample python based application i also have dockerized that python based application by creating this docker file so what i'm planning to do is i want to build the docker image by building azure build pipeline and then upload the docker image into azure container registry it's a very simple use case okay so that our pipeline right it should be able to automate the bill process and then it should also build the docker image as well as upload the docker image into azure container registry okay so that's what we are going to learn in this simple video awesome so let's get started if you look at the pre request yes we need to have azure container registry setup which i'm going to do in a minute okay so i'm going to use uh azure cli okay i'm going to use that in order to create azure container registry and then if you look at the second step we need to have azure devops dashboard so so this is the azure devops you know project dashboard i'm going to use so i'm going to build azure pipeline in this project dashboard okay and then we already have uh you know a sample project setup so if you look at here this is my sample python based code i do have a docker file already created right so this is a docker file so we are going to dockerize this python based application and then build a docker image and then upload the docker image into azure container registry so that's exactly what we are going to do in this video awesome so let's get started we need to first create uh azure container registry right so we need to create acr so like i said i'm going to use um azure cli okay so i have already installed azure cli on my machine okay so i have already installed azure cli so what i'm going to do i'm going to first login into azure cloud um so i'm typing ac login this is going to login into um azure cloud perfect so i'm logged in now okay perfect so now we are going to create azure container registry but before that we need to create a resource group okay so i want to create a resource group with this name and then i would like to use south central us okay so i'm going to copy this command and then go ahead and then execute it so right now my resource group has been created okay perfect and then i'm going to go ahead and then create this container registry right so basically i would like to name my repo as this name so make sure this should be unique right make sure you know this should be unique okay and i of course i would like to use south central us location and then i would like to create acr under this resource group name okay so let me go ahead and copy this command wonderful as you can see here uh you know the repo has been created and if you want you know you can login into azure portal and then verify that that's not a problem so let's quickly validate that let me quickly log into azure portal uh okay so that is my portal so this is the resource group which we just created uh it might take few seconds to show let's see or you can also search um all right let's see azure container registry wow there you go you see here so this is our acr what we just created okay perfect right so everything is good all right so let me go back to my instruction here perfect so we just created a azure container registry all we have to do is you know build a pipeline that pipeline should be able to check out the code from github and then it should create the docker image and then push the docker image into acr okay so that's exactly what we are going to do awesome so let's get started so basically what we have to do is uh we need to log into azure devops dashboard and then create a build pipeline right so this is my azure devops dashboard so click on pipeline ah click on new pipeline uh i'm going to use actually classic editor of course you can also you know build using ammo file as well but i want to keep it very simple so click on the classic editor and where is my source code my source code is in github so i'm going to click on github and we need to authenticate so click on new service connection i would like to authenticate with github personal access token so let me quickly create the token go to settings developer settings personal access token let me generate a new token i want to keep it seven days give full control that's fine this isn't temporary i'm going to delete the token right after this video so no one would be able to use the token so copy the token and then enter the token so that azure devops can authenticate perfect now i was able to authenticate i'm going to go ahead and then choose the repository so what is our repository name that would be my python repo this one so copy that enter that there you go so select that and then this is the default branch i'm fine with that the branch name is master perfect so go ahead and then click on continue awesome perfect right so now we are going to select the template so basically what we are trying to do is like i said we want to build a docker image right so all you have to do is just type um or you can also choose this you see here build a docker image and then push into a container register right so we are going to select this template okay go ahead and then click on apply perfect right so now as you can see here uh pipeline has been created with these two tasks populated right and then if you like to rename the pipeline you can click on this pencil mark and then rename the pipeline right so i want to say my awesome pipeline right so you can give any name it doesn't matter i want to give my awesome pipeline job perfect and then we need to kind of configure our pipeline right let's see what is this yeah so basically okay so it is asking for the agent yeah you know you can select any agent doesn't matter uh let's choose ubuntu 18.04 that's fine and then we have to customize uh these two jobs and then of course we are also going to add you know few other jobs as well perfect so if you see here uh we need to uh you know choose the azure subscription so click on available subscription and then i'm going to select this one because i am under psego uh subscription so i'm going to use that okay and then click on this one there you go you see here so this was the repo what we had created in azure portal right so you just have to select it but if you are actually doing for the very first time it may ask you whenever you choose the subscription it may ask you to enter microsoft credential then you can go ahead and then provide that microsoft credential so that pipeline can authenticate and then you know you should be able to select your azure container registry right from the drop down okay perfect and then rest of the things i'm going to leave it as it is right i'm going to leave it as it is it is going to build a docker image perfect and then the second task is once you build the docker image we want to upload into uh acr right so let's select the same subscription here perfect and then go ahead and then choose uh the acr perfect so that is also good okay um and then uh you know what we wanted to do also right so we want to build a docker image upload into acr but but think about this right you know we want to build this docker image and then eventually we want to deploy this docker image into our kubernetes cluster right so so it is also important that you know you you uh you know copy the deployment ammo file as well so if you look at here maybe in the next video i'm going to show you uh how to deploy this docker image into aks cluster right for that we need to uh you know use this aml file right we need to use this aml file so what i wanted to do i want to add a task in my pipeline so that you know while building the image itself you can also copy the ammo file as well right uh so that it is available for for your pipeline right for your release pipeline to pick up the aml file from the build pipeline right so we need to add a task so how to do the task so i have provided instruction over here if you see here so we need to go ahead and add this particular task right copy files to so let me go to pipeline here and then click on add i'm going to say copy and then we are going to copy add this particular task okay and then uh so basically uh source filer is fine so what we wanted to copy you can actually select here right so basically we wanted to copy this particular file right because this is the file you know which is going to have our image information everything right so so i'm going to copy the file name and then mention that file name here and then where it's supposed to copy so i want to let's say copy into my target directory so that's fine i think i think that that is perfectly fine i think you can say like that okay let me just verify everything is good or not so this is good this is good right so perfect okay and then once you add the task we also need to publish the file as well so i'm going to go ahead and then add a task okay so look for publish so i'm going to select this particular task okay perfect right and then what this is going to do this is going to copy the files into uh you know respective location so that our pipe end can actually pick up right azure bill pipeline can pick up right so let me just make sure perfect i think everything is looking good so now what i'm going to do uh so we made sure all these four tasks have been added and then configured so now i should be able to build the pipeline so i'm going to click on save and queue so click on save and queue and then click on save and run so now our pipeline is running so click on this uh you know job agent job one so we should be able to see that you know pipeline should be able to check out the code should be able to build the docker image and then upload the docker image into acr okay as you can see here it is building the docker image by reading the instruction from the docker file as you can see here wow so our pipeline has been uh you know completed uh it has run successfully right so now i should be able to uh see the docker image into acr and this is also complete right like docker image has been pushed into acr so how do i verify that so yes let's login into our portal click on our container registry and then go to repositories see here so this was the image right so look at that 1 26 p.m central time so that's the time you know uh it was able to uh you know upload the image and this is the tag right and then this is the kind of a docker pull command right so if you want to download the docker image this is how you know you can download the docker image from acr right so yeah so that's it guys you know that's how you would uh create a azure build pipeline for for building the docker image and then uploading the docker image into azure container registry maybe in the next video we will learn how to deploy uh this docker image into aks cluster thank you for watching
Info
Channel: DevOps Coach
Views: 15,476
Rating: undefined out of 5
Keywords: Azure DevOps Tutorials Azure Build Pipeline
Id: XyVLQhDhQTU
Channel Id: undefined
Length: 15min 1sec (901 seconds)
Published: Fri Oct 29 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.