You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fineract.apache.org by aw...@apache.org on 2019/11/26 07:16:10 UTC

[fineract] branch develop updated: Allow customizing JDBC URLs at run-time instead of during container build (FINERACT-773)

This is an automated email from the ASF dual-hosted git repository.

awasum pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract.git


The following commit(s) were added to refs/heads/develop by this push:
     new edc9e03  Allow customizing JDBC URLs at run-time instead of during container build (FINERACT-773)
     new c6d8a49  Merge pull request #648 from vorburger/FINERACT-773_Dockerfile-JDBC-URL
edc9e03 is described below

commit edc9e030e10b9f7f6c394ab35c307c7fa28939a0
Author: Michael Vorburger <mi...@vorburger.ch>
AuthorDate: Sun Oct 13 13:57:28 2019 +0200

    Allow customizing JDBC URLs at run-time instead of during container build (FINERACT-773)
    
    In Docker, set JAVA_OPTS instead of FINERACT_TENANTS_URL.
    
    Because ARG/ENV in the Dockerfile can't (easily) be changed at run-time.
    
    At first I tried to override the ENTRYPOINT with a script which sets
    JAVA_OPTS based on FINERACT_TENANTS_URL and then delegates to the original
    /app-entrypoint.sh; that didn't immediately work, so this seems simpler.
    
    Including make default tenant JDBC hostname & port configurable at Docker container run instead of build time.
---
 .travis.yml                                                  |  3 ++-
 Dockerfile                                                   | 12 ++++++------
 README.md                                                    | 12 +++++-------
 docker-compose.yml                                           |  4 ++++
 docker/server.xml                                            |  2 +-
 .../core/service/TenantDatabaseUpgradeService.java           |  7 ++++++-
 .../migrations/list_db/V1__mifos-platform-shared-tenants.sql |  2 +-
 7 files changed, 25 insertions(+), 17 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 91d999f..1d42d3e 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -62,4 +62,5 @@ script:
 # @see https://docs.travis-ci.com/user/job-lifecycle/#customizing-the-build-phase
   - ./gradlew --console=plain licenseMain licenseTest licenseIntegrationTest test  &&  ./gradlew --console=plain integrationTest
 # We must stop mysql the mysql system service to avoid port 3306 conflicts (unless we run the mysql in docker-compose on another port; req. FINERACT-773)
-  - sudo service mysql stop  &&  docker-compose build  &&  docker-compose up -d  &&  sleep 30s  &&  http --verify=no --timeout 240 --check-status get https://localhost:8443/fineract-provider/actuator/health
+  - sudo service mysql stop  &&  docker-compose build  &&  docker-compose up -d  &&  sleep 30s  &&  http --verify=no --timeout 240 --check-status get https://localhost:8443/fineract-provider/actuator/health || docker logs fineract_fineract-server_1
+# The || docker logs lets use see the root cause in case of failures
diff --git a/Dockerfile b/Dockerfile
index 4a86d1e..299bf36 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -21,23 +21,23 @@ RUN mkdir fineract
 COPY . fineract
 
 WORKDIR fineract
-ARG mysqlserver=fineractmysql
-RUN sed -i "s/localhost/${mysqlserver}/" ./fineract-provider/src/main/resources/sql/migrations/list_db/V1__mifos-platform-shared-tenants.sql
-RUN ./gradlew clean -x test war
+RUN ./gradlew clean -x rat -x test war
 
+# =========================================
 
 FROM bitnami/tomcat:7.0.94 as fineract
 
+ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64/jre
+
 USER root
-ARG mysqlserver=fineractmysql
 RUN apt-get update -qq && apt-get install -y wget
-ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64/jre
 
 COPY --from=builder /fineract/build/libs/fineract-provider.war /opt/bitnami/tomcat/webapps
 
 RUN keytool -genkey -keyalg RSA -alias tomcat -keystore /opt/bitnami/tomcat/tomcat.keystore -keypass xyz123 -storepass xyz123 -noprompt -dname "CN=Fineract, OU=Fineract, O=Fineract, L=Unknown, ST=Unknown, C=Unknown"
 COPY ./docker/server.xml /opt/bitnami/tomcat/conf
-RUN sed -i "s/fineractmysql/${mysqlserver}/" /opt/bitnami/tomcat/conf/server.xml
 RUN chmod 664 /opt/bitnami/tomcat/conf/server.xml
 WORKDIR /opt/bitnami/tomcat/lib
+# org.drizzle.jdbc.DrizzleDriver is used in docker/server.xml for jdbc/mifosplatform-tenants DataSource
+# (But note that connections to individual tenant DBs may use another driver...)
 RUN wget http://central.maven.org/maven2/org/drizzle/jdbc/drizzle-jdbc/1.4/drizzle-jdbc-1.4.jar
diff --git a/README.md b/README.md
index 6c4cd00..8b3a81b 100644
--- a/README.md
+++ b/README.md
@@ -95,13 +95,11 @@ The [`docker-compose.yml`](docker-compose.yml) will build the `fineract` contain
 
 https://hub.docker.com/r/apache/fineract has a pre-built container of this project, built continuously.
 
-You can use a MySQL database from a different or remote server by passing the server's IP address to the docker fineract build process like this:
-
-    docker build --build-arg mysqlserver=<MySQL server IP> -t fineract:latest .
-
-The run it:
-
-    docker run -d fineract:latest
+You must specify the MySQL tenants database JDBC URL by passing it to the `fineract` container via environment
+variables; please consult the [`docker-compose.yml`](docker-compose.yml) for exact details how to specify those.
+_(Note that in previous versions, the `mysqlserver` environment variable used at `docker build` time instead of at
+`docker run` time did something similar; this has changed in [FINERACT-773](https://issues.apache.org/jira/browse/FINERACT-773)),
+and the `mysqlserver` environment variable is now no longer supported.)_
 
 
 Version
diff --git a/docker-compose.yml b/docker-compose.yml
index 5f7faec..88515c0 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -42,3 +42,7 @@ services:
       - 8443:8443
     depends_on:
       - fineractmysql
+    environment:
+      - JAVA_OPTS=-Dfineract_tenants_url=jdbc:mysql:thin://fineractmysql:3306/mifosplatform-tenants -Djava.awt.headless=true -XX:+UseG1GC -Dfile.encoding=UTF-8
+      - FINERACT_DEFAULT_TENANTDB_HOSTNAME=fineractmysql
+      - FINERACT_DEFAULT_TENANTDB_PORT=3306
diff --git a/docker/server.xml b/docker/server.xml
index 11508eb..9c8e23a 100644
--- a/docker/server.xml
+++ b/docker/server.xml
@@ -42,7 +42,7 @@
         name="jdbc/mifosplatform-tenants"
         factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
         driverClassName="org.drizzle.jdbc.DrizzleDriver"
-        url="jdbc:mysql:thin://fineractmysql:3306/mifosplatform-tenants"
+        url="${fineract_tenants_url}"
         username="root"
         password="mysql"
         initialSize="3"
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/service/TenantDatabaseUpgradeService.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/service/TenantDatabaseUpgradeService.java
index 740dcb5..0a1c91b 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/service/TenantDatabaseUpgradeService.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/service/TenantDatabaseUpgradeService.java
@@ -32,6 +32,8 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.stereotype.Service;
 
+import com.google.common.collect.ImmutableMap;
+
 import com.googlecode.flyway.core.Flyway;
 import com.googlecode.flyway.core.api.FlywayException;
 import com.googlecode.flyway.core.util.jdbc.DriverDataSource;
@@ -90,8 +92,11 @@ public class TenantDatabaseUpgradeService {
         flyway.setDataSource(tenantDataSource);
         flyway.setLocations("sql/migrations/list_db");
         flyway.setOutOfOrder(true);
+        flyway.setPlaceholders(ImmutableMap.of( // FINERACT-773
+            "fineract_default_tenantdb_hostname", System.getProperty("FINERACT_DEFAULT_TENANTDB_HOSTNAME", "localhost"),
+            "fineract_default_tenantdb_port",     System.getProperty("FINERACT_DEFAULT_TENANTDB_PORT", "3306")));
         flyway.migrate();
 
         tenantDataSourcePortFixService.fixUpTenantsSchemaServerPort();
     }
-}
\ No newline at end of file
+}
diff --git a/fineract-provider/src/main/resources/sql/migrations/list_db/V1__mifos-platform-shared-tenants.sql b/fineract-provider/src/main/resources/sql/migrations/list_db/V1__mifos-platform-shared-tenants.sql
index 9ec2f2f..4cc1f95 100644
--- a/fineract-provider/src/main/resources/sql/migrations/list_db/V1__mifos-platform-shared-tenants.sql
+++ b/fineract-provider/src/main/resources/sql/migrations/list_db/V1__mifos-platform-shared-tenants.sql
@@ -66,7 +66,7 @@ CREATE TABLE `tenants` (
 
 LOCK TABLES `tenants` WRITE;
 /*!40000 ALTER TABLE `tenants` DISABLE KEYS */;
-INSERT INTO `tenants` VALUES (1,'default','Default Demo Tenant','mifostenant-default','Asia/Kolkata',NULL,NULL,NULL,NULL,'localhost','3306','root','mysql',1);
+INSERT INTO `tenants` VALUES (1,'default','Default Demo Tenant','mifostenant-default','Asia/Kolkata',NULL,NULL,NULL,NULL,'${fineract_default_tenantdb_hostname}','${fineract_default_tenantdb_port}','root','mysql',1);
 -- Add tenants to support interoperation multi-tenancy
 -- INSERT INTO `tenants` VALUES (2,'tn01','Buffalo','tn01','Africa/Bujumbura',NULL,NULL,NULL,NULL,'localhost','3306','root','mysql',1);
 -- INSERT INTO `tenants` VALUES (3,'tn02','Lion','tn02','Africa/Bujumbura',NULL,NULL,NULL,NULL,'localhost','3306','root','mysql',1);