Condividi tramite


Using the VSTS Packer Task and Replace Tokens Task

In my post How to continuously deploy web application to Azure VM Scale sets using VSTS and Packer? shell script tasks were used to bake Azure VM image using packer and to Replace tokens for VM username and VM password in the ARM template parameter file. In this post we will replace these shell script tasks by The Build immutable image (using Packer) task, and the Replace tokens tasks. As compared to the previous release pipeline the new release pipeline is much cleaner and much more easier to understand and manage.

In case you have not gone through the previous post the code and build file can be found at my github repo . Lets have a look at the modified release pipeline.

Release Overview

Build and Release Pipeline Overview

The first step of the release packages the latest application files into an Azure VHD image using the packer task, this VM image (vhd) is stored in the configured storage account. Next we use the replace tokens task to replace tokens in the Azure Deployment Parameters File. After this the Azure Group deployment task is used to push the new VM image (with latest application code baked in) to the VM Scale set. The last two steps are for UI testing (Using php unit and selenium in this case), and Load testing (using JMeter).

In this post we are not going to look at the UI Testing and Load testing tasks as there is no change to these tasks as compared to my previous post.

Please Note : The VSTS VM Scale Sets (VMSS) task is also available now, The deployment pipeline is even more simpler if the VSTS Packer task and the VSTS VMSS tasks are used together. See the Post on how to use these tasks together to bake custom VM Image and update VM Scale Set Image.

Let us look at the other tasks in more detail :

  1. Build immutable image using packer: In this step we use the Build immutable image task. We pass the path to the phpapp-packer.json file to this task. We will need VSTS Variables ARM_SUBSCRIPTION_ID, ARM_CLIENT_ID, ARM_CLIENT_SECRET, and ARM_TENANT_ID to be set. You can revisit my post to find out how to get value of these variables. Additionally we provide name of VSTS variable (IMAGEURI) to this task, this variable needs to be created in VSTS. Once the VM image is baked the task will save the image uri for the baked VM image to this variable (IMAGEURI). Screenshot below shows configuration of this task:

    Bake VM Image using Packer

  2. Replace Tokens Task: This task replace tokens in the Azure Deployment Parameters File with values from VSTS variables.
    Snippet below is from parameters file:
    "adminUsername": { "value": "@@VMUSERNAME@@" }, "imageUri":{ "value": "@@IMAGEURI@@" }, "adminPassword": { "value": "@@VMPASSWORD@@" }
    The replace token task will replace token @@VMUSERNAME@@ with value of the VSTS variable VMUSERNAME, similarly token @@IMAGEURI@@ will be replaced by the VSTS variable IMAGEURI value, which was set by the previous packer task.

    screenshot below shows configuration of this task:

    Replace Tokens

  3. Azure Resource Group Deployment Task: This task will update the VM Image associated with the VM Scaleset. The ARM template file azuredeploy.json and parameter file (where tokens have been replaced by variables by previous task) are passed to this task.

    Screenshot below shows configuration of this task:

    Azure Group Deployment

Thanks for reading my blog. I hope you liked it. Please feel free to write your comments and views about the same over here or at @manisbindra.