Cloud Foundry CLI is the official command line client for Cloud Foundry. In this blog post, I will show you on how to deploy an application in Cloud Foundry using this tool. It is very easy to use this CLI once it is correctly installed and set up.
In order to log into cf, you need to create an account in run.pivotal.io. You can sign up for free for 60 day free trial which requires no credit card. Please Remember the credentials, because you need them later to login to cf.
Getting started
Latest stable
Download and run the installer for your platform from here. You can find the installer or compressed binary for your platform from there.
Command line
If you prefer installing cf cli via command line, Ubuntu users can use the following command.
$ curl -L "https://cli.run.pivotal.io/stable?release=linux64-binary&source=github" | tar -zx
Log in
$ cf login
API endpoint: https://api.run.pivotal.io
Email> nanduni@wso2.com
Password>
Authenticating...
OK
Targeted org nanduni-org
Targeted space development
API endpoint: https://api.run.pivotal.io (API version: 2.48.0)
User: nanduni@wso2.com
Org: nanduni-org
Space: development
If you are using cf for the first time, this will ask you to create organizations, spaces required etc.
Push an application
Now, go to the base directory that contains your application and execute the following command.
$ cf push mytomcatCreating app mytomcat in org nanduni-org / space development as nanduni@wso2.com...OKCreating route mytomcat.cfapps.io...OKBinding mytomcat.cfapps.io to mytomcat...OKUploading mytomcat...Uploading app files from: /home/nanduni/apache-tomcat-7.0.67/webapps/Servlet3Uploading 3.2K, 7 filesDone uploadingOKStarting app mytomcat in org nanduni-org / space development as nanduni@wso2.com...Downloading go_buildpack...Downloading java_buildpack...Downloading ruby_buildpack...Downloading python_buildpack...Downloading nodejs_buildpack...Downloading staticfile_buildpack...Downloading php_buildpack...Downloading liberty_buildpack...Downloading binary_buildpack...Downloaded binary_buildpackDownloaded php_buildpackDownloaded java_buildpackDownloaded ruby_buildpackDownloaded liberty_buildpackDownloaded python_buildpackDownloaded nodejs_buildpackDownloaded go_buildpackDownloaded staticfile_buildpackCreating containerSuccessfully created containerDownloading app package...Downloaded app package (2.3K)Staging...-----> Java Buildpack Version: v3.5.1 | http://github.com/pivotal-cf/pcf-java-buildpack.git#d6c19f8-----> Downloading Open Jdk JRE 1.8.0_65 from https://download.run.pivotal.io/openjdk/trusty/x86_64/openjdk-1.8.0_65.tar.gz (1.1s)Expanding Open Jdk JRE to .java-buildpack/open_jdk_jre (1.0s)-----> Downloading Open JDK Like Memory Calculator 2.0.1_RELEASE from https://download.run.pivotal.io/memory-calculator/trusty/x86_64/memory-calculator-2.0.1_RELEASE.tar.gz (0.0s)Memory Settings: -Xss1M -Xmx768M -XX:MaxMetaspaceSize=104857K -Xms768M -XX:MetaspaceSize=104857K-----> Downloading Tomcat Instance 8.0.30 from https://download.run.pivotal.io/tomcat/tomcat-8.0.30.tar.gz (0.3s)Expanding Tomcat Instance to .java-buildpack/tomcat (0.1s)-----> Downloading Tomcat Lifecycle Support 2.5.0_RELEASE from https://download.run.pivotal.io/tomcat-lifecycle-support/tomcat-lifecycle-support-2.5.0_RELEASE.jar (0.0s)-----> Downloading Tomcat Logging Support 2.5.0_RELEASE from https://download.run.pivotal.io/tomcat-logging-support/tomcat-logging-support-2.5.0_RELEASE.jar (0.0s)-----> Downloading Tomcat Access Logging Support 2.5.0_RELEASE from https://download.run.pivotal.io/tomcat-access-logging-support/tomcat-access-logging-support-2.5.0_RELEASE.jar (0.0s)Exit status 0Staging completeUploading droplet, build artifacts cache...Uploading droplet...Uploading build artifacts cache...Uploaded build artifacts cache (52.3M)Uploaded droplet (51.1M)Uploading complete1 of 1 instances runningApp startedOKApp mytomcat was started using this command `CALCULATED_MEMORY=$($PWD/.java-buildpack/open_jdk_jre/bin/java-buildpack-memory-calculator-2.0.1_RELEASE -memorySizes=metaspace:64m.. -memoryWeights=heap:75,metaspace:10,native:10,stack:5 -memoryInitials=heap:100%,metaspace:100% -totMemory=$MEMORY_LIMIT) && JAVA_HOME=$PWD/.java-buildpack/open_jdk_jre JAVA_OPTS="-Djava.io.tmpdir=$TMPDIR -XX:OnOutOfMemoryError=$PWD/.java-buildpack/open_jdk_jre/bin/killjava.sh $CALCULATED_MEMORY -Daccess.logging.enabled=false -Dhttp.port=$PORT" exec $PWD/.java-buildpack/tomcat/bin/catalina.sh run`Showing health and status for app mytomcat in org nanduni-org / space development as nanduni@wso2.com...OKrequested state: startedinstances: 1/1usage: 1G x 1 instancesurls: mytomcat.cfapps.iolast uploaded: Wed Jan 27 05:54:32 UTC 2016stack: cflinuxfs2buildpack: java-buildpack=v3.5.1-http://github.com/pivotal-cf/pcf-java-buildpack.git#d6c19f8 open-jdk-like-jre=1.8.0_65 open-jdk-like-memory-calculator=2.0.1_RELEASE tomcat-access-logging-support=2.5.0_RELEASE tomcat-instance=8.0.30 tomcat-lifecycle-support=2.5.0...state since cpu memory disk details#0 running 2016-01-27 11:25:10 AM 0.0% 109.2M of 1G 129.5M of 1G
When you push an app, Cloud Foundry determines which buildpack to use. Each buildpack has a position in the detection priority list. Cloud Foundry first checks whether the buildpack in position 1 is right for the app. If the position 1 buildpack is not appropriate, Cloud Foundry moves on to the position 2 buildpack. This goes on until Cloud Foundry finds the correct buildpack.
I no matching buildpack is found, cf push fails with an error like below.
Staging...
None of the buildpacks detected a compatible application
Exit status 222
Staging failed: Exited with status 222
FAILED
NoAppDetectedError
The available buildpacks can be checked using the following command.
$ cf buildpacks
Getting buildpacks...
buildpack position enabled locked filename
staticfile_buildpack 1 true false staticfile_buildpack-cached-v1.3.0.zip
java_buildpack 2 true false java-buildpack-v3.5.1.zip
ruby_buildpack 3 true false ruby_buildpack-cached-v1.6.12.zip
nodejs_buildpack 4 true false nodejs_buildpack-cached-v1.5.5.zip
go_buildpack 5 true false go_buildpack-cached-v1.7.2.zip
python_buildpack 6 true false python_buildpack-cached-v1.5.4.zip
php_buildpack 7 true false php_buildpack-cached-v4.3.3.zip
liberty_buildpack 8 true false liberty_buildpack.zip
binary_buildpack 9 true false binary_buildpack-cached-v1.0.1.zip
I hope that this blog post would be useful for anyone who is interested in deploying applications in cloud foundry using cf cli.
Excellent blog, I wish to share your post with my folks circle. It’s really helped me a lot, so keep sharing post like this
ReplyDeletepython training in rajajinagar
Python training in bangalore
Python training in usa
I am really impressed with your efforts and really pleased to visit this post.
ReplyDeleteAWS Training in pune
AWS Online Training
This post useful for me..Thanks lot!!
ReplyDeleteAndroid Training in Chennai | Certification | Mobile App Development Training Online | Android Training in Bangalore | Certification | Mobile App Development Training Online | Android Training in Hyderabad | Certification | Mobile App Development Training Online | Android Training in Coimbatore | Certification | Mobile App Development Training Online | Android Training in Online | Certification | Mobile App Development Training Online