In this post I’m gonna explain how to set up a custom agent and take profit of that machine using docker images and containers for running more than one agent instance in that machine. The information I’m showing in this post could be useful for your time if you use VSTS, you define CD/CI tasks, automatic testing, etc… as the team and project is growing you can run into a bottleneck scenario where pipe tasks expend more time than desired queued waiting for a machine to run.
When you define a build pipe you need to select an Agent Queue where the task related to the build will be executed.
Agents Queues are a collection of machines within the same capabilities. If you press “Manage” button you see in the picture above you will be redirected to the Agent Queues Management Page where you can see default queues, check capabilities and create your own queues and bind new machines to queues. VSTS provides oob different Queues with different capabilities. You can use it for free (free quota per month) and this queue is shared with other vsts users.
You can bind any machine, you’ll need to install capabilities and run a vsts service to act as an Agent. In the section shown in the picture above you’re able to create new Queues. If you press Download Agent you will get the instructions to install capabilities and how to run the vsts service to act as agent for different platforms. You will find a lot of official tutorials explaining this scenario, I’m gonna skip this part, the interesting topic I want to show is described in next section.
Microsoft has a github repo where you can find prepared docker files within standard capabilities. If you have docker installed in your machine it’s easy to test… you only need to generate a PAT and run the container in docker replacing <name>,<agentname>,<pat>
with your values (PAT you can generate under security section in your VSTS profile).
This will add an agent into the default queue… you can specify a different queue using VSTS_POOL env var.
You can add capabilities to this image or create a new one from this base. For example, I’m gonna extend the microsoft agent for ubuntu adding kubernetes client, helm and acs engine as capabilities.
Open a terminal in the same folder where you saved this file and run this command to build the new image replacing <yournewimagename>
.
Once image is created and stored in your local images repository you can run the agent replacing the gaps with your values.
After few minutes you should see in VSTS Agents Queues management section this agent appearing in the list ready to queue new tasks. If you run the same command changing <youragentname>
you’ll see another agent in the list ready…
Using docker you can take more profit of a machine and paralelice tasks avoiding tasks waiting to be executed for long periods… You save money and time… The only thing you have to care is to don’t saturate the machine, depending on what are you running on the agent you can run more instances per machine or not.