Tfs 2015 comes with many new build management features. One of my favorites is the new cross-platform build agent that they introduced and its open sourced at github. Feels like this capability unlocks huge opportunities for those who have invested in VS ALM stack. Already VS ALM offers best suite tools for Windows/Microsoft world of things. With this new cross platform build capability and revamped build authoring from web browser experience makes the job much easier.
Lets assume, I’ve a web app and want to deploy that to Nginx on an Ubuntu server. In order to coordinate Build-Deploy-Test flow, I’m going to use the vso-agent. This is 100% non-Microsoft stuff and lets see how it works together.
Setup a brand new Ubuntu box
I use Vagrant to spin up new base Ubuntu from Hashicorp.
I dont have NodeJs, Nginx or Npm installed.
Setup Ansible playbook for app deployment
Assuming you are familiar with Ansible. I’m not an expert in this cool technology but it was too hard to pick up lately, very interesting one for orchestrating DevOps flow from environment provisioning thru monitoring. I got a simple playbook that will install NodeJs, Nginx then copy my static content over to the Nginx box, run post deployment xml/json transformation.
Below is the snippet, pretty simple self explanatory .yml file..
- highlighted ones are the modules I use to install NodeJs and other prerequisites
- task to copy the index.html
- task to transform the config file using exising node modules
Prepare_env module, just installs nginx and set of node modules required for my app
Another simple run.sh to kick off the playbook (I’ve setup .ssh keys behind the scene and sudo password for remote installation is encrypted using ansible vault module and vault password is given for execution via –vault-password-file)
Setup Tfs cross-platform build agents
I’ve installed the agent on my mac, its up and running
Setup Ansible on the build Agent
In order to run the deployments on Ubuntu box, I’m going to use Ansible. vso-agent will kick off the playbook and hence we need to install Ansible on the agent machine. In my case its the Mac book. Run “brew install ansible” to install Ansible.
Connect the dots
Now that we got all fundamentals covered, idea is to create a build that will pull my source code from tfs git repo, run Mocha tests (unit and integration tests) if successful deploy thru Ansible.
I use built-in tasks provided by the new build system.
Npm Install – to install dependencies
Shell script that kicks off Mocha tests (really it’s one line and that is “npm test”. I dont know if there is a better way to kick off npm tests)
Shell script that kicks off Ansible playbook that I mentioned earlier (run.sh above)
Queue the build ..
Make sure to select the correct Agent, in this case not Hosted, its Default because I added my Mac vso-agent part of Default pool
Running the build in my local vso-agent
Seeing the Build status in VSO .. nice rolling log
Below output shows NodeJs, Nginx installation, copying files, transforming the sample .xml/.json config and finally starting Nginx..
So far, cross-platform build agent is very impressive capability, we might see some shortcomings interms of existing OOB tasks, like it comes with Gulp and if we want to run Grunt which is still widely being used, we need to wrap the grunt execution in some shell script and run that shell script. However, step in right direction to enable everyone to use VS ALM stack.