Skip to content

Commit

Permalink
Allow Java system properties to override config
Browse files Browse the repository at this point in the history
This re-enables the Heroku setup now that the maven system properties
can no longer override the database credentials. To be documented later,
as tracked on GitHub.

Co-Authored-By: Ino de Bruijn <[email protected]>
  • Loading branch information
fedde-s and inodb committed Sep 21, 2018
1 parent 5c51c2d commit cbcbd05
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 10 deletions.
9 changes: 4 additions & 5 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@
},
"MAVEN_CUSTOM_OPTS": {
"description":"set heroku profile for mvn",
"value":"-Pheroku,public -DskipTests -Dfinal.war.name=cbioportal -Ddb.user=cbio_user -Ddb.password=cbio_pass -Ddb.portal_db_name=public_test_small -Dtomcat.catalina.scope=runtime -Ddb.connection_string=jdbc:mysql://sm4sa6ozhn5ya6.cuooweljyhix.us-east-1.rds.amazonaws.com:3306/ -Ddb.host=sm4sa6ozhn5ya6.cuooweljyhix.us-east-1.rds.amazonaws.com"
"value":"-Pheroku,public -DskipTests -Dtomcat.catalina.scope=runtime -Dfinal.war.name=cbioportal"
},
"FRONTEND_URL": {
"description":"set frontend URL to use (default: empty string, uses frontend inside war)",
"value":"",
"required":false
"SPRING_OPTS": {
"description":"set spring properties with e.g. -Dshow.civic=true (TODO: not all props work atm)",
"value":"-Dtomcat.catalina.scope=runtime -Ddb.user=cbio_user -Ddb.password=cbio_pass -Ddb.portal_db_name=public_test_small -Ddb.connection_string=jdbc:mysql://devdb.cbioportal.org:3306/ -Ddb.host=devdb.cbioportal.org -Dshow.civic=true -Ddbconnector=dbcp -Dsuppress_schema_version_mismatch_errors=true"
}
},
"buildpacks": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,9 @@

package org.mskcc.cbio.portal.util;

import org.mskcc.cbio.portal.servlet.QueryBuilder;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.ClassPathResource;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -308,9 +305,49 @@ public static String parseUrl(String url)
public void setFrontendUrlRuntime(String property) { frontendUrlRuntime = property; }

private static Log LOG = LogFactory.getLog(GlobalProperties.class);
private static Properties portalProperties = initializeProperties(PORTAL_PROPERTIES_FILE_NAME);
private static ConfigPropertyResolver portalProperties = new ConfigPropertyResolver();
private static Properties mavenProperties = initializeProperties(MAVEN_PROPERTIES_FILE_NAME);

/**
* Minimal portal property resolver that takes system property overrides.
*
* Provides properties from runtime or the baked-in
* portal.properties config file, but takes overrides from <code>-D</code>
* system properties.
*/
private static class ConfigPropertyResolver {
private Properties configFileProperties;
/**
* Finds the config file for properties not overridden by system props.
*
* Either the runtime or buildtime portal.properties file.
*/
public ConfigPropertyResolver() {
configFileProperties = initializeProperties(PORTAL_PROPERTIES_FILE_NAME);
}
/**
* Finds the property with the specified key, or returns the default.
*/
public String getProperty(String key, String defaultValue) {
String propertyValue = configFileProperties.getProperty(key, defaultValue);
return System.getProperty(key, propertyValue);
}
/**
* Finds the property with the specified key, or returns null.
*/
public String getProperty(String key) {
return getProperty(key, null);
}
/**
* Tests if a property has been specified for this key.
*
* @return true iff the property was specified, even if blank.
*/
public boolean containsKey(String key) {
return getProperty(key) != null;
}
}

private static Properties initializeProperties(String propertiesFileName)
{
return loadProperties(getResourceStream(propertiesFileName));
Expand Down
2 changes: 1 addition & 1 deletion heroku/Procfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
web: java $JAVA_OPTS -Dfrontend.url=$FRONTEND_URL -Dshow.civic=true -Ddb.suppress_schema_version_mismatch_errors=true -Dsession.service.url=https://cbioportal-session-service.herokuapp.com/api/sessions/heroku_portal/ -Ddbconnector=dbcp -jar portal/target/dependency/webapp-runner.jar --enable-compression --expand-war --port $PORT portal/target/cbioportal.war
web: java $JAVA_OPTS $SPRING_OPTS -jar portal/target/dependency/webapp-runner.jar --enable-compression --expand-war --port $PORT portal/target/cbioportal.war

0 comments on commit cbcbd05

Please sign in to comment.