Deploying Spring Boot Application to PCF (Pivotal Cloud Foundry)

Sujit Tripathy
4 min readApr 23, 2018

--

PaaS (Platform as a Service) is changing the way of how we build production-ready software in a much faster and simpler way. Pivotal Cloud Foundry (PCF) is a major commercial version of open source Cloud Foundry. As part of this post, I have taken a sample spring boot application and deployed the same to PCF via CLI. The demo application has two REST API endpoints /addTask and /fetchTasks for adding a new task to ToDo and fetching all the ToDo tasks. Application is deployed as a self-contained fat jar with embedded tomcat.

Step 1: Clone the source code from the GitHub repository

This is a sample Spring Boot application with Maven which is already present in GitHub, and I am going to deploy the same to PCF.

Step 2: Create a deployment artifact

After cloning the code, on the project root execute the below command to create a maven jar artifact. This will create the self-contained jar with embedded tomcat at /src/target path.

mvn package

Step 3: Execute the application in local

As the application is self-contained in a jar file, it can be started from the command line as shown below.

java -jar ToDoPlannerCF-0.0.1-SNAPSHOT.jar

Server should get started at port 8080, defined in application.properties. The REST API should be accessible at http:\\localhost:8080\addTask and http:\\localhost:8080\fetchTasks

2018-03-28 21:31:25.775  INFO 9509 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2018-03-28 21:31:25.781 INFO 9509 --- [ main] c.t.T.ToDoPlannerCfApplication

Step 4: Let’s deploy the app to PCF

Note: Registration is required at https://run.pivotal.io to deploy to Pivotal Cloud Foundry. The space needs to be created in PCF where the app will be deployed prior to pushing the app to PCF.

A manifest file needs to exist on the project root folder for the deployment of the application to PCF. This is a type of descriptor file that has properties of application such as name, path, memory requirement, number of instances, service dependency, etc. Below is the manifest.yml file for the demo application which we are going to deploy to PCF via CLI. For now, ignore the rabbitmq service dependency.

Navigate to project root location and execute cf push. PCF will take care of build pack download for a specific language (in this case Java) and deploy the same in the PCF container via BOSH. Below is the log-in console while PCF is deploying the application.

Binding service rabbitmq to app ToDoPlannerCF in org Neon / space development as XXXX.XXXX@gmail.com...
OK

Starting app ToDoPlannerCF in org Neon / space development as XXXX.XXXX@gmail.com...
.
.
.
Cell 9a954275-7f82-421f-9904-247e12f74292 creating container for instance 19350fe5-fc36-410f-bfc3-84f43783c815
Cell 9a954275-7f82-421f-9904-247e12f74292 successfully created container for instance 19350fe5-fc36-410f-bfc3-84f43783c815
Downloading build artifacts cache...
Downloading app package...
Downloaded build artifacts cache (132B)
Downloaded app package (33.7M)
-----> Java Buildpack v4.9 (offline) | https://github.com/cloudfoundry/java-buildpack.git#830f4c3
-----> Downloading Jvmkill Agent 1.12.0_RELEASE from https://java-buildpack.cloudfoundry.org/jvmkill/trusty/x86_64/jvmkill-1.12.0_RELEASE.so (found in cache)
-----> Downloading Open Jdk JRE 1.8.0_162 from https://java-buildpack.cloudfoundry.org/openjdk/trusty/x86_64/openjdk-1.8.0_162.tar.gz (found in cache)
Expanding Open Jdk JRE to .java-buildpack/open_jdk_jre (1.1s)
JVM DNS caching disabled in lieu of BOSH DNS caching
-----> Downloading Open JDK Like Memory Calculator 3.10.0_RELEASE from https://java-buildpack.cloudfoundry.org/memory-calculator/trusty/x86_64/memory-calculator-3.10.0_RELEASE.tar.gz (found in cache)
Loaded Classes: 18656, Threads: 250
-----> Downloading Client Certificate Mapper 1.5.0_RELEASE from https://java-buildpack.cloudfoundry.org/client-certificate-mapper/client-certificate-mapper-1.5.0_RELEASE.jar (found in cache)
-----> Downloading Container Security Provider 1.13.0_RELEASE from
.
.
.

Verify the status of the app instance with the command cf apps. The recent application should be in started state.

ToDoPlannerCF $cf apps
Getting apps in org Neon / space development as tripathy1.kits@gmail.com...
OK

name requested state instances memory disk urls
ToDoPlannerCF started 1/1 1G 1G todoplannercf.cfapps.io

Login to PCF web console and verify the application's running status. As we are seeing below the application is running at https://todoplannercf.cfapps.io/ which is running in the PCF cloud.

As part of the Last Step, let’s trigger the REST API from the postman and verify if the request is executing successfully.

The API response code was 200 which executed successfully executed and received the To-Do task id in the response body.

As we have seen here is that deploying Spring Boot to Pivotal Cloud Foundry PaaS is quite simple which can enhance developer productivity during CI/CD development.

--

--

Sujit Tripathy
Sujit Tripathy

Written by Sujit Tripathy

Staff Engineer @ Walmart Global Tech

No responses yet