We are going to deploy a GitHub repo to Azure App Service and configure CI/CD for that repo through the Azure CLI 2.0 so if you’re not aware of the azure cli 2.0, I will request you to go to my previous blog posts here and here.
First we are going to list down all the steps required for it. The steps are as follow:
1)Create a Resource Group
We will create a resource group with the name githubdemorg and host it in location EASTUS
az group create –name githubdemoorg –location EASTUS
2)Create an App Service Plan
An app service plan is to define the size, location, scale count and sku of the app where you will be hosting it.
az appservice plan create –name githubdemplan –resource-group githubdemoorg –sku FREE
3)Create a Web App
We will create a new web app with the following command.
az appservice web create –name githubdemoag –resource-group githubdemorg –plan githubdemoplan
4)Create a Git repo in Github
If you’re not familiar with github, just follow the steps.
a)Go to Github.com and Signup/login with your Credentials
b)Click on Start a project
c)Create a new repository by passing a repo name and description and make your Repo as public. Also, Make sure that you didn’t checked the Initialize this repository with a README if you’re not familiar with github and blindly follow this demo. Click on the create repo button.
5)Push the Code to the Github
Go to your code directory and open a new instance of the command prompt for the git command and follow the new or existing repository on the command line according to the requirement.
For us, we did the new repository in the demo. Let me quickly walk through the commands.
It’s going to initiate a new blank repository in your local
git add readme.md
It is going to add a readme file to the repo.
git commit –m “first commit”
It is going to commit the code with the message in the double quote
git remote add origin url
It’s going to add the remote to the origin.
git push –u origin master
It’s going to push to origin git repo in the master branch.
Once you completed the above commands then go to your repo on github and check if the files got push.
6) Deploy Code from a public Github Repository with CI &CD
Inorder to setup the source control config, you need to authenticate your command line with a token and In order to get the token you need to go to github.com and then settings and on bottom left click on personal access token.
Click on Generate new token and enter the token description.
Click on generate token button on the down.
Copy the token generated in this step and use it in the next step. I have not used it in the screenshot below as I have already setup the token once and azure remembers the token.
az appservice web source-control config –name githubdemoag –resource-group githubdemorg –repo-url YOURREPOURL –branch master –git-token $token
Now check the site if the code is published or not.
7)Validate CI & CD
Now, to validate the CI CD Configuration. I am going to make a simple code change in my heml and append Updated to GITHUB DEMO and I am going to push the code to git hub and check the site again to see if the changes are reflecting or not.
Update the HTML File
Push the code to the github by using the following commands in your git cmd
Git add .
Git commit –m “new commit”
Check the site again.