After deploying our application, to deploy the application to Cloud Foundry, we can use the Push command with the Cloud Foundry CLI. In this tutorial, I will guide you how to use Push command in the Cloud Foundry.
The main steps for deploying our application to Cloud Foundry including:
- First, we will use Cloud Foundry CLI to log into Cloud Foundry.
- Navigate to the folder containing the application that you want to deploy.
- Using the command “cf push”
- Get the URL that Cloud Foundry has deployed our application and use.
Push command in Cloud Foundry CLI will do the following:
- Upload all the required files of the application onto Cloud Foundry.
- Inside Cloud Foundry, after you have uploaded the necessary files, the Cloud Controller will find the appropriate buildpack for our application. This buildpack will give us a droplet. Diego will use this Droplet to run in a container (Diego Cell).
- Reported to us the deployment of the application to success or failure.
OK, now I’m going to do an example to see how the Push command works.
Here, I will get the HelloWorld application in my tutorial about how Spring Boot works.
At local, this application will run as follows:
Now, we will deploy this application to Pivotal Cloud Foundry.
Log in to Pivotal Cloud Foundry.
Go to the folder containing our application.
In my example it would be:
Now, I will package the application using Apache Maven:
mvn clean package
After running the above command, you will see the file spring-boot-example-0.0.1-SNAPSHOT.war in the target directory. This file is the file we will use to deploy our application to Cloud Foundry.
Now, we will use the Push command to deploy the application to Cloud Foundry.
The contents of this statement are basically as follows:
cf push <application_name> -p <path_to_application_file>
As for the name of the application, remember that Cloud Foundry will use it to generate the URL, so the name of the application needs to be unique. That means it should not overlap with other deployed applications on Cloud Foundry.
In this example, I will use the following statement:
cf push huongdanjava-spring-boot-example -p target/spring-boot-example-0.0.1-SNAPSHOT.war
As you can see, after deploying, our application will run on a URL. In this example, the URL would be:
Here we can see information about CPU, memory, disk.
On the Pivotal Cloud Foundry management page, you will also find information about our application:
Now, try accessing the URL of our application, you will see the result as if we were running on local.