55.1 Cloud Foundry

如果不指定其他打包方式,Cloud Foundry会启用它提供的默认打包方式。Cloud Foundry的Java buildpack对Spring应用有出色的支持,包括Spring Boot。你可以部署独立的可执行jar应用,也可以部署传统的.war形式的应用。

一旦你构建应用(比如,使用mvn clean package)并安装cf命令行工具,你可以使用下面的cf push命令(将路径指向你编译后的.jar)来部署应用。在发布应用前,确保你已登陆cf命令行客户端

  1. $ cf push acloudyspringtime -p target/demo-0.0.1-SNAPSHOT.jar

查看cf push文档获取更多可选项。如果相同目录下存在manifest.yml,Cloud Foundry会使用它。

就此,cf将开始上传你的应用:

  1. Uploading acloudyspringtime... OK
  2. Preparing to start acloudyspringtime... OK
  3. -----> Downloaded app package (8.9M)
  4. -----> Java Buildpack source: system
  5. -----> Downloading Open JDK 1.7.0_51 from .../x86_64/openjdk-1.7.0_51.tar.gz (1.8s)
  6. Expanding Open JDK to .java-buildpack/open_jdk (1.2s)
  7. -----> Downloading Spring Auto Reconfiguration from 0.8.7 .../auto-reconfiguration-0.8.7.jar (0.1s)
  8. -----> Uploading droplet (44M)
  9. Checking status of app 'acloudyspringtime'...
  10. 0 of 1 instances running (1 starting)
  11. ...
  12. 0 of 1 instances running (1 down)
  13. ...
  14. 0 of 1 instances running (1 starting)
  15. ...
  16. 1 of 1 instances running (1 running)
  17. App started

恭喜!应用现在处于运行状态!

检验部署应用的状态是很简单的:

  1. $ cf apps
  2. Getting applications in ...
  3. OK
  4. name requested state instances memory disk urls
  5. ...
  6. acloudyspringtime started 1/1 512M 1G acloudyspringtime.cfapps.io
  7. ...

一旦Cloud Foundry意识到你的应用已经部署,你就可以点击给定的应用URI,此处是acloudyspringtime.cfapps.io/