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

ptuomola 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 6e052e5  Replace command line Docker image build with Gradle Jib plugin
6e052e5 is described below

commit 6e052e536be5119b68ae095b923538912fde716a
Author: Aleksandar Vidakovic <[email protected]>
AuthorDate: Sun Jan 2 02:34:40 2022 +0100

    Replace command line Docker image build with Gradle Jib plugin
---
 .github/workflows/build-docker.yml                 |  2 +-
 Dockerfile                                         | 50 ----------------------
 README.md                                          |  4 +-
 build.gradle                                       |  1 +
 docker-compose.yml                                 |  6 +--
 entrypoint.sh                                      | 33 --------------
 fineract-provider/build.gradle                     | 47 ++++++++++++++++++++
 .../core/config/PersistenceConfig.java             |  7 ++-
 gradle.properties                                  |  2 +-
 9 files changed, 59 insertions(+), 93 deletions(-)

diff --git a/.github/workflows/build-docker.yml 
b/.github/workflows/build-docker.yml
index ec71251..25ceff9 100644
--- a/.github/workflows/build-docker.yml
+++ b/.github/workflows/build-docker.yml
@@ -9,7 +9,7 @@ jobs:
     steps:
       - uses: actions/checkout@v2
       - name: Build the image
-        run: docker-compose build
+        run: ./gradlew :fineract-provider:jibDockerBuild -x test
       - name: Start the stack
         run: docker-compose up -d
       - name: Wait for stack to come up
diff --git a/Dockerfile b/Dockerfile
deleted file mode 100644
index df852c3..0000000
--- a/Dockerfile
+++ /dev/null
@@ -1,50 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-FROM azul/zulu-openjdk-debian:11 AS builder
-
-RUN apt-get update -qq && apt-get install -y wget
-
-COPY . fineract
-WORKDIR /fineract
-
-RUN ./gradlew --no-daemon -q -x rat -x compileTestJava -x test -x 
spotlessJavaCheck -x spotlessJava bootJar
-
-WORKDIR /fineract/target
-RUN jar -xf /fineract/fineract-provider/build/libs/fineract-provider.jar
-
-# We download separately a JDBC driver (which not allowed to be included in 
Apache binary distribution)
-WORKDIR /fineract/target/BOOT-INF/libs
-RUN wget -q 
https://downloads.mariadb.com/Connectors/java/connector-java-2.7.3/mariadb-java-client-2.7.3.jar
-
-# =========================================
-
-FROM azul/zulu-openjdk-alpine:11 AS fineract
-
-COPY --from=builder /fineract/target/BOOT-INF/lib /app/lib
-COPY --from=builder /fineract/target/META-INF /app/META-INF
-COPY --from=builder /fineract/target/BOOT-INF/classes /app
-
-WORKDIR /
-
-COPY entrypoint.sh /entrypoint.sh
-
-RUN chmod 775 /entrypoint.sh
-
-EXPOSE 8443
-
-ENTRYPOINT ["/entrypoint.sh"]
diff --git a/README.md b/README.md
index 872abfe..d276d3e 100644
--- a/README.md
+++ b/README.md
@@ -118,7 +118,7 @@ Now to run a new Fineract instance you can simply:
 
 1. `git clone https://github.com/apache/fineract.git ; cd fineract`
 1. for windows, use `git clone https://github.com/apache/fineract.git --config 
core.autocrlf=input ; cd fineract`
-1. `docker-compose build`
+1. `./gradlew :fineract-provider:jibDockerBuild -x test`
 1. `docker-compose up -d`
 1. fineract (back-end) is running at https://localhost:8443/fineract-provider/
 1. wait for https://localhost:8443/fineract-provider/actuator/health to return 
`{"status":"UP"}`
@@ -126,8 +126,6 @@ Now to run a new Fineract instance you can simply:
 1. community-app (UI) is running at 
http://localhost:9090/?baseApiUrl=https://localhost:8443/fineract-provider&tenantIdentifier=default
 1. login using default _username_ `mifos` and _password_ `password`
 
-The [`docker-compose.yml`](docker-compose.yml) will build the `fineract` 
container from the source based on the [`Dockerfile`](Dockerfile).  You could 
change that to use the pre-built container image instead of having to re-build 
it.
-
 https://hub.docker.com/r/apache/fineract has a pre-built container image of 
this project, built continuously.
 
 You must specify the MySQL tenants database JDBC URL by passing it to the 
`fineract` container via environment
diff --git a/build.gradle b/build.gradle
index dfe9cb7..3888201 100644
--- a/build.gradle
+++ b/build.gradle
@@ -72,6 +72,7 @@ plugins {
     id 'org.asciidoctor.jvm.revealjs' version '3.3.2' apply false
     id 'org.asciidoctor.jvm.gems' version '3.3.2' apply false
     id 'org.asciidoctor.kindlegen.base' version '3.2.0' apply false
+    id "com.google.cloud.tools.jib" version "3.1.4" apply false
     id "org.sonarqube" version "3.3"
 }
 
diff --git a/docker-compose.yml b/docker-compose.yml
index 23435c8..b4d0af9 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -36,9 +36,9 @@ services:
     ports:
       - "3306:3306"
   fineract-server:
-    build:
-      context: .
-      target: fineract
+    image: fineract:latest
+    volumes:
+      - ./fineract-provider/build/data:/data
     healthcheck:
       test: ["CMD", 'sh', '-c', 'echo -e "Checking for the availability of 
Fineract server deployment"; while ! nc -z "fineract-server" 8443; do sleep 1; 
printf "-"; done; echo -e " >> Fineract server has started";' ]
       timeout: 10s
diff --git a/entrypoint.sh b/entrypoint.sh
deleted file mode 100755
index 320ed3b..0000000
--- a/entrypoint.sh
+++ /dev/null
@@ -1,33 +0,0 @@
-#!/bin/sh
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-
-# NOTE that we are limited to busybox's sh, and cannot use bash here, because
-# this is used in a container image based on azul/zulu-openjdk-alpine:17.
-
-# see e.g. https://explainshell.com/explain?cmd=set+-eux
-set -ex
-
-while ! nc -zvw3 "${FINERACT_DEFAULT_TENANTDB_HOSTNAME:-fineractmysql}" 
"${FINERACT_DEFAULT_TENANTDB_PORT:-3306}" ; do
-    >&2 echo "DB Server is unavailable - sleeping"
-    sleep 5
-done
->&2 echo "DB Server is up - executing command"
-
-java -cp "app:app/lib/*" org.apache.fineract.ServerApplication
diff --git a/fineract-provider/build.gradle b/fineract-provider/build.gradle
index 8c14d46..a763471 100644
--- a/fineract-provider/build.gradle
+++ b/fineract-provider/build.gradle
@@ -27,6 +27,7 @@ apply plugin: 'com.gorylenko.gradle-git-properties'
 apply plugin: 'io.swagger.core.v3.swagger-gradle-plugin'
 apply plugin: 'distribution'
 apply plugin: 'signing'
+apply plugin: 'com.google.cloud.tools.jib'
 
 // Configuration for the OpenJPA enhance task
 // https://github.com/radcortez/openjpa-gradle-plugin
@@ -246,6 +247,52 @@ bootJar {
     classifier = ''
 }
 
+jib {
+    from {
+        image = 'azul/zulu-openjdk-alpine:11'
+    }
+
+    to {
+        image = 'fineract'
+        tags = [
+            "${releaseVersion}",
+            'latest'
+        ]
+    }
+
+    container {
+        creationTime = 'USE_CURRENT_TIMESTAMP'
+        mainClass = 'org.apache.fineract.ServerApplication'
+        jvmFlags = [
+            '-Xmx1G',
+            '-Xms1G',
+            '-XshowSettings:vm',
+            '-XX:+UseContainerSupport',
+            '-XX:+UseStringDeduplication',
+            '-XX:MinRAMPercentage=25',
+            '-XX:MaxRAMPercentage=80'
+        ]
+        args = [
+            '-Duser.home=/tmp',
+            '-Dspring.profiles.active=basicauth',
+            '-Dfile.encoding=UTF-8',
+            '-Duser.timezone=UTC',
+            '-Djava.security.egd=file:/dev/./urandom'
+        ]
+        ports = ['8080/tcp', '8443/tcp']
+        labels = [maintainer: 'Aleksandar Vidakovic <[email protected]>']
+        user = 'nobody:nogroup'
+    }
+
+    allowInsecureRegistries = true
+
+    dependencies {
+        implementation 'org.mariadb.jdbc:mariadb-java-client:2.7.3'
+    }
+}
+
+tasks.jibDockerBuild.dependsOn = ["bootJar"]
+
 tasks.withType(Tar) {
     compression Compression.GZIP
     extension 'tar.gz'
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/config/PersistenceConfig.java
 
b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/config/PersistenceConfig.java
index a28db6f..4b14812 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/config/PersistenceConfig.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/config/PersistenceConfig.java
@@ -45,13 +45,16 @@ public class PersistenceConfig {
 
     @Bean
     @DependsOn("tenantDatabaseUpgradeService")
-    public EntityManagerFactory entityManagerFactory() {
+    public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
         final LocalContainerEntityManagerFactoryBean em = new 
LocalContainerEntityManagerFactoryBean();
         em.setDataSource(routingDataSource);
+        // NOTE: very important to set this explicitly when building Docker 
images with Jib; otherwise complains about
+        // duplicate resources
+        em.setPersistenceXmlLocation("classpath:META-INF/persistence.xml");
         em.setJpaVendorAdapter(new OpenJpaVendorAdapter());
         em.setPersistenceUnitName("jpa-pu");
         em.afterPropertiesSet();
-        return em.getObject();
+        return em;
     }
 
     @Bean
diff --git a/gradle.properties b/gradle.properties
index 2cb4e87..6c88940 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -17,5 +17,5 @@
 # under the License.
 #
 org.gradle.jvmargs=-Xmx2g
-releaseVersion=1.4.0
+releaseVersion=1.5.0
 buildType=BUILD

Reply via email to