The Disco Blog

Can you dig it?

Docker Containers With Gradle in 4 Steps

Do you need to create a Docker image from your Java web app? Are you using Gradle? If so, then you are only 4 steps away from Docker nivana.

For this example, I’m going to use a simple Spring Boot application. You can find all the source code in my Github repository dubbed galoshe.

If you haven’t had a chance to see Spring Boot in action, then you’re in for a treat, especially if the words simple and Java web app in the same sentence make you flinch. That was certainly my long standing reaction until I took a serious look at Boot.

Dockerfiles in a Jiffy

Docker is a lightweight container for applications – think of a Docker as an app in a box, except that the box in this case isn’t an entire VM, but the bare necessities required to run a process. Consequently, you can run many Dockers in a VM. In essence, Docker replaces installation steps for a particular app. Rather than having to execute a series of steps to get, say, MongoDB running, you can simply fire up a Mongo Docker image.

Docker images can be created from a Dockerfile, which is similar to a Vagrantfile or even a build script – it’s a prescription for how to assemble an image. You don’t need to have a Dockerfile to create a Docker image, however, creating one makes image creation repeatable. It also provides a means for others to verify an image.

Schooled in Ping Pong

Years ago, a good friend of mine taught me an effective pair programming technique that results in universally covered code. What’s more, this manner of pairing ultimately made me a better developer as I learned myriad different coding skills from my coding partner, ranging from testing techniques, defensive coding, and encapsulation, just to name a few.

A lot of my coding practices today can be traced to tactics I learned from playing what’s known as ping pong.

Custom Git Commands in 3 Steps

I’m lazy and so I seek ways to reduce repetitious activities. For instance, I’ve spent a lot of time in a terminal typing Git commands. A few of the more common commands, I’ve aliased. If I want to see a list of branches, I used to type:

Listing Git branches
$> git branch -v -a

But after adding an alias to my bash profile, I simply type gb. I’ve done this for a few commands like git commit, which is gc and gca for the -a flag.

Java 8’s Functional Fomentation

Java 8 has revolutionized Java. It’s easily the most significant release of Java in the last 10 years. There are a ton of new features including default methods, method and constructor references, and lambdas, just to name a few.

One of the more interesting features is the new API, which as the Javadoc states, enables

functional-style operations on streams of elements, such as map-reduce transformations on collections

Combine this new API with lambda expressions and you end up with a terse, yet, powerful syntax that significantly simplifies code through the application of projections.

Ahoy There Maven Central

Ahoy!, which is an asynchronous SQS adapter for AWS’s Java SQS library, is now syncing with Maven Central. This means you can easily use Ahoy! in your Maven or Gradle builds.

For example, if you want to spice up your SQS and you use Maven, just add the following dependency for your pom.xml file and you’ll be rockin’ it in no time, baby!

Including Ahoy! into your Maven pom.xml

You don’t use Maven? But rather use Gradle? I’ve got you covered!

Adding Ahoy! into your Gradle build.gradle file
compile 'com.github.aglover:ahoy:1.0.1'

Check out for how to include Ahoy! into your SBT build or other dependency management tool like Ivy.

Continuous Delivery for Heroku With Jenkins

A continuous delivery pipeline that leverages Jenkins and targets Heroku is fairly simple to set up, provided you install the Jenkins Git plugin. With this pipeline, changes to a specific Git branch will result in a Heroku deployment.

For this deployment process to work nicely, you should use at least two Git branches, as you’ll want to have one branch targeted for auto-deploys and another that doesn’t (as it represents active development). For example, following the git-flow convention, those two branches could be named development and master, where changes to master are deployed to Heroku and changes to development aren’t. Thus, you will have at least two Jenkins jobs that monitor each of these branches.

Just Require Tire to Inquire

In the land of Ruby there’s a few client libraries for Elasticsearch, however, one stands above the rest with a comprehensive set of features and remarkable documentation: Tire.

With its DSL based API, you’ll find working with Elasticsearch straightforward and a lot of fun. And even though the project’s repository has been renamed to retire, the Tire library

will continue to work…bugs will be fixed and important features will be added.

In my opinion, for the time being, Tire is still superior to the elasticsearch-ruby alternative in terms of features and its elegant DSL.

Heroku Deployments With Git Branches

Single branch development is easy. But this strategy’s easiness blows up once you release code to the general public. If you need to hot-fix an instance of deployed code, while in the midst of a development cycle, single branch development gets in your way by requiring you think. On the other hand, having more than one branch at least allows you to jump back in time via an alternate branch to perform a patch, while not disturbing an unfinished developmental branch. And you can do this without having to think much.