Prerequisites

Sign up for a free Cloud Foundry account and install or update the Cloud Foundry command line tool, VMC, to the latest version (0.3.18 or higher) by using the following command:

gem install vmc

Build your Application

Package your app by typing the dist command in the play prompt.

Deploy your Application

Deploy the created zip file to Cloud Foundry with the VMC push command. If you choose to create a database service, Cloud Foundry will automatically apply your database evolutions on application start.

Working With Services

Auto-Reconfiguration

Cloud Foundry uses a mechanism called auto-reconfiguration to automatically connect your Play application to a relational database service. If a single database configuration is found in the Play configuration (for example, default) and a single database service instance is bound to the application, Cloud Foundry will automatically override the connection properties in the configuration to point to the PostgreSQL or MySQL service bound to the application.

This is a great way to get simple apps up and running quickly. However, it is quite possible that your application will contain SQL that is specific to the type of database you are using. In these cases, or if your app needs to bind to multiple services, you may choose to avoid auto-reconfiguration and explicitly specify the service connection properties.

Connecting to Cloud Foundry Services

As always, Cloud Foundry provides all of your service connection information to your application in JSON format through the VCAP_SERVICES environment variable. However, connection information is also available as series of properties you can use in your Play configuration. Here is an example of connecting to a PostgreSQL service named tasks-db from within an application.conf file:

This information is available for all types of services, including NoSQL and messaging services. Also, if there is only a single service of a type (e.g. postgresql), you can refer to that service only by type instead of specifically by name, as exemplified below:

We recommend keeping these properties in a separate file (for example cloud.conf) and then including them only when building a distribution for Cloud Foundry. You can specify an alternative config file to play dist by using -Dconfig.file.

Opting out of Auto-Reconfiguration

If you use the properties referenced above, you will automatically be opted-out. To explicitly opt out, include a file named “cloudfoundry.properties” in your application’s conf directory, and add the entry autoconfig=false

Found an error in this documentation? The source code for this page can be found here. After reading the documentation guidelines, please feel free to contribute a pull request.