Skip to content

Commit

Permalink
Add support to database config from docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
yamelsenih committed Sep 20, 2024
1 parent f2e0ebf commit 3827d5c
Show file tree
Hide file tree
Showing 12 changed files with 128 additions and 36 deletions.
14 changes: 0 additions & 14 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,6 @@
<attribute name="gradle_used_by_scope" value="main,test"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="bin/test" path="build/generated/source/proto/test/java">
<attributes>
<attribute name="gradle_scope" value="test"/>
<attribute name="gradle_used_by_scope" value="test"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="bin/test" path="build/generated/source/proto/test/grpc">
<attributes>
<attribute name="gradle_scope" value="test"/>
<attribute name="gradle_used_by_scope" value="test"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="bin/main" path="build/generated/source/proto/main/java">
<attributes>
<attribute name="gradle_scope" value="main"/>
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
- name: Build with Gradle
uses: gradle/gradle-build-action@v2
env:
GITHUB_DEPLOY_USER: "${{ github.actor }}"
GITHUB_DEPLOY_USER: "${{ secrets.DEPLOY_USER }}"
GITHUB_DEPLOY_TOKEN: "${{ secrets.DEPLOY_TOKEN }}"
GITHUB_DEPLOY_REPOSITORY: ${{ secrets.DEPLOY_REPOSITORY }}
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
gradle-version: 8.0.2
arguments: createRelease
env:
GITHUB_DEPLOY_USER: ${{ github.actor }}
GITHUB_DEPLOY_USER: ${{ secrets.DEPLOY_USER }}
GITHUB_DEPLOY_TOKEN: ${{ secrets.DEPLOY_TOKEN }}
GITHUB_DEPLOY_REPOSITORY: ${{ secrets.DEPLOY_REPOSITORY }}

Expand Down
11 changes: 11 additions & 0 deletions .settings/org.eclipse.buildship.core.prefs
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
arguments=
auto.sync=false
build.scans.enabled=false
connection.gradle.distribution=GRADLE_DISTRIBUTION(VERSION(8.0.2))
connection.project.dir=
eclipse.preferences.version=1
gradle.user.home=
java.home=
jvm.arguments=
offline.mode=false
override.workspace.settings=true
show.console.view=true
show.executions.view=true
26 changes: 17 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,23 @@ docker pull openls/adempiere-mobile-service:latest
To use this Docker image you must have your Docker engine version greater than or equal to 3.0.

### Environment variables
- `DB_TYPE`: Database Type (Supported `Oracle` and `PostgreSQL`). Default `PostgreSQL`
- `DB_HOST`: Hostname for data base server. Default: `localhost`
- `DB_PORT`: Port used by data base server. Default: `5432`
- `DB_NAME`: Database name that adempiere-mobile-service will use to connect with the database. Default: `adempiere`
- `DB_USER`: Database user that adempiere-mobile-service will use to connect with the database. Default: `adempiere`
- `DB_PASSWORD`: Database password that Adempiere-Backend will use to connect with the database. Default: `adempiere`
- `SERVER_PORT`: Port to access adempiere-mobile-service from outside of the container. Default: `50062`
- `SERVER_LOG_LEVEL`: Log Level. Default: `WARNING`
- `TZ`: (Time Zone) Indicates the time zone to set in the nginx-based container, the default value is `America/Caracas` (UTC -4:00).
* `DB_TYPE`: Database Type (Supported `Oracle` and `PostgreSQL`). Default `PostgreSQL`.
* `DB_HOST`: Hostname for data base server. Default: `localhost`.
* `DB_PORT`: Port used by data base server. Default: `5432`.
* `DB_NAME`: Database name that Adempiere-Backend will use to connect with the database. Default: `adempiere`.
* `DB_USER`: Database user that Adempiere-Backend will use to connect with the database. Default: `adempiere`.
* `DB_PASSWORD`: Database password that Adempiere-Backend will use to connect with the database. Default: `adempiere`.
* `IDLE_TIMEOUT`: It sets the maximum time a connection can sit around without being used before it gets closed to free up resources. Default: `300`.
* `MINIMUM_IDLE`: It sets the minimum number of connections that should be kept open and ready to use, even if they're not currently being used. This helps improve performance by reducing the time it takes to get a connection. Default: `1`.
* `MAXIMUM_POOL_SIZE`: It sets the maximum number of connections that can be open at the same time. This helps prevent the pool from getting too big and using up too much memory. Default: `10`.
* `CONNECTION_TIMEOUT`: it sets the maximum time HikariCP will wait to get a connection from the pool before giving up and throwing an error. Default: `5000`.
* `MAXIMUM_LIFETIME`: It sets the maximum amount of time a connection can stay open in the pool before it's automatically closed. This helps keep the pool clean and prevents problems. Default: `6000`.
* `KEEPALIVE_TIME`: It sets a test query that HikariCP will run on connections to make sure they're still working properly. Default: `360000`.
* `CONNECTION_TEST_QUERY`: It sets how often HikariCP will check if a connection is still working properly. This helps prevent problems with connections that might become inactive. Default: `SELECT 1`
* `SERVER_PORT`: Port to access Adempiere-Backend from outside of the container. Default: `50059`.
* `SERVER_LOG_LEVEL`: Log Level. Default: `WARNING`.
* `TZ`: (Time Zone) Indicates the time zone to set in the nginx-based container, the default value is `America/Caracas` (UTC -4:00).
* `SYSTEM_LOGO_URL`: Logo of the main image of the system, shown in the login screen.

You can download the last image from docker hub, just run the follow command:

Expand Down
12 changes: 7 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ repositories {
mavenLocal()
mavenCentral()
maven {
url = System.getenv("GITHUB_DEPLOY_REPOSITORY") ?: System.properties['deploy.repository'] ?: 'https://maven.pkg.github.com'
credentials {
username = System.getenv("GITHUB_DEPLOY_USER") ?: System.properties['deploy.user']
password = System.getenv("GITHUB_DEPLOY_TOKEN") ?: System.properties['deploy.token']
// Adempiere GitHub Organization
url = 'https://maven.pkg.github.com/adempiere/adempiere'
credentials {
// project property, system properrty, enviroment variable
username = findProperty("deployUsername") ?: System.properties['deploy.user'] ?: System.getenv("GITHUB_DEPLOY_USER")
password = findProperty("deployToken") ?: System.properties['deploy.token'] ?: System.getenv("GITHUB_DEPLOY_TOKEN")
}
}
}
Expand Down Expand Up @@ -152,7 +154,7 @@ dependencies {
implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.15.0'
// ADempiere Core
implementation "${baseGroupId}:base:${baseVersion}"
implementation "${baseGroupId}:adempiere-grpc-utils:1.3.4"
implementation "${baseGroupId}:adempiere-grpc-utils:1.5.1"
implementation "${baseGroupId}:human-resource-and-payroll:${baseVersion}"
// Others
compileOnly 'org.apache.tomcat:annotations-api:6.0.53'
Expand Down
11 changes: 9 additions & 2 deletions docker/backend_alpine.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,22 @@ LABEL maintainer="ySenih@erpya.com; EdwinBetanc0urt@outlook.com;" \

# Init ENV with default values
ENV \
SERVER_PORT="50062" \
SERVER_PORT="50059" \
SERVER_LOG_LEVEL="WARNING" \
DB_HOST="localhost" \
DB_PORT="5432" \
DB_NAME="adempiere" \
DB_USER="adempiere" \
DB_PASSWORD="adempiere" \
DB_TYPE="PostgreSQL" \
ADEMPIERE_APPS_TYPE="" \
IDLE_TIMEOUT="300" \
MINIMUM_IDLE="1" \
MAXIMUM_POOL_SIZE="10" \
CONNECTION_TIMEOUT="5000" \
MAXIMUM_LIFETIME="6000" \
KEEPALIVE_TIME="360000" \
CONNECTION_TEST_QUERY="\"SELECT 1\"" \
SYSTEM_LOGO_URL="" \
TZ="America/Caracas"

EXPOSE ${SERVER_PORT}
Expand Down
9 changes: 8 additions & 1 deletion docker/backend_focal.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@ ENV \
DB_USER="adempiere" \
DB_PASSWORD="adempiere" \
DB_TYPE="PostgreSQL" \
ADEMPIERE_APPS_TYPE="" \
IDLE_TIMEOUT="300" \
MINIMUM_IDLE="1" \
MAXIMUM_POOL_SIZE="10" \
CONNECTION_TIMEOUT="5000" \
MAXIMUM_LIFETIME="6000" \
KEEPALIVE_TIME="360000" \
CONNECTION_TEST_QUERY="\"SELECT 1\"" \
SYSTEM_LOGO_URL="" \
TZ="America/Caracas"

EXPOSE ${SERVER_PORT}
Expand Down
9 changes: 8 additions & 1 deletion docker/env.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
server:
port: 50062
port: 50059
host: localhost
log_level: WARNING
database:
Expand All @@ -9,3 +9,10 @@ database:
user: "adempiere_user_value"
password: "adempiere_pass_value"
type: PostgreSQL
idle_timeout: fill_idle_timeout
minimum_idle: fill_minimum_idle
maximum_pool_size: fill_maximum_pool_size
connection_timeout: fill_connection_timeout
maximum_lifetime: fill_maximum_lifetime
keepalive_time: fill_keepalive_time
connection_test_query: fill_connection_test_query
9 changes: 8 additions & 1 deletion docker/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# @autor Yamel Senih <ysenih@erpya.com>

# Set server values
sed -i "s|50062|$SERVER_PORT|g" env.yaml
sed -i "s|50059|$SERVER_PORT|g" env.yaml
sed -i "s|WARNING|$SERVER_LOG_LEVEL|g" env.yaml

export DEFAULT_JAVA_OPTIONS='"-Xms64M" "-Xmx1512M"'
Expand All @@ -13,6 +13,13 @@ sed -i "s|adempiere_database_value|$DB_NAME|g" env.yaml
sed -i "s|adempiere_user_value|$DB_USER|g" env.yaml
sed -i "s|adempiere_pass_value|$DB_PASSWORD|g" env.yaml
sed -i "s|PostgreSQL|$DB_TYPE|g" env.yaml
sed -i "s|fill_idle_timeout|$IDLE_TIMEOUT|g" env.yaml
sed -i "s|fill_minimum_idle|$MINIMUM_IDLE|g" env.yaml
sed -i "s|fill_maximum_pool_size|$MAXIMUM_POOL_SIZE|g" env.yaml
sed -i "s|fill_connection_timeout|$CONNECTION_TIMEOUT|g" env.yaml
sed -i "s|fill_maximum_lifetime|$MAXIMUM_LIFETIME|g" env.yaml
sed -i "s|fill_keepalive_time|$KEEPALIVE_TIME|g" env.yaml
sed -i "s|fill_connection_test_query|$CONNECTION_TEST_QUERY|g" env.yaml
sed -i "s|$DEFAULT_JAVA_OPTIONS|$GRPC_JAVA_OPTIONS|g" bin/adempiere-mobile-service-server

# Run app
Expand Down
42 changes: 42 additions & 0 deletions src/main/java/org/spin/mobile_service/setup/Database.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ public class Database {
private String name;
/** Database type */
private String type;
/** IDLE Timeout */
private long idle_timeout;
/** Minimum IDLE */
private int minimum_idle;
/** Maximum Pool Size */
private int maximum_pool_size;
/** Connection Timeout */
private long connection_timeout;
/** Maximum Lifetime */
private long maximum_lifetime;
/** Keepalive Time */
private long keepalive_time;
/** Connection Test Query */
private String connection_test_query;

/**
* Default constructor
Expand Down Expand Up @@ -100,6 +114,34 @@ public final String getType() {
return type;
}

public long getIdle_timeout() {
return idle_timeout;
}

public int getMinimum_idle() {
return minimum_idle;
}

public int getMaximum_pool_size() {
return maximum_pool_size;
}

public long getConnection_timeout() {
return connection_timeout;
}

public long getMaximum_lifetime() {
return maximum_lifetime;
}

public long getKeepalive_time() {
return keepalive_time;
}

public String getConnection_test_query() {
return connection_test_query;
}

@Override
public String toString() {
return "Database [host=" + host + ", port=" + port + ", user=" + user + ", password=******, name="
Expand Down
17 changes: 16 additions & 1 deletion src/main/java/org/spin/mobile_service/setup/SetupLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.compiere.util.DB;
import org.compiere.util.Ini;
import org.spin.mobile_service.setup.SetupLoader;
import org.spin.server.config.BackendDatabaseConfig;

import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
Expand Down Expand Up @@ -109,7 +110,21 @@ public void validateLoad() throws Exception {
// Set default init
Ini.setProperty(Ini.P_CONNECTION, connection.toStringLong());
Ini.setClient(true);
// Ini.setProperty(Ini.P_ADEMPIERE_APPS_TYPE, "wildfly");
// Set Database default parameters
// Close inactive connections after 5 minutes 300
BackendDatabaseConfig.setIdleTimeout(dataBase.getIdle_timeout());
// Minimum connection opening 1
BackendDatabaseConfig.setMinimumIdle(dataBase.getMinimum_idle());
// 10
BackendDatabaseConfig.setMaximumPoolSize(dataBase.getMaximum_pool_size() + 1);
// New connection waiting time 5 seconds 5000
BackendDatabaseConfig.setConnectionTimeout(dataBase.getConnection_timeout());
// Close connections after 10 minutes
BackendDatabaseConfig.setMaxLifetime(dataBase.getMaximum_lifetime());
// Validate connection each 6 minutes 360000
BackendDatabaseConfig.setKeepaliveTime(dataBase.getKeepalive_time());
// Test connection just make a ping to validate database "SELECT 1"
BackendDatabaseConfig.setConnectionTestQuery(dataBase.getConnection_test_query());
Level logLevel = Level.parse(setup.getServer().getLog_level().toUpperCase());
Ini.setProperty(Ini.P_TRACEFILE, logLevel.getName());
CLogMgt.setLevel(logLevel);
Expand Down

0 comments on commit 3827d5c

Please sign in to comment.