CloudFoundry: Deploying the spring-music webapp, Part 1

Cloud Foundry is an opinionated Platform-as-a-Service that allows you to manage applications at scale.  It supports multiple infrastructure platforms, and is able to standardize deployment, logging,  scaling, and routing in a way friendly to a continuous delivery pipeline.

This article is Part 1 of  a series on Cloud Foundry concepts:

In this particular article, we will install the command line interface for Cloud Foundry on Ubuntu and then use that to deploy the Spring Boot based spring-music project to a CF provider.

Selecting a Cloud Foundry Provider

For purposes of simplicity, I’m going to recommend you sign up for a free Cloud Foundry trial directly from Pivotal.  Click here to start.

Note that there are many Cloud Foundry providers [1,2], using Pivotal will just make the subsequent outputs more uniform with this article.

Pick an arbitrary name for your org, I choose “fleetest1”, and you should see something similar after you have verified your account and logged in.

Install Command Line Tool

Install the CF CLI which is a console based client application that communicates with the CF Cloud Controller hosted at Pivotal.

$ wget -q -O - | sudo apt-key add -
$ echo "deb stable main" | sudo tee /etc/apt/sources.list.d/cloudfoundry-cli.list
$ sudo apt-get update
$ sudo apt-get install cf-cli

Then verify the CLI version, which should look similar to below:

$ cf --version
cf version 6.31.0+b35df905d.2017-09-15

Validate CLI

Now authenticate into your remote Pivotal CF org using the command ‘cf login’.  The API endpoint will by default point at ‘’ which is correct for Pivotal CF.  If you were using  another provider, you would need to use the ‘-a’ option to override the API endpoint.

$ cf login
API endpoint:


Targeted org fleetest1

Targeted space development
API endpoint: (API version: 2.98.0)
Org:            fleetest1
Space:          development

There are no applications currently loaded, so listing them with ‘cf apps’ results in an empty list.

$ cf apps
Getting apps in org fleetest1 / space development as

No apps found

Build project

The spring-music project is a Spring Boot project that allows a user to browse and modify a collection of music.  By default it persists to an in-memory database, although it can very easily persist to Postgres, SQL Server, or Oracle.

In order to create the spring-music.jar that will be pushed to CloudFoundry, we need to build the project from source.  The project requires Java8, so the first step is to install Java8 on our Ubuntu host.

$ sudo add-apt-repository ppa:openjdk-r/ppa -y
$ sudo apt-get update
$ sudo apt-cache policy openjdk-8-jdk
$ sudo apt-get install openjdk-8-jdk -y
$ sudo update-alternatives --config java
$ sudo update-alternatives --config javac

$ /usr/bin/java -version
openjdk version "1.8.0_141"
OpenJDK Runtime Environment (build 1.8.0_141-8u141-b15-3~14.04-b15)
OpenJDK 64-Bit Server VM (build 25.141-b15, mixed mode)

Then we grab the source code of the project from github and assemble it using the included gradle scripts:

$ sudo apt-get install git -y
$ git clone
$ cd spring-music
$ ./gradlew clean assemble


This should result in a ‘build/libs/spring-music.jar’ file, which is used in the staging process by the buildpacks when creating the droplet.

Deploy app

The ‘manifest.yml’ file found in the root directory is used as the driving configuration for the CF push.

- name: spring-music
  memory: 1G
  random-route: true
  path: build/libs/spring-music.jar

This simple manifest provides a name and the path of the spring-music.jar used in the staging process.  The ‘random-route’ property makes sure that the deployment URL is unique by suffixing two random words to ensure uniqueness.

Go ahead and push the application:

$ cf push

You should see output saying that buildpacks and app packages are downloading and finally that the instance is starting.  At the end you will see something similar to below:

Showing health and status for app spring-music in org fleetest1 / space development as

requested state: started
instances: 1/1
usage: 1G x 1 instances
last uploaded: Thu Nov 9 20:20:48 UTC 2017 
stack: cflinuxfs2 
buildpack: client-certificate-mapper=1.2.0_RELEASE container-security-provider=1.8.0_RELEASE java-buildpack=v4.5-offline- java-main java-opts jvmkill-agent=1.10.0_RELEASE open-jdk-like-jre=1.8.0_1... 

state since cpu memory disk details #0 
running 2017-11-09 03:22:48 PM 94.9% 323.1M of 1G 171.3M of 1G

The last line tells us the service is running, and how much cpu/memory is being consumed by the application.

The ‘urls:’ line means that the application can be found at ‘’, which can be tested in the browser.




REFERENCES (command reference) (PCF 15 minute tutorial)