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
Why do I need Continuous Deployment?
Usually, developers write, compile and test code locally and then manually upload the package to the server. However, once the project grow 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.
The problems above can be successfully addressed by introducing a build server and deployment automation to your workflow.
What does it mean for the development process?
- 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: Initializing Git repository
Before you apply the Continuous approach to your workflow, we need to start with the basics: putting your files under Git version control. In this example we shall use Buddy's fully featured Git hosting with code editor, branch management and merge requests. Here's what you need to do:
Prepare your project by packing into a ZIP archive. Alternatively, you can download and use our sample .NET project available here.
Create a new project in Buddy, choose Buddy as the Git provider and use the Import ZIP archive option:
- If you host your projects on GitHub, Bitbucket or GitLab, you can choose one of them as the provider when setting up a new project. If you're a GitHub user, you can fork our sample project from our profile and select it from the project list.
- If you're not familiar with Git, this guide will get you started.
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 the XML file with publishing data.
Step 3: Configuring Deployment in Buddy [Updated 17.01.18]
Now, we need to create a pipeline that will push your files to your Azure repository. Pipelines in Buddy are CI/CD actions arranged in sequence on 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 every so often. You can read more about setting pipeline details here.
Select the Azure 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 to test & add the action:
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.
In the command field enter the following:
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.