Coding, How to

Build & Push a Docker Image using Visual Studio Online Build vNext

So I’ve got a nice and simple NodeJs app and I want to have a CI build which builds my Docker image and pushes it to my docker hub ready for deployment. I’ll look at deployment in a future post, this time round we’ll focus on the build process.

To get this setup we’ll need to go through two bits, basically VSO uses agents (machines used to execute builds) and a build, which defines some steps that output an artifact (in this case a docker image). So we’ll setup a build agent, where the docker build can run, and then setup the build itself.

Setup the Build Agent

We’re going to need a linux based build agent to build out our docker image and push it to docker hub, as we’re hosting on the linux version of docker. We could also look at using the Windows implementation of Docker, which is available in the most recently Window Server Preview, but I’ll leave this for another day.

To do this we can use the ARM templates from the Azure Marketplace in the new portal to spin up an ubuntu VM then install all the bits we need. One the machine is up and running connect up to it via SSH to start install stuff, if you don’t have a client puttys a good bet.

First up let’s install docker on the agent. (full guide )

sudo curl -sSL | sh

After the docker install I found I had to reboot the machine to get things to behave.

After the reboot, check docker is up and running on the box. Easy way to do this is to type “docker info” at command line and you should get an overview of the Docker install, like so.

Next let’s install the VSO agent so it can pick up and do the builds. (full guide here )

To do this we have to setup apt-get for Ubuntu to install Nodejs:

curl -sL | sudo -E bash -

Then install Nodejs:

sudo apt-get install –yes nodejs

So hopefully that went well and now if you type ‘node –v’ you see it all installed! (This may change over time, install docs for npm are here)

Continue reading