mstine / draft-gs-spring-cloud-and-lattice

Spring Cloud + Lattice

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

tags projects
lattice
spring cloud
docker
spring-cloud

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 solution small enough to run on your laptop. By giving up features like multi-tenancy, you can build cloud apps rapidly and later target them for things like Pivotal CF. In this guide, you’ll setup Lattice and then deploy a service to it.

Set up Lattice

Lattice is Cloud Foundry with certain non-critical features removed. 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.

Note
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

Build a Containerized Spring Cloud app for Lattice

With Lattice set up, you will build and install a Spring Cloud sample application.

Temporary Pre-setup

Until the Recepter Client library is deployed to a maven repository, these extra steps are necessary:

  1. Go to your root source folder (like cd ~/src)

  2. git clone git@github.com:markfisher/receptor-client.git

  3. cd receptor-client

  4. ./gradlew clean build install -x test

Main Steps

Note
At this point in time, lattice requires docker images to be served from https://hub.docker.com. It means you have to register and push your image there to deploy.
  1. Go back to the folder that holds the lattice folder you recently cloned (like cd ~/src).

  2. Clone Spring Cloud Lattice by typing git clone git@github.com:spring-cloud/spring-cloud-lattice.git

  3. cd spring-cloud-lattice

  4. mvn --settings .settings.xml install

  5. cd spring-cloud-lattice-sample

  6. mvn --settings ../.settings.xml clean package docker:build

  7. docker tag spring-cloud-lattice-sample:latest <yourdockerhubid>/spring-cloud-lattice-sample

  8. docker push <yourdockerhubid>/spring-cloud-lattice-sample

With everything built, you can now deploy this sample app to your lattice installation.

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

  2. LATTICE_CLI_TIMEOUT=180 ltc create spring-cloud-lattice-sample <yourdockerhubid>/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.

Bonus commands to tinker with:

  • Tail the logs by typing ltc logs spring-cloud-lattice-sample

  • See all apps deployed on your Lattice by typing ltc list

  • See status by typing ltc status spring-cloud-lattice-sample

  • Visualize containers by typing ltc visualize

  • Crash the app by typing http://spring-cloud-lattice-sample.192.168.11.11.xip.io/exit into your browser’s address bar. The watch it automatically recover by revisiting it shortly thereafter.

Summary

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

About

Spring Cloud + Lattice