Skip to content

Commit

Permalink
Add database setup support
Browse files Browse the repository at this point in the history
  • Loading branch information
yamelsenih committed Sep 21, 2024
1 parent 374a301 commit 1ecc055
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 25 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ jobs:
architecture: x64

- name: Build with Gradle
uses: gradle/actions/setup-gradle@v3
uses: gradle/gradle-build-action@v3
env:
GITHUB_DEPLOY_USER: "${{ secrets.DEPLOY_USER }}"
GITHUB_DEPLOY_TOKEN: "${{ secrets.DEPLOY_TOKEN }}"
GITHUB_DEPLOY_REPOSITORY: ${{ secrets.DEPLOY_REPOSITORY }}
with:
gradle-version: 8.0.2
arguments: build
env:
GITHUB_DEPLOY_USER: ${{ github.actor }}
GITHUB_DEPLOY_TOKEN: ${{ secrets.DEPLOY_TOKEN }}
GITHUB_DEPLOY_REPOSITORY: ${{ secrets.DEPLOY_REPOSITORY }}
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,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
26 changes: 17 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,23 @@ docker pull openls/adempiere-processors-service:alpine-1.0.1
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-processors-service will use to connect with the database. Default: `adempiere`
- `DB_USER`: Database user that adempiere-processors-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-processors-service 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).
* `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
5 changes: 2 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,14 @@ repositories {
mavenCentral()
maven {
// Adempiere GitHub Organization
url = findProperty("deployRepository") ?: System.properties['deploy.repository'] ?: System.getenv("GITHUB_DEPLOY_REPOSITORY") ?: 'https://maven.pkg.github.com'
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")
}
}
}

protobuf {
protoc {
artifact = "com.google.protobuf:protoc:${protobufVersion}"
Expand Down Expand Up @@ -161,7 +160,7 @@ dependencies {

// ADempiere Core
implementation "${baseGroupId}:base:${baseVersion}"
implementation "${baseGroupId}:adempiere-grpc-utils:1.4.8"
implementation "${baseGroupId}:adempiere-grpc-utils:1.5.1"
implementation "${baseGroupId}:adempiere-business-processors:1.1.5"
// Others
compileOnly 'org.apache.tomcat:annotations-api:6.0.53'
Expand Down
12 changes: 9 additions & 3 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@ 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"

WORKDIR /opt/apps/server

Expand All @@ -21,8 +29,6 @@ COPY docker/start.sh /opt/apps/server/start.sh

EXPOSE ${SERVER_PORT}

# timezone
ENV TZ America/Caracas

# Add operative system dependencies
RUN apt-get update && apt-get install -y tzdata \
Expand Down
12 changes: 9 additions & 3 deletions docker/Dockerfile.alpine
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@ 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"

WORKDIR /opt/apps/server

Expand All @@ -21,8 +29,6 @@ COPY docker/start.sh /opt/apps/server/start.sh

EXPOSE ${SERVER_PORT}

# timezone
ENV TZ America/Caracas

# Add operative system dependencies
RUN rm -rf /var/cache/apk/* && \
Expand Down
7 changes: 7 additions & 0 deletions docker/env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions docker/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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-processors-service-server

# Run app
Expand Down
42 changes: 42 additions & 0 deletions src/main/java/org/spin/processor/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/processor/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.processor.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 1ecc055

Please sign in to comment.