Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for cloudfoundry deployments using spring-cloud. #15

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions grails-app/conf/BuildConfig.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ grails.project.dependency.resolution = {
mavenLocal()
grailsCentral()
mavenCentral()
mavenRepo "http://repo.spring.io/release"
mavenRepo "http://repo.spring.io/milestone"
mavenRepo "http://repo.spring.io/snapshot"
// uncomment these (or add new ones) to enable remote dependency resolution from public Maven repositories
//mavenRepo "http://repository.codehaus.org"
//mavenRepo "http://download.java.net/maven/2/"
Expand All @@ -48,20 +51,28 @@ grails.project.dependency.resolution = {

dependencies {
// specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes e.g.
// runtime 'mysql:mysql-connector-java:5.1.27'
runtime 'mysql:mysql-connector-java:5.1.29'
// runtime 'org.postgresql:postgresql:9.3-1100-jdbc41'

//compile "org.springframework:spring-orm:$springVersion"

compile 'org.springframework.cloud:spring-cloud-cloudfoundry-connector:1.0.0.RELEASE'
compile('org.springframework.cloud:spring-cloud-spring-service-connector:1.0.0.RELEASE') {
excludes('spring-context', 'spring-context-support')
}
}

plugins {
// plugins for the build system only
build ":tomcat:7.0.52.1"
build ":tomcat:7.0.53"

// plugins for the compile step
compile ":scaffolding:2.0.3"
compile ':cache:1.1.1'

// plugins needed at runtime but not for compilation
runtime ":hibernate:3.6.10.13" // or ":hibernate4:4.5.1"
//runtime ":hibernate:3.6.10.13" // or ":hibernate4:4.5.1"
runtime ":hibernate4:4.3.5.3" // or ":hibernate:3.6.10.15"
runtime ":database-migration:1.4.0"
runtime ":jquery:1.11.0.2"
runtime ":jquery-ui:1.10.3"
Expand Down
74 changes: 62 additions & 12 deletions grails-app/conf/DataSource.groovy
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
import org.springframework.cloud.CloudFactory

def cloud

try {
cloud = new CloudFactory().cloud
} catch(e) {
println e.getMessage() + '... because we are not running in the cloud'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change this println to use a commons logging debug statement

}

dataSource {
pooled = true
driverClassName = 'org.h2.Driver'
Expand All @@ -7,7 +17,7 @@ dataSource {
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = false
cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'
cache.region.factory_class = 'org.hibernate.cache.ehcache.EhCacheRegionFactory'
format_sql = true
use_sql_comments = true
}
Expand All @@ -31,19 +41,59 @@ environments {
}
production {
dataSource {
dbCreate = 'update'
url = 'jdbc:h2:prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000'
pooled = true
properties {
maxActive = -1
minEvictableIdleTimeMillis=1800000
timeBetweenEvictionRunsMillis=1800000
numTestsPerEvictionRun=3
testOnBorrow=true
testWhileIdle=true
testOnReturn=true
validationQuery='SELECT 1'
dbCreate = 'update'

if (cloud) {
def dbInfo = cloud.getServiceInfo('petclinic-mysql')
driverClassName = 'com.mysql.jdbc.Driver'
url = dbInfo.jdbcUrl
username = dbInfo.userName
password = dbInfo.password
} else {
driverClassName = 'org.h2.Driver'
url = 'jdbc:h2:prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000'
properties {
maxActive = -1
minEvictableIdleTimeMillis=1800000
timeBetweenEvictionRunsMillis=1800000
numTestsPerEvictionRun=3
testOnBorrow=true
testWhileIdle=true
testOnReturn=true
validationQuery='SELECT 1'
}
}
}
// grails {
// mongo {
// if (cloud) {
// def mongoInfo = cloud.getServiceInfo('petclinic-mongodb')
// host = mongoInfo.host
// port = mongoInfo.port
// databaseName = mongoInfo.database
// username = mongoInfo.userName
// password = mongoInfo.password
// } else {
// host = 'localhost'
// port = 27107
// databaseName = 'foo'
// username = 'user'
// password = 'password'
// }
// }
// redis {
// if (cloud) {
// def redisInfo = cloud.getServiceInfo('petclinic-redis')
// host = redisInfo.host
// port = redisInfo.port
// password = redisInfo.password
// } else {
// host = 'localhost'
// port = 6379
// password = 'password'
// }
// }
// }
}
}
7 changes: 7 additions & 0 deletions manifest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
applications:
- name: petclinic
memory: 1G
instances: 1
path: target/petclinic-0.1.war
buildpack: https://github.com/cloudfoundry/java-buildpack.git