The buzz around the microservice way of architecting software systems is taking hold across the Internet. Many people are trying to figure out what this means for their deployment strategy and their DevOps folks. Cloud Foundry provides great support for deploying these types of applications and this will be the first in a series of posts that will show how to effectively deploy a microservices architecture to Cloud Foundry. We will start with a single service and build up to a web or multiple services that talk to each other.
This series of posts is not going to cover why you would (or why you wouldn’t) want to use this method of software construction in your next, or current, project. There are plenty of good posts across the web about the pros and cons of a microservice architecture. They will assume that you’ve decided to use microservices and are planning on deploying them to a Cloud Foundry installation, either Pivotal Web Services (PWS), a private installation of Pivotal Cloud Foundry (PCF). To simplify local development, we will be using Lattice as a stand in for a full installation of Cloud Foundry. It will also assume some level of familiarity with Java and Spring Boot.
This first installment will show you how to deploy a Spring Boot based, Java 8 microservice to Lattice using Docker as a packaging mechanism. You could very easily substitute a Go or Ruby based microservice packaged in a Docker container into this flow. That’s one of the benefits of using a microservice architecture.
Before we start, please follow these instructions for getting Lattice set up on your laptop. We will wait here for you to return so there is no rush.
Now that we have that out of the way, let’s get started. The first thing we will need is a running Spring Boot application. You can get the sample code locally by cloning this repository to you computer and following along as we explore each file in the repository.
The README.md file contains some information about building the Docker images. Take some time to read through it and try to build the Docker images by running
./gradlew build buildDocker
in a terminal window.
Now that you have the Docker container build, it is time to deploy it to your locally running Lattice installation. Check out the bin/deploy-to-lattice.sh file for all of the details. The first thing the script does is to remove any currently running Docker container for this service and then creates an application with the newly minted Docker container from above. Yes this may cause some downtime for the service. We will address this concern in a future blog post. Yes it is that simple.
Yep it was that easy. For more details of how the Docker container gets built, check out the build.gradle file. Here you will see that it uses the gradle-docker plugin to help simplify the creation. There is a little magic at the end of the buildDocker task that takes the jar file created by the build task and makes it available to be added to the Docker container.
The rest of the files live in the src directory and are the actual code for the microservice. Take a look around and if you have any questions, post them here and I will address them in a future post.
Thanks for reading and stay tuned as we deploy multiple services to our Lattice environment and tie them together using a service discovery service for easy access.
About the AuthorMore Content by Mike Gehard