From Github to ACI – A tale how to use Visual Studio Team Services & Azure Container Registry for Container CI/CD

Introduction

Today’s post is conceptually a rather simple one… Let’s see how we can go from this ;

To here ;

By using a CI/CD pipeline.

 

Flow of the day

What will we be doing today?

  • Kick-off a VSTS build once a change has been made to our Github repo
    • Build a container via VSTS
    • Publish the container to an ACR (Azure Container Registry)
  • Kick-off a VSTS release once the build succeeded
    • Use an ARM template to deploy an ACI (Azure Container Instance) with our docker container underneath

Sound cool? Let’s get to it!

 

Deepdive

Let’s take a look at our build flow… So we’ll start by trigger. We’ve enabled “Continuous Integration” and trigger the build flow upon every change made to our repository.

The first step will be to retrieve the sources from our repo ;

Next we’ll build the image ;

This can be done by a default VSTS task ;

Likewise for the task that publishes the newly build container to the ACR ;

For both steps we used a “Docker Host Connection” ;

Now what is that “Docker Host Connection”. Basically a host with docker installed upon it, which can be reached by the VSTS build agent. Looking what to provide in the following configuration … Check out this page.

Now if the build succeeded, then we can kick off our release flow. As an input we’ll be using the “build artifact” as trigger for our “Continuous deployment” ;

In addition, we’ll link the github repo so we can use the ARM template for the deployment of the ACI. The parameters file has been set-up with “tokens” that can be used in the build ;

These tokens have been configured in the “Variables” section of our build ;

Which then will be used for the “tokenization” of our parameters file. Basically, each token will be used to do a lookup in the variables name, and then replace by the relative value.

As you might have noticed, the “image”-variable includes the build number. This build number was used as a tag for the image in the registry ;

Now let’s use the template & parameter file to do the deployment ;

 

CI/CD Demo Flow

So let’s see how that all ties together… First the build kicks in ;

Afterwards our release ;

Which created a resource group with an ACI inside ;

The ACI is running nicely…

And published to the outside world!

All done! Whoot. 😀

Advertisements

3 thoughts on “From Github to ACI – A tale how to use Visual Studio Team Services & Azure Container Registry for Container CI/CD

  1. Hi,
    Excellent post. I was trying it out but I am stuck. So in build step, I added Build an image and Push an image and the variables. My builds are successful but in Release it says “Latest version has no artifacts to publish. Check source control.”
    Build is generating an image and pushing it to ACR. But release are failing coz it cannot find template file from Build Artifacts. I checked adding “Push Build Artifacts” in Build step and it says
    “Total files copied: 0.
    Directory ‘d:\a\1\a\TestArtifacts’ is empty. Nothing will be added to build artifact ‘TestArtifacts’.”

    Any idea where I am going wrong?

    1. Either package the template file (advantage versioning) or you can link the source as artifact (advantage easier to setup).

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s