Getting Started: Pivotal Spring Tool Suite deployments to local and public CloudFoundry
This blog post describes a tutorial how to get started with application development and deployment to a local and public Pivotal Cloud Foundry (PCF) environment.
In order to complete the tutorial you need to have the following software installed:
Spring Tool Suite 3.8 or higher
Java 7 or higher
VirtualBox 5 or higher
The overall goal is to set up the local and public cloud configuration and deploy the same sample application to each one.
The blog post will guide you through the process of registering for a public PCF account as well as the setup of a local PCF development (PCF Dev) environment. The PCF Dev is a light-weight implementation of the full PCF setup that can be run locally and is very suitable for implementation and testing.
The application to be deployed is taken from the Pivotal Getting Started samples. The import, build and deployment of the application is done using the Spring Tool Suite (STS). If you already have an existing Eclipse installation you can add the STS as extension instead of installing it from scratch. This tutorial will however not describe these steps and is based on a fresh STS installation.
Installing the Cloud Foundry Command Line interface
Prior to using the public or local Cloud Foundry platform it is required to install the Cloud Foundry Command-Line Interface (CF CLI). The download can be found here: https://console.run.pivotal.io/tools
Download the installer suitable for your Operating System, extract it and run the binary contained in the downloaded file. The installation does not take any parameters.
Registration for a public Pivotal Cloud Foundry account
The base requirement to deploy an application to the public cloud is an account at Pivotal. The registration is free and can be done here.
If you already have an account you can sign in here and proceed to the next step.
On the dialog enter your name, e-mail and password. After the submission of this form an activation link will be sent to your e-mail address.
Confirm the link in your inbox and it will take you to the following web page.
On this page select the Pivotal Web Services. This will take you to a dialog where you need to accept the terms of service. Depending on your preference you can check/uncheck the e-mail notifications and updates from Pivotal.
Select Next: Claim your trial. You need to provide a phone number where you can receive a call or SMS for verification. After this the registration is completed.
The first thing you are asked to do is create an Org. You can label it anything you like as long as the name is not already taken. A so-called space with the name of development is automatically created within this Org.
You will see an overview of your deployments and services. If you just created your space you will have no apps or services running.
You can log out for now.
Configuration of the Pivotal Cloud Foundry development (PCF Dev) environment
Pick the download suitable for your Operating System. (This tutorial was written using pcfdev-v0.17.0 on Windows). The download is fairly small in size (~4MB). Extract the content to a certain directory (e.g. pcfdev) and open a command shell in this directory. Execute the executable within this directory.
It will tell you once the plugin is successfully upgraded. After that run “cf dev help” to get the following output screen.
Run “cf dev start -s scs” to kick-off the download and deployment of the VM.
The app should be displayed. Click connect, enter a name and press Send.
If you see the previous screen the app has been compiled and deployed successfully. It is now running on a Tomcat server locally on your Operating System.
Run the sample application on the CloudFoundry instances
Now that you have set up an application in your development environment and configured two cloud instances you can move forward to deploy the same application to them.
Right-click the application within the Spring Tool Suite again.
This time select Run As -> Run on Server.
You will see the local and public instances of Cloud Foundry, which you have configured before:
Select CFlocal and click Finish.
On the application details dialog select Next >
On the Launch deployment dialog copy the Deployed URL information to your clipboard.
In the console you can trace the deployment again. The log output will be different this time in a way that the application and the Tomcat server will not be deployed locally to your OS, but to the running VM that hosts the Cloud Foundry runtime.
Once the application is running open a new browser and point it to the link you saved in your clipboard. In case you did not save, it is: http://<name_of_your_app>.local.pcfdev.io. In my case this is http://mhs-messaging.local.pcfdev.io
The browser should look identical to the local test of the previous example. However the application is hosted within Cloud Foundry (PCF Dev) this time.
As a final step, deploy the application to the public Cloud Foundry platform.
Repeat the steps from above. As this deployment will be publicly available on the Internet, the URL must be unique. If your name is already in use, the deployment will be rejected and you need to use a unique name in the URL.
After completing the dialogs, you will see the deployment steps in the console again. After that your application is running in the public Cloud and accessible via: http://<name_of_your_app>.cfapps.io. In my case this is http://mhs-messaging.cfapps.io
With this tutorial you have seen 3 different ways to deploy an application. A “non-Cloud” local deployment and 2 Cloud deployments – to a local development environment and to the public cloud. To the end-user the access is almost transparent, it basically differs by URL only. However, the underlying runtime is significantly different in terms of location and flexibility.
For further validation you can now log in again to the Cloud Foundry Web Services page (public and/or local) where you see your running app:
Alternatively you can use the CF CLI to control via command line.
The tutorial completes with this step. Thanks for reading!