Grails 3 makes development of microservices awesome. Docker makes ops for developers of said microservices awesome. However, once we get past “hello, world” and into HOLY TRAFFIC there’s a whole new layer of complexity around scalability and reliability. There have been a handful of tools emerging to target these issues, but in this post I want to introduce Cloud Foundry’s Lattice. If you haven’t heard of Lattice here’s the elevator pitch to save you a click:
A project that helps manage a cluster of containers to keep things scalable and reliable so you don’t have to reinvent that wheel during the worst possible time (when you’re app is finally attracting load).
Let’s go through a simple tutorial of getting a bare Grails 3 app deployed to Docker and clustered with Lattice.
Lattice’s Getting Started docs do a great job explaining how to get everything set up and running. Make sure to follow the instructions all the way through the launching of their sample “lattice-app” to make sure everything is installed correctly.
I would recommend using GVM to install and manage your Grails versions, but it can also be downloaded and installed from the Grails website. For this tutorial you will need Grails 3 or higher. I’m using 3.0.1.
You will need to create an account on Docker Hub. We will use it to store the image that will be run in the cluster.
Much of this is borrowed from the spring-boot-docker guide (hurray for boot-based Grails :-)), so check there for more info. We will start by creating a Dockerfile in the project:
In the Dockerfile, use the following instructions:
Now we need to add the following pieces to build.gradle:
Make sure you replace “group” with your Docker Hub id, or else it will fail while pushing the image. Next we will build the Docker image and push it to Docker Hub (NOTE: if using a Mac, execute this in your boot2docker terminal):
It should print out a URL to hit the application such as http://grails-lattice-app.192.168.11.11.xip.io.
It may take a while for the image to download so don’t panic if you get a timeout message or the URL gives you an error. Keep checking the status of the application with the command
Once the “Instances” field has the value “1/1” it means the application is deployed and should serve requests. You’re now ready to scale up, crash instances to watch recovery, and all the other fun basic operations from Lattice’s Getting Started docs.
Depends on your team size and deployment needs. Lattice is being created for single user/single tenant clusters and is ideal for small teams and simpler use cases. It is a small subset of a full Cloud Foundry Elastic Runtime deployment and serves as its impressive gateway drug. Even if you aren’t planning on using Lattice in production, its ease of use makes deploying and experimenting with a local environment of microservices useful.