Skip to content

Instantly share code, notes, and snippets.

@bivas
Created August 12, 2011 10:58
Show Gist options
  • Save bivas/1141858 to your computer and use it in GitHub Desktop.
Save bivas/1141858 to your computer and use it in GitHub Desktop.
Running Play Framework Application in CloudFoundry
package plugins;
import java.util.List;
import java.util.Properties;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.cloudfoundry.runtime.env.CloudEnvironment;
import org.cloudfoundry.runtime.env.MysqlServiceInfo;
import play.Play;
import play.PlayPlugin;
public class CloudFoundryMySqlBootstrap extends PlayPlugin {
private static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
private static final Log LOG = LogFactory.getLog(CloudFoundryMySqlBootstrap.class);
@Override
public void onApplicationStart() {
final CloudEnvironment cloudEnvironment = new CloudEnvironment();
final List<MysqlServiceInfo> mysqlServices = cloudEnvironment.getServiceInfos(MysqlServiceInfo.class);
if (mysqlServices.isEmpty()) {
LOG.warn("no mysqlServiceInfo found - using existing db settings");
return;
}
final Properties configuration = Play.configuration;
final MysqlServiceInfo serviceInfo = mysqlServices.get(0);
removeExistingDbSettings(configuration);
configuration.put("db.driver", JDBC_DRIVER);
configuration.put("db.url", serviceInfo.getUrl());
configuration.put("db.user", serviceInfo.getUserName());
configuration.put("db.pass", serviceInfo.getPassword());
}
private void removeExistingDbSettings(final Properties configuration) {
configuration.remove("db");
}
}
# Application dependencies
require:
- play 1.2.2
- play -> crud
- org.cloudfoundry -> cloudfoundry-runtime 0.6.1
repositories:
- spring_milestone:
type: iBiblio
root: http://maven.springframework.org/milestone
contains:
- org.cloudfoundry -> *
10:plugins.CloudFoundryMySqlBootstrap
play war path\to\playdemo --output C:\path\to\playdemo\war (additional options omitted)
vmc push playframework-demo --path C:\path\to\playdemo\war --mem 1G
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment