Go + Maven + Chef - a webinar

https://github.com/ThoughtWorksInc/go-book-config

https://github.com/ThoughtWorksInc/go-book-website
https://github.com/ThoughtWorksInc/go-book-inventory
https://github.com/ThoughtWorksInc/go-book-management

Notes:
https://dl.dropboxusercontent.com/u/6691653/webinars/go-maven-chef-notes.pdf

Update: 14th June 2013
Here's how the demo pipelines look (minus the logos) with the new value stream visualization


Update: 29th March 2013
Recording now available at the studios website.

Maven based build pipelines are fairly common. Chef based deployment pipelines are also gaining traction. In this demo, I will demonstrate how to design and connect the two using Go. Along the way I'll explain why not to use maven-snaphosts, how to make Chef talk to Nexus and provide several tips on Go usage. The resulting end-to-end automated build and deployment pipeline will provide overarching visibility, traceability, orchestration and access control for the entire continuous delivery value stream.

Date: 21st March 2013
Time: UK 10:00 AM | IN 3:30 PM | AUS 9:00 PM

One task per job

I care for the ability to keep my build and deploy config under version control (just like application source code and config). I also care for the ability to run my builds and deployments outside of Go if needed. Turns out this is pretty straightforward to achieve with Go because Go simply execs its tasks, even in case of first-class support (except for fetch-artifact). As an aside, this is actually one reason why even task-plugins should not be more than exec - get too close and you lose independence.

One useful step along the way is to make sure I don’t inline my build and deployment commands within Go. So each task should just be a script invocation to an externally version controlled script. For example if we use a tool like ant, maven, nant or rake, pretty much every task can be of the form: tool <target> that runs off a version controlled build file.


In general, a job with N tasks can be refactored to a single-task-job that invokes a version controlled script containing N
lines. There is one small hitch though. In Go, a job is the unit of work on the agent. A job can have many tasks, they will be executed in sequence on the same agent. If any task exits with non-zero, the job is failed and subsequent tasks are not executed (except for cancel and fail handlers). This is useful fail-fast behaviour.

However, we lose this behaviour when we move from N tasks to a single-script-
task because by default, a bash script or windows batch script will not stop execution if any of its lines returns non-zero. This can be easily fixed in bash with the set -e command (thanks Arvind). Combine this with the -x option to get even better logging on the Go Job Console!

#!/bin/bash
set -e -x
# rest of the script

There are ways to do this on Windows, please see this discussion on stackoverflow.

Monitor Go Agents with Graphite




Say we want to use Graphite to monitor free memory on all Go agents. There are many ways to do it (e.g. cron job, free -s) but you will have to set it up on each agent. Here is one way to do it using a combination of Go’s features.

We’ll send data using the plaintext protocol.

echo "local.random.diceroll 4 `date +%s`" | nc ${SERVER} ${PORT};

I find redirection cooler, so:

echo ”server-name.freemem 23 `date +%s`” >/dev/tcp/carbon-server/2003

where 23 is percentage free memory. To get free memory as a single number, we use this tip:

free | grep Mem | awk '{print $4/$2 * 100.0}'

Thus, we have the following Go custom command that also reports hostname dynamically:

<exec command="/bin/bash">
   <arg>
-c</arg>
   <arg>
echo "`hostname`.freemem `free | grep Mem | awk '{print $4/$2 * 100.0}'` `date +%s`" &gt; /dev/tcp/carbon-server/2003</arg>
</exec>


Next, we set up a timer trigger based pipeline (with a dummy material, fetch set to false) so that it runs this command every x seconds.

To ensure that it always runs on the agent you want to monitor, you could use a job resource with value equal to the hostname of the agent. On the other hand, you could check run-on-all-agents on the job to monitor every agent - present and future, for now and ever!

Mapping TeamCity to Go

Here is a rough, partial mapping of abstractions and features in TeamCity and Go.

 

TeamCityGo
ProjectPipelineGroup
-Environment
BuildConfigurationJob
BuildStepTask
BuildStep - Command lineCustom command task
BuildChainValueStream
BuildChain visualDashboard and upstream-downstream
-Pipeline
-Pipeline activity visual
-Stage
Snapshot dependency based build chain (sharing same VCS root)Single Pipeline
Artifact dependency based build chainPipeline dependency with fetch artifact
Version Control SettingsSCM Material
Shared VCS Root-
VCS triggerMaterial polling
Schedule triggerTimer trigger
Finish Build triggerPipeline dependency + Material polling
Maven artifact dependency trigger
Maven snapshot dependency trigger
Nuget dependency trigger
Watch this space!
Fan-in dependency management

Werner Vogels shows off Go

At the recently held AWS ReInvent conference in the US, during one of the keynotes, Werner Vogels (Amazon's CTO) cited REA as "one of the most advanced AWS users in the world", and specifically mentioned the approach to continuous delivery that has been implemented there.


And then he showed Go's pipeline activity page to demonstrate how REA is set up.

He said:
"And in the new world where all our requirements change all the time, customers change their minds, environment changes, business decisions are being made. In the past, it would be almost impossible to meet those guarantees...Because we were in this style of development that was sort of next generation thinking. Oh you know, we'll do this in the next cycle...that is sort of thinking of the past...lots of lean thinking concepts being brought into businesses ...you will bring a product to market in a robust, limited feature set...then quickly iterate with your customers to go in a particular direction. Now if thats the new way that businesses actually want to build their product...after these days there is abundance of products in the market...competition is murderous..there is increasing consumer choice...it is highly uncertain if your product is going to be successful or not...so we need to have a development methodology that deals well with uncertainty...and the fact that you are no longer controlled by your resources allows you to be this flexible...for example one of our customers in Australia has really pushed this to the max...can I show you that slide...yes...
This is the guys of realestate.com in OZ - they are...experts in Agile. They have a distributed development environment that runs all over the world...all the engineers are collaborating together...on top of AWS, they do continuous build and integration...whenever you check something in, it automatically goes through all the steps and meets all the checks and will also be deployed into production."

Choose wisely between Pipelines, Stages, Jobs and Tasks

When modeling pipelines with Go, always remember that, subject to availability of agents:
  1. Multiple instances of a pipeline can run simultaneously. This is common if we have a pipeline that takes half an hour to complete and there are multiple commits to the pipeline's material during that interval.
  2. Stages of a pipeline-instance will execute in sequence.
  3. Jobs within a stage will be executed in parallel. If you have stuff that must run in sequence, model them as tasks within a job, not as multiple jobs. But you could also distribute these tasks over multiple stages having one job each. Why? For one, it gives better visibility on the dashboard and pipeline activity page. Stage progression is visually depicted. Task progression within a job is only depicted as a overall progress bar (because agents only report back to the server on job completion, not for each task). But perhaps more importantly, this gives you finer-grained re-run ability. It isn't possible to re-run individual tasks, only jobs. So modeling a sequence of activities into a number of single-job stages lets us pick and choose what to re-run thus resulting in faster feedback at a micro level.
  4. Note however that refactoring a multi-task job into multiple jobs means that the tasks may not all run on the same agent. Job is the unit of agent activity - so if you care about agent affinity (e.g. not fetch materials on multiple agents), a single job is the way to go.
On the other hand, do make full of parallelizability. Try to refactor pipelines with many stages into multiple pipelines. Try to partition independent compilation or testing activity into multiple jobs. Go is quite powerful and flexible - make sure you put it to work.

Pipelines and Value Streams

A Go Pipeline does not necessarily map one-to-one with what is referred to as the automated deployment pipeline in continuous delivery litreature. The automated deployment pipeline is essentially the end-to-end CD value stream. This end to end value stream is often better modeled using multiple Go Pipelines.

For very simple cases, it may be enough to model the entire value stream inside a single Go Pipeline as the diagram in the documentation suggests.
But for any realistic case, we are going to have to integrate the output of multiple teams and then subject the combined package to integration testing etc. In this case, it is much more flexible to model the value stream with multiple pipelines as below (each box is a pipeline).


There is no need to stop at one pipeline per team. If anything, the pipeline group is useful as a team level concept. Modeling your delivery value stream using multiple pipelines allows you to:
  1. Associate different materials with different pipelines
  2. Associate different pipelines with different environments.
  3. Pause or lock a specific pipeline without affecting the other pipelines.
Here is a simple delivery value stream modeled using seven Go pipelines.

Why continuous delivery needs devops, and why devops needs infrastructure-as-code

Update 02-Apr-13
Just came across this detailed relevant talk by Reinertsen - the author I reference for silo reduction and batch size reduction.


http://www.infoq.com/presentations/lean-product-dev
 
Update 31-Oct-12


Update 26-Oct-12

Slides, with notes
=====================

I'll present on this topic on 25th October 2012 as part of a ThoughtWorks Studios webinar series on continuous delivery. Please register from the webinar page.

Abstract
Continuous delivery and devops have gone mainstream, at least in terms of mindshare. As a result, a lot of vendors have jumped onto the bandwagon. Most products that have anything to do with deployment now try to associate themselves with devops and continuous delivery. In this webinar, Sriram will try to clear the air in a product independent manner. He will also cover common devops anti-patterns and explain the idea of infrastructure as code.

Does Go support my favorite build/deployment tool?

We’ve had numerous requests to provide first class support for more tasks (in Go). This is what first class support looks like:

 

And this is what less than first class support looks like:



 

The thing to realize is that first class support really isn’t all that it is made out to be. Go necessarily execs all tasks, first class or not. If the exec returns an exit code of zero, the task is considered successful, else the task (and job) are failed. The task specific GUI is merely a scaffold. At the time of job execution, it makes no difference whether you defined an Ant task via the GUI or via a custom command. In fact, it is not possible to make this out from the execution log for the task. The Go config xml will differ slightly based on whether you used the task specific GUI or  custom command but it really doesn’t matter.

However, it may take a bit of effort to get the arguments in the custom command exactly right. Would it help if we hosted a task repository for this purpose? Something like this? Note that this is currently totally experimental, unsupported and may disappear any time. But we’d like your feedback on this (via comments to this post please). I think this has potential for community participation and may evolve into a useful repo of reusable tasks that serve as a useful starting point for your own tasks.




On the other hand, it is good practice to keep the definition of a Go job very light. Instead of defining ten different tasks under one job, just write a script (or a build target) for the ten tasks and hook it into Go with a bare bones custom command that calls the script/target.
 

This lets you keep the script/build file under version control and change what a Go task does without touching the pipeline config. In fact, there are some advanced folks out there who use Puppet to push config changes to the Go Server and keep the entire config.xml under version control.

Go illustrated

The official Go documentation explains some key concepts with the help of  a nice diagram (reproduced below).
Here is another clickable diagram that tries to tie in other important abstractions in Go. Blogger does something to my image map that makes it a little off - kindly excuse.


Briefly, a pipeline may be based off a template. Materials refer to source code repositories or other pipelines. A pipeline group is a grouping of pipelines for administrative convinience. It is useful to think of a directed graph of pipelines (say from build to functional-test to integration to performance to QA to UAT to staging to production) as your continuous delivery value stream. An environment represents a ring-fencing of agents and includes one or more pipelines. The unit of work is a job. Jobs may be tagged with required resources so that they run only on correspondingly tagged agents. Jobs can be made to publish artifacts that are then stored on the server.

At first blush, it may appear overkill to have four levels of abstraction (pipeline, stage, job and task) for work execution. But the moment you start doing more than single team CI, they become indispensible. For instance, it is trivial to set up an integration pipeline that feeds off three upstream component pipelines and also feeds off a integration test repository. It is also easy to define different triggering behaviours for pipelines and stages. If we had only two abstractions, say jobs and stages, they'd be overloaded with different behaviour configurations for different contexts. Jobs and stages are primitives, they can and should be extended to achieve higher order abstractions. By doing so, we avoid primitive obsession at an architectural level.

Also note that multiple instances of a given pipeline can run in parallel. Stages within a pipeline run in sequence. Jobs in a stage can run in parallel. Tasks within a job run in sequence. This alternating behaviour is designed deliberately so that you have the ability to parallelize and sequentialize your work as needed at two different levels of granularity.