The following article will help you set up Continuous Deployment to Azure using Buddy. Upon reading this guide you will be able to:
- Initialize Continuous Deployment on Microsoft Azure
- Create a pipeline in Buddy that will deliver your .NET app to Azure
- Configure Buddy to test your app before deployment
The problems of modern web development
Usually, developers write, compile and test code locally and then manually upload the package to the server. However, once the project grows bigger and more developers start to participate, problems begin to appear:
- Deployment preparation is getting more time-consuming as more time is needed for preparation.
- Software iteration is getting longer with every release, which results in less feedback from the client.
- Testing is more difficult as every team member has their own development environment.
- Team members need to communicate more often, increasing the risk of communication errors.
How CI/CD helps developers solve these problems
The issues above can be successfully addressed by introducing a build server and deployment automation to your workflow.
- The software is built and tested in one consistent environment, avoiding dependencies on local dev boxes.
- You save time on setting up builds, installing required software, etc.
- Having one centralized build server provides easy access to code metrics, making it easier to properly cover your code with tests.
- Automatic deployments allow you to release software and receive feedback more often with the whole process simplified to minimum.
As you can see, these are some serious advantages one shouldn't reject easily. The following guide will tell how to use Buddy to apply Continuous Deployment to your projects so you can benefit from all of the above.
Step 1: Synchronizing Git repository
Before you apply the Continuous approach to your workflow, we need to start with the basics: putting your files under version control. We firmly believe this is a standard practice in web development companies by now, but it's never enough to stress how imporant it is. In this example we shall use a preconfigured .NET sample project hosted on GitHub:
You can also use Bitbucket, GitLab, any type of a custom repository, or Buddy's fully featured Git hosting with code editor, branch management and merge requests.
Step 2: Setting up Azure
Let's automate your workflow in a way that every time you make a push to branch Buddy will deploy your project. First we need to set a couple of things in Azure:
- Log in to https://portal.azure.com
- Go to your web app's blade and click Overview. There will be a Get publish profile link on the top. Click it to download an XML file with the publishing data.
Step 3: Configuring Deployment in Buddy
Now, we need to create a pipeline that will push your files to the Azure repository. Pipelines in Buddy consists of actions arranged in a sequence and triggered on a push to branch. Let's create a pipeline for Azure:
- Add a new pipeline, set the trigger mode to On every push and assign it to the Master branch. This way the pipeline will be executed automatically on every push to Master:
You can also set the trigger mode to manual or recurrent if you don't want to update the Master so often. Read more about setting pipeline details.
Select the Azure App Service action and paste the following values from the downloaded XML file:
Make sure to provide the data from the publish profile with
Click the button Add this action to finish configuration.
From now on Buddy will deploy your project to Microsoft Azure every time you make a push to Master in your repository:
But are we sure the code that you send is properly verified for errors?
Step 4: Testing application before deployment
One of the basic rules of the Continuous approach is to make sure your code is thoroughly tested before deploying it to the server. With Buddy you can do that by running tests in pre-defined Linux containers that represent your developer environment. Since our project is a C# website, we shall use Mono, a cross platform .NET framework:
On the action manager view click plus above Azure and select Load Linux image from Docker
Go to the image settings and change the image from ubuntu to mono official. Click Update to save changes.
You can create .NET Core projects in Buddy as well.
By default, the following commands are executed:
nuget restore NetMvcExample.sln xbuild /p:Configuration=Release /p:DebugSymbols=false /p:TargetFrameworkVersion="v4.5" NetMvcExample/NetMvcExample.csproj
The first command downloads any packages missing from the packages folder. The second command builds the whole solution. 4.5 is the version of your .NET framework:
Click Add this action to save changes and run the pipeline to see if everything works:
Congratulations! We've just created a pipeline that on every push to branch automatically tests and delivers your project to Azure (provided the tests went through successfully). The pipeline is very simple: you can add more actions to the pipeline if you wish - for example a notification to your Slack channel - or read more on the concept of pipelines in our dedicated guide.