This guide walks you through the process setting up Lattice and then deploying a Spring Boot application to it.

What you’ll build

Lattice is a cloud-native application platform that enables you to run your applications in containers using solutions like Docker. Lattice includes features like:

  • Cluster scheduling

  • HTTP load balancing

  • Log aggregation

  • Health management

Lattice does this by packaging a subset of the components found in the Cloud Foundry elastic runtime. The result is an open, single-tenant environment suitable for rapid application development. Applications developed using Lattice should migrate unchanged to full Cloud Foundry deployments.

In this guide you’ll deploy a sample application that demonstrates service discovery. The application leverages Spring Cloud to discover and display metadata about horizontally-scaled instances of itself via Lattice’s API.

This guide also requires docker. For more details about getting started with Spring apps in Docker, see Spring Boot with Docker.

Set up Lattice

The following getting started steps are all you need to get Lattice going:

  1. Visit VirtualBox’s download site and pick the version for your machine. Download and install. Don’t worry about actually running it.

  2. Visit Vagrant’s download site and pick the version for your machine. Download and install.

  3. You need git, the DVCS tool. Options include "brew install git" or visiting the download page. After installing, verify you can run "git" from the command line.

  4. Create a folder to check out Lattice, e.g. mkdir ~/src && cd ~/src

  5. Check out a copy of Lattice by typing git clone https://github.com/cloudfoundry-incubator/lattice.git

  6. cd lattice

  7. git checkout v0.2.1

  8. vagrant up --provider virtualbox (this command MUST take place in this folder)

  9. Go get a coffee. This will take some time as it downloads a Lattice Docker image into your VirtualBox setup.

  10. When Lattice finishes this step, it should print out a target address like this: 192.168.11.11.xip.io. Note it for later usage.

Docker has to be setup and working properly. If you are on a Mac, you need to have Docker’s environment variables properly configured. It’s recommended to embed $(boot2docker shellinit 2> /dev/null) towards the bottom of your .bash_profile (or other env-loading file) to ensure proper settings. If you see a Docker-related issue, always check if Docker and its components are up by first running docker ps for a quick check.
Vagrant also has support for other VMs like VMware Fusion. It requires not only a commercial copy of VMware Fusion, but a copy of the Vagrant/VMware Fusion plugin as well.

Set up Lattice CLI

With Lattice installed and running, you now need a copy of the Lattice CLI (ltc).

Using Mac Homebrew? Try this:

  1. wget https://lattice.s3.amazonaws.com/releases/v0.2.1/darwin-amd64/ltc -O /usr/local/bin/ltc

  2. chmod 755 /usr/local/bin/ltc

If not, try this instead:

  1. mkdir -p $HOME/bin

  2. wget https://lattice.s3.amazonaws.com/releases/v0.2.1/darwin-amd64/ltc -O $HOME/bin/ltc

  3. chmod 755 $HOME/bin/ltc

  4. Add $HOME/bin to your PATH inside your .bash_profile (or similar PATh configuration file).

Verify ltc is setup with this:

$ ltc --version

Deploying a Containerized Spring Cloud app for Lattice

With Lattice set up, you will now install a Spring Cloud sample application into your lattice installation from Docker’s hub location.

  1. Point ltc at your Lattice setup by typing: ltc target <lattice address>

  2. LATTICE_CLI_TIMEOUT=180 ltc create spring-cloud-lattice-sample springcloud/spring-cloud-lattice-sample --memory-mb=0 (0 means no memory limits. See http://lattice.cf/docs/ltc/ for more details.)

  3. Scale the app to three instances by typing ltc scale spring-cloud-lattice-sample 3

  4. Visit http://spring-cloud-lattice-sample.192.168.11.11.xip.io?service=spring-cloud-lattice-sample and verify you can see the JSON service record. Refresh the browser multiple times notice how the uri attribute rotates.

  5. Visit http://spring-cloud-lattice-sample.192.168.11.11.xip.io/me and see a pared down record that also rotates the uri.

See http://lattice.cf/docs/ltc/ for more details about the various CLI commands you can run.

Summary

Congratulations! You have setup the lightweight Lattice platform on your machine and ran a Spring Cloud app on it!