Book Image

Building Web Services with Windows Azure (new)

Book Image

Building Web Services with Windows Azure (new)

Overview of this book

Table of Contents (17 chapters)
Building Web Services with Microsoft Azure
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Introduction
5
Connecting Applications with Microsoft Azure Service Bus
Index

Continuous Deployment using Azure Websites


In the previous section, we used Visual Studio tools to deploy our Web API in Microsoft Azure Websites. The Visual Studio deployment option works well for one-off deployments or small development projects. However, in real-world scenarios, customers prefer integrating builds with automated deployments. Azure Websites provides continuous deployment from source code control and repository tools such as BitBucket, CodePlex, Dropbox, Git, GitHub, Mercurial, and Team Foundation Server. We can, in fact, do a Git deployment from a local machine!

For the purpose of this sample, we use VSO and Git as our repository. Let's take a look at how we can configure Visual Studio Online for our Continuous Deployments (CD):

  1. Go to the Azure portal and browse to the Azure Website we just created. From the dashboard, select setup deployment from source control. When using the new preview portal, this option will be in the Deployment section as Set up continuous deployment.

  2. Select VSO to designate the source code and then select the repository to deploy:

    Azure will now create a link to Visual Studio Online. Once the link is established, when a change is committed, it will get deployed to Azure Website automatically. The link creates a build definition for the solution and configures it to run in CD mode. If we go to the build definition in Visual Studio, we can see that a new build definition is added. The linkage also sets the deployment attributes for the build. It ensures that a commit on the solution triggers a deployment. Note that if any unit test projects, which are part of the solution will also automatically get triggered.

  3. Let's make a change to our existing sample to verify this. We will add a new attribute to our Package ASP.NET data model that we created earlier. This attribute will get populated with the current UTC timestamp when the package is created:

    namespace Contoso.Transport.Services.Models
    {
        public class Package
        {
            public int Id { get; set; }
    
            public Guid AccountNumber { get; set; }
    
            public string Destination { get; set; }
    
            public string Origin { get; set; }
    
            public double Weight { get; set; }
    
            public double Units { get; set; }
    
            public int StatusCode { get; set; }
    
            public DateTime Created { get; set; }
        }
    }

    We will also update the in-memory collection in PackageController to ensure that a created timestamp is associated with each record. The code for updating the controller is left as an exercise.

  4. When we make a commit and push to the Visual Studio Online repository, the build definition will invoke a new build, which will also update the deployment in our existing Azure Website. This can be verified by looking at the build report:

  5. Now, if we again call the same end point, we should get the Created attribute as part of the response:

    Request

    http://dotnetbook.azurewebsites.net/api/package/1

    Response

    {
        "Id": 1,
        "AccountNumber": "48e89bcd-cfaa-4a47-a402-9038ca2dd69b",
        "Destination": "TX",
        "Origin": "CA",
        "Weight": 2.5,
        "Units": 1,
        "StatusCode": 1,
        "Created": "2014-09-14T22:17:32.8954157Z",
        "History": null,
        "Properties": null
    }

Our Web API is now successfully deployed in Microsoft Azure Website and configured for CD.