Azure and Git
Azure provides various services that can be integrated with Git to enable continuous integration and continuous deployment (CI/CD) of code. Here’s a general overview of how to set up Azure with Git and use it for CI/CD.
Prerequisites
Before you begin, you will need the following:
- An Azure subscription
- A Git repository (e.g. GitHub, Azure DevOps, Bitbucket)
Setting up Azure with Git
To set up Azure with Git, you will need to perform the following steps:
- Create an Azure resource group: This is the container for your Azure resources.
- Create an Azure App Service: This is the web app that runs your code.
- Set up continuous deployment: This enables Azure to automatically deploy updates from your Git repository.
- Configure Git deployment: This sets up the Git repository for deployment to Azure.
- Connect to the Git repository: This creates a connection between Azure and the Git repository.
Creating an Azure Resource Group
To create an Azure resource group, follow these steps:
- Go to the Azure portal.
- Click on “Create a resource”.
- Select “Resource Group” from the list of options.
- Enter a name for the resource group.
- Select a subscription and location for the resource group.
- Click “Review + create” and then click “Create” to create the resource group.
Creating an Azure App Service
To create an Azure App Service, follow these steps:
- Go to the Azure portal.
- Click on “Create a resource”.
- Select “Web App” from the list of options.
- Enter a name for the web app.
- Select the resource group you created earlier.
- Choose an operating system.
- Choose a runtime stack (e.g. Node.js, Python, .NET).
- Click “Review + create” and then click “Create” to create the web app.
Setting up Continuous Deployment
To set up continuous deployment, follow these steps:
- Go to the Azure portal.
- Navigate to your Azure App Service.
- Click on “Deployment Center”.
- Select “GitHub” (or your Git provider of choice).
- Sign in to your Git account and authorise Azure to access it.
- Select the repository you want to use for deployment.
- Choose a branch to deploy.
- Click “Continue” and follow the prompts to complete the setup.
Configuring Git Deployment
To configure Git deployment, follow these steps:
- Go to your Git repository.
- Navigate to the repository settings.
- Select “Webhooks”.
- Click “Add webhook”.
- Enter the URL of the deployment webhook provided by Azure.
- Choose the events that trigger the webhook (e.g. push, pull request).
- Click “Create” to create the webhook.
Connecting to the Git Repository
To connect to the Git repository, follow these steps:
- Go to the Azure portal.
- Navigate to your Azure App Service.
- Click on “Configuration”.
- Select “General settings”.
- Click “Configure Git credentials”.
- Follow the prompts to set up the connection to the Git repository.
Branches and Publishing
With Git and Azure, you can use different branches for different environments (e.g. development, staging, production). Each branch can have its own deployment configuration.
To publish changes to Azure, push the changes to the selected branch in your Git repository. Azure will automatically detect the changes and trigger a deployment to the Azure App Service.
It’s good to take into consideration that if a resource has not been published, it will not be visible or available to be read in any other branch. This is because the resource has not yet been created in Azure, and therefore cannot be accessed or interacted with.
So, if you have created a resource in one branch and have not published it, you cannot access that resource in another branch until you publish the changes. This is because Git uses a version control system, and unpublished changes are unavailable in other branches until they are committed and pushed to the repository.
In summary, Azure and Git provide a powerful platform for continuous integration and deployment of code.