This is an automated email from the ASF dual-hosted git repository. danwatford pushed a commit to branch experimental-docker in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git
The following commit(s) were added to refs/heads/experimental-docker by this push: new 34e5e958ec Implemented: Postgres connection from OFBiz container (OFBIZ-12757) 34e5e958ec is described below commit 34e5e958ec5e4e33042f16629b7928a4987a32d2 Author: Daniel Watford <dan...@watfordconsulting.com> AuthorDate: Sat Mar 4 14:20:40 2023 +0000 Implemented: Postgres connection from OFBiz container (OFBIZ-12757) Postgres connection enabled based on environment variables. Example docker-compose configuration configured with PostgreSQL database added to sources. --- .github/workflows/docker-image.yaml | 6 +- DOCKER.md | 43 ++++- Dockerfile | 29 ++-- docker/docker-entrypoint.sh | 103 +++++++++-- docker/examples/postgres-demo/docker-compose.yml | 26 +++ docker/examples/postgres-demo/ofbiz-postgres.env | 13 ++ .../postgres-initdb.d/10-init-user-db.sh | 16 ++ docker/examples/postgres-demo/postgres.env | 2 + docker/templates/postgres-entityengine.xml | 188 +++++++++++++++++++++ 9 files changed, 388 insertions(+), 38 deletions(-) diff --git a/.github/workflows/docker-image.yaml b/.github/workflows/docker-image.yaml index 11e9f223e0..8e86839a18 100644 --- a/.github/workflows/docker-image.yaml +++ b/.github/workflows/docker-image.yaml @@ -23,7 +23,7 @@ on: jobs: docker_build: - name: Build OFBiz docker container image + name: Build and push OFBiz docker container images runs-on: ubuntu-latest steps: - name: Check out OFBiz sources @@ -49,7 +49,7 @@ jobs: # Construct container tag based on branch name, string 'branch' and the short format of the commit SHA. type=ref,event=branch,suffix=-branch-{{sha}},priority=600 - - name: Build runtime docker image + - name: Build and push runtime docker image uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671 with: context: . @@ -68,7 +68,7 @@ jobs: type=ref,event=branch,suffix=-branch-preloaddemo-snapshot,priority=650 type=ref,event=branch,suffix=-branch-preloaddemo-{{sha}},priority=600 - - name: Build demo docker image + - name: Build and push demo docker image uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671 with: context: . diff --git a/DOCKER.md b/DOCKER.md index f56d01d676..5fd7d77ce2 100644 --- a/DOCKER.md +++ b/DOCKER.md @@ -68,13 +68,14 @@ Environment variables are used in `docker-entrypoint.sh` to control configuratio |Environment variable | Default value | Description | |---|---|---| -|OFBIZ_SKIP_INIT | *empty* | Any non-empty value will cause this script to skip any initialisation steps. | +|OFBIZ_SKIP_INIT | *empty* | Any non-empty value will cause the docker-entrypoint.sh script to skip any initialisation steps. | |OFBIZ_ADMIN_USER | admin | Sets the username of the OFBIZ admin user. | |OFBIZ_ADMIN_PASSWORD | ofbiz | Sets the password of the OFBIZ admin user. | |OFBIZ_DATA_LOAD | seed | Determine what type of data loading is required. *none*: No data loading is perfomed. *seed*: Seed data is loaded. *demo*: Demo data is loaded. | |OFBIZ_HOST | <empty> | Specify the hostname used to access OFBiz. If empty then the default value of host-headers-allowed from framework/security/config/security.properties is used. | |OFBIZ_CONTENT_URL_PREFIX | <empty> | Used to set the content.url.prefix.secure and content.url.prefix.standard properties in `framework/webapp/config/url.properties`. | |OFBIZ_ENABLE_AJP_PORT | *empty* | Enable the AJP (Apache JServe Protocol) port to allow communication with OFBiz via a reverse proxy. Enabled when this environment variable contains a non-empty value. | +|OFBIZ_SKIP_DB_DRIVER_DOWNLOAD | *empty* | Any non-empty value will cause the docker-entrypoint.sh script to skip downloading of any database drivers. | ### Hooks At various steps of initialisation, the `docker-entrypoint.sh` script will check for @@ -87,14 +88,14 @@ be executed, otherwise it will be sourced. |Directory | Step | |---|---| -| `/docker-entrypoint-before-config-applied.d` | Scripts processed before configuration, such as modifications to property files, are applied. | -| `/docker-entrypoint-after-config-applied.d` | Scripts processed after configuration modifications have been applied. | -| `/docker-entrypoint-before-data-load.d` | Scripts processed before data loading is executed. Could be used to apply modifications to data files.| -| `/docker-entrypoint-after-data-load.d` | Scripts processed after data loading is executed. | +| `/docker-entrypoint-hooks/before-config-applied.d` | Scripts processed before configuration, such as modifications to property files, are applied. | +| `/docker-entrypoint-hooks/after-config-applied.d` | Scripts processed after configuration modifications have been applied. | +| `/docker-entrypoint-hooks/before-data-load.d` | Scripts processed before data loading is executed. Could be used to apply modifications to data files.| +| `/docker-entrypoint-hooks/after-data-load.d` | Scripts processed after data loading is executed. | ### Data files During the data loading step - but after either seed or demo data has been loaded - directory -`/docker-entrypoint-additional-data.d` will be checked to see if any files are present. +`/docker-entrypoint-hooks/additional-data.d` will be checked to see if any files are present. If files are present then the load-data functionality in OFBiz will be executed, specifying the `/docker-entrypoint-additional-data.d` directory as a data source. Any `.xml` files in this @@ -103,6 +104,36 @@ directory will be treated as a data source and will be imported by the entity en This functionality can be used to pre-load OFBiz with user-specific data, such as a chart of accounts. +### Database +By default the OFBiz container will use an internal Derby database, storing database related files +in the /ofbiz/runtime volume. + +Use of an external database can be configured through environment variables. + +#### Derby +To use the embedded Derby database, ensure all database related environment variables are unset. + +#### PostgreSQL +To use a Postgres database set the `OFBIZ_POSTGRES_HOST` environment variable. + +Environment variable | Default | Description +---|---|--- +OFBIZ_POSTGRES_HOST | *unset* | Hostname of the PostgreSQL database server. +OFBIZ_POSTGRES_OFBIZ_DB | ofbiz | Name of the *ofbiz* database. +OFBIZ_POSTGRES_OFBIZ_USER | ofbiz | Username when connecting to the ofbiz database. +OFBIZ_POSTGRES_OFBIZ_PASSWORD | ofbiz | Password when connecting to the ofbiz database. +OFBIZ_POSTGRES_OLAP_DB | ofbizolap | Name of the *olap* database. +OFBIZ_POSTGRES_OLAP_USER | ofbizolap | Username when connecting to the olap database. +OFBIZ_POSTGRES_OLAP_PASSWORD | ofbizolap | Password when connecting to the olap database. +OFBIZ_POSTGRES_TENANT_DB | ofbiztenant | Name of the *tenant* database. +OFBIZ_POSTGRES_TENANT_USER | ofbiztenant | Username when connecting to the tenant database. +OFBIZ_POSTGRES_TENANT_PASSWORD | ofbiztenant | Password when connecting to the tenant database. + +The docker-entrypoint.sh script will download a JDBC driver to access the PostgreSQL server and +place the script in the `/ofbiz/lib-extra` volume. If you wish to skip this step then set the +OFBIZ_SKIP_DB_DRIVER_DOWNLOAD environment variable to a non-empty value. This would be +useful if you have already placed a suitable database driver in the `/ofbiz/lib-extra` volume. + ## Examples of running the OFBiz container ``` diff --git a/Dockerfile b/Dockerfile index f7f1d47e7b..ce03f968c8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -32,11 +32,14 @@ FROM eclipse-temurin:17 as runtimebase RUN ["useradd", "ofbiz"] -# Configure volumes where hooks into the startup process can be placed. -RUN ["mkdir", "/docker-entrypoint-before-config-applied.d", "/docker-entrypoint-after-config-applied.d", \ - "/docker-entrypoint-before-data-load.d", "/docker-entrypoint-after-data-load.d", \ - "/docker-entrypoint-additional-data.d"] -RUN ["sh", "-c", "/usr/bin/chown -R ofbiz:ofbiz /docker-entrypoint-*.d" ] +# Create directories used to mount volumes where hooks into the startup process can be placed. +RUN ["mkdir", "--parents", \ + "/docker-entrypoint-hooks/before-config-applied.d", \ + "/docker-entrypoint-hooks/after-config-applied.d", \ + "/docker-entrypoint-hooks/before-data-load.d", \ + "/docker-entrypoint-hooks/after-data-load.d", \ + "/docker-entrypoint-hooks/additional-data.d"] +RUN ["/usr/bin/chown", "-R", "ofbiz:ofbiz", "/docker-entrypoint-hooks" ] USER ofbiz WORKDIR /ofbiz @@ -45,10 +48,12 @@ WORKDIR /ofbiz RUN --mount=type=bind,from=builder,source=/builder/build/distributions/ofbiz.tar,target=/mnt/ofbiz.tar \ ["tar", "--extract", "--strip-components=1", "--file=/mnt/ofbiz.tar"] -RUN ["mkdir", "/ofbiz/runtime", "/ofbiz/config"] +# Create directories for OFBiz volume mountpoints. +RUN ["mkdir", "/ofbiz/runtime", "/ofbiz/config", "/ofbiz/lib-extra"] COPY docker/docker-entrypoint.sh . COPY docker/send_ofbiz_stop_signal.sh . +COPY docker/templates templates EXPOSE 8443 EXPOSE 8009 @@ -67,17 +72,13 @@ RUN mkdir --parents /ofbiz/runtime/container_state RUN touch /ofbiz/runtime/container_state/data_loaded RUN touch /ofbiz/runtime/container_state/admin_loaded -VOLUME ["/docker-entrypoint-before-config-applied.d", "/docker-entrypoint-after-config-applied.d", \ - "/docker-entrypoint-before-data-load.d", "/docker-entrypoint-after-data-load.d", \ - "/docker-entrypoint-additional-data.d"] -VOLUME ["/ofbiz/config", "/ofbiz/runtime"] +VOLUME ["/docker-entrypoint-hooks"] +VOLUME ["/ofbiz/config", "/ofbiz/runtime", "/ofbiz/lib-extra"] ################################################################################### # Runtime image with no data loaded. FROM runtimebase as runtime -VOLUME ["/docker-entrypoint-before-config-applied.d", "/docker-entrypoint-after-config-applied.d", \ - "/docker-entrypoint-before-data-load.d", "/docker-entrypoint-after-data-load.d", \ - "/docker-entrypoint-additional-data.d"] -VOLUME ["/ofbiz/config", "/ofbiz/runtime"] +VOLUME ["/docker-entrypoint-hooks"] +VOLUME ["/ofbiz/config", "/ofbiz/runtime", "/ofbiz/lib-extra"] diff --git a/docker/docker-entrypoint.sh b/docker/docker-entrypoint.sh index 9aefe492e7..6eaca1e464 100755 --- a/docker/docker-entrypoint.sh +++ b/docker/docker-entrypoint.sh @@ -23,6 +23,7 @@ # Triggers the loading of data and configuration of various OFBiz properties before # executing the command given as arguments to the script. # +# # Behaviour controlled by environment variables: # # OFBIZ_SKIP_INIT @@ -60,14 +61,43 @@ # Enabled when this environment variable contains a non-empty value. # Default value: <empty> # +# OFBIZ_SKIP_DB_DRIVER_DOWNLOAD +# When connecting to databases other than the OFBiz embedded Derby database a suitable driver will be needed. +# This script will attempt to download a suitable driver unless the OFBIZ_SKIP_DB_DRIVER_DOWNLOAD contains a non-empty +# value. +# +# OFBIZ_POSTGRES_HOST +# Sets the name of the PostgreSQL database host. +# If OFBIZ_POSTGRES_HOST is non-empty, then the following OFBIZ_POSTGRES_* environment variables are used to configure +# access to PostgreSQL databases. +# OFBIZ_POSTGRES_OFBIZ_DB Default: ofbiz +# OFBIZ_POSTGRES_OFBIZ_USER Default: ofbiz +# OFBIZ_POSTGRES_OFBIZ_PASSWORD Default: ofbiz +# OFBIZ_POSTGRES_OLAP_DB Default: ofbizolap +# OFBIZ_POSTGRES_OLAP_USER Default: ofbizolap +# OFBIZ_POSTGRES_OLAP_PASSWORD Default: ofbizolap +# OFBIZ_POSTGRES_TENANT_DB Default: ofbiztenant +# OFBIZ_POSTGRES_TENANT_USER Default: ofbiztenant +# OFBIZ_POSTGRES_TENANT_PASSWORD Default: ofbiztenant +# +# # Hooks are executed at the various stages of the initialisation process by executing scripts in the following # directories. Scripts must be executable and have the .sh extension: # -# /docker-entrypoint-before-data-load.d +# /docker-entrypoint-hooks/before-config-applied.d +# Executed before any changes are applied to the OFBiz configuration files. +# +# /docker-entrypoint-hooks/after-config-applied.d +# Executed after any changes are applied to the OFBiz configuration files. +# +# /docker-entrypoint-hooks/before-data-load.d # Executed before any data loading is about to be performed. Only executed if data loading is required. # Example usage would be to alter the data to be loaded. # -# /docker-entrypoint-after-data-load.d +# /docker-entrypoint-hooks/additional-data.d +# Any data files (.xml files) in this directory are loaded after seed/demo data. +# +# /docker-entrypoint-hooks/after-data-load.d # Executed after any data loading has been performed. Only executed if data loading was required. # ############################################################################### @@ -80,6 +110,9 @@ CONTAINER_STATE_DIR="/ofbiz/runtime/container_state" CONTAINER_DATA_LOADED="$CONTAINER_STATE_DIR/data_loaded" CONTAINER_ADMIN_LOADED="$CONTAINER_STATE_DIR/admin_loaded" CONTAINER_CONFIG_APPLIED="$CONTAINER_STATE_DIR/config_applied" +CONTAINER_DB_CONFIG_APPLIED="$CONTAINER_STATE_DIR/db_config_applied" + +POSTGRES_DRIVER_URL="https://jdbc.postgresql.org/download/postgresql-42.5.4.jar" ############################################################################### # Validate and apply defaults to any environment variables used by this script. @@ -95,6 +128,18 @@ ofbiz_setup_env() { OFBIZ_ADMIN_USER=${OFBIZ_ADMIN_USER:-admin} OFBIZ_ADMIN_PASSWORD=${OFBIZ_ADMIN_PASSWORD:-ofbiz} + + OFBIZ_POSTGRES_OFBIZ_DB=${OFBIZ_POSTGRES_OFBIZ_DB:-ofbiz} + OFBIZ_POSTGRES_OFBIZ_USER=${OFBIZ_POSTGRES_OFBIZ_USER:-ofbiz} + OFBIZ_POSTGRES_OFBIZ_PASSWORD=${OFBIZ_POSTGRES_OFBIZ_PASSWORD:-ofbiz} + + OFBIZ_POSTGRES_OLAP_DB=${OFBIZ_POSTGRES_OLAP_DB:-ofbizolap} + OFBIZ_POSTGRES_OLAP_USER=${OFBIZ_POSTGRES_OLAP_USER:-ofbizolap} + OFBIZ_POSTGRES_OLAP_PASSWORD=${OFBIZ_POSTGRES_OLAP_PASSWORD:-ofbizolap} + + OFBIZ_POSTGRES_TENANT_DB=${OFBIZ_POSTGRES_TENANT_DB:-ofbiztenant} + OFBIZ_POSTGRES_TENANT_USER=${OFBIZ_POSTGRES_TENANT_USER:-ofbiztenant} + OFBIZ_POSTGRES_TENANT_PASSWORD=${OFBIZ_POSTGRES_TENANT_PASSWORD:-ofbiztenant} } ############################################################################### @@ -140,7 +185,7 @@ run_init_hooks() { # If required, load data into OFBiz. load_data() { if [ ! -f "$CONTAINER_DATA_LOADED" ]; then - run_init_hooks /docker-entrypoint-before-data-load.d/* + run_init_hooks /docker-entrypoint-hooks/before-data-load.d/* case "$OFBIZ_DATA_LOAD" in none) ;; @@ -157,13 +202,13 @@ load_data() { esac # Load any additional data files provided. - if [ -z $(find /docker-entrypoint-additional-data.d/ -prune -empty) ]; then - /ofbiz/bin/ofbiz --load-data dir=/docker-entrypoint-additional-data.d + if [ -z $(find /docker-entrypoint-hooks/additional-data.d/ -prune -empty) ]; then + /ofbiz/bin/ofbiz --load-data dir=/docker-entrypoint-hooks/additional-data.d fi touch "$CONTAINER_DATA_LOADED" - run_init_hooks /docker-entrypoint-after-data-load.d/* + run_init_hooks /docker-entrypoint-hooks/after-data-load.d/* fi } @@ -206,29 +251,57 @@ load_admin_user() { # in the classpath and override the build-time copies of the properties in ofbiz.jar. apply_configuration() { if [ ! -f "$CONTAINER_CONFIG_APPLIED" ]; then - run_init_hooks /docker-entrypoint-before-config-applied.d/* + run_init_hooks /docker-entrypoint-hooks/before-config-applied.d/* if [ -n "$OFBIZ_ENABLE_AJP_PORT" ]; then # Configure tomcat to listen for AJP connections on all interfaces within the container. sed --in-place \ - '/<property name="ajp-connector" value="connector">/ a <property name="address" value="0.0.0.0"/>' \ - /ofbiz/framework/catalina/ofbiz-component.xml + '/<property name="ajp-connector" value="connector">/ a <property name="address" value="0.0.0.0"/>' \ + /ofbiz/framework/catalina/ofbiz-component.xml fi if [ -n "$OFBIZ_HOST" ]; then sed "s/host-headers-allowed=.*/host-headers-allowed=${OFBIZ_HOST}/" \ - framework/security/config/security.properties > config/security.properties + framework/security/config/security.properties >config/security.properties fi if [ -n "$OFBIZ_CONTENT_URL_PREFIX" ]; then sed \ - --expression="s#content.url.prefix.secure=.*#content.url.prefix.secure=${OFBIZ_CONTENT_URL_PREFIX}#;" \ - --expression="s#content.url.prefix.standard=.*#content.url.prefix.standard=${OFBIZ_CONTENT_URL_PREFIX}#;" \ - framework/webapp/config/url.properties > config/url.properties + --expression="s#content.url.prefix.secure=.*#content.url.prefix.secure=${OFBIZ_CONTENT_URL_PREFIX}#;" \ + --expression="s#content.url.prefix.standard=.*#content.url.prefix.standard=${OFBIZ_CONTENT_URL_PREFIX}#;" \ + framework/webapp/config/url.properties >config/url.properties fi touch "$CONTAINER_CONFIG_APPLIED" - run_init_hooks /docker-entrypoint-after-config-applied.d/* + run_init_hooks /docker-entrypoint-hooks/after-config-applied.d/* + fi +} + +############################################################################### +# Set up the connection to the OFBiz database. +configure_database() { + if [ ! -f "$CONTAINER_DB_CONFIG_APPLIED" ]; then + if [ -n "$OFBIZ_POSTGRES_HOST" ]; then + sed \ + --expression="s/@HOST@/$OFBIZ_POSTGRES_HOST/;" \ + --expression="s/@OFBIZ_DB@/$OFBIZ_POSTGRES_OFBIZ_DB/;" \ + --expression="s/@OFBIZ_USERNAME@/$OFBIZ_POSTGRES_OFBIZ_USER/;" \ + --expression="s/@OFBIZ_PASSWORD@/$OFBIZ_POSTGRES_OFBIZ_PASSWORD/;" \ + --expression="s/@OLAP_DB@/$OFBIZ_POSTGRES_OLAP_DB/;" \ + --expression="s/@OLAP_USERNAME@/$OFBIZ_POSTGRES_OLAP_USER/;" \ + --expression="s/@OLAP_PASSWORD@/$OFBIZ_POSTGRES_OLAP_PASSWORD/;" \ + --expression="s/@TENANT_DB@/$OFBIZ_POSTGRES_TENANT_DB/;" \ + --expression="s/@TENANT_USERNAME@/$OFBIZ_POSTGRES_TENANT_USER/;" \ + --expression="s/@TENAN_PASSWORD@/$OFBIZ_POSTGRES_TENANT_PASSWORD/;" \ + templates/postgres-entityengine.xml > config/entityengine.xml + + if [ -z "$OFBIZ_SKIP_DB_DRIVER_DOWNLOAD" ]; then + echo "Retrieving PostgreSQL driver from $POSTGRES_DRIVER_URL" + wget --verbose --directory-prefix=lib-extra "$POSTGRES_DRIVER_URL" + fi + fi + + touch "$CONTAINER_DB_CONFIG_APPLIED" fi } @@ -242,6 +315,7 @@ _main() { if [ -z "$OFBIZ_SKIP_INIT" ]; then ofbiz_setup_env create_ofbiz_runtime_directories + configure_database apply_configuration load_data load_admin_user @@ -259,4 +333,3 @@ _main() { } _main "$@" - diff --git a/docker/examples/postgres-demo/docker-compose.yml b/docker/examples/postgres-demo/docker-compose.yml new file mode 100644 index 0000000000..34a5283d02 --- /dev/null +++ b/docker/examples/postgres-demo/docker-compose.yml @@ -0,0 +1,26 @@ +version: "2.4" + +services: + db: + image: postgres:13 + mem_limit: 300M + memswap_limit: 300M + cpu_shares: 200 + restart: "no" + volumes: + - ./postgres-initdb.d:/docker-entrypoint-initdb.d + env_file: + - postgres.env + - ofbiz-postgres.env + + ofbiz: + image: ofbiz-docker + mem_limit: 1600M + memswap_limit: 1600M + cpu_shares: 200 + ports: + - 8443:8443 + env_file: + - ofbiz-postgres.env + environment: + OFBIZ_DATA_LOAD: demo diff --git a/docker/examples/postgres-demo/ofbiz-postgres.env b/docker/examples/postgres-demo/ofbiz-postgres.env new file mode 100644 index 0000000000..682126eaa7 --- /dev/null +++ b/docker/examples/postgres-demo/ofbiz-postgres.env @@ -0,0 +1,13 @@ +OFBIZ_POSTGRES_HOST=db + +OFBIZ_POSTGRES_OFBIZ_DB=ofbizmaindb +OFBIZ_POSTGRES_OFBIZ_USER=ofbiz +OFBIZ_POSTGRES_OFBIZ_PASSWORD="Ab6SqDD2YM2lmEsvao-" + +OFBIZ_POSTGRES_OLAP_DB=ofbizolapdb +OFBIZ_POSTGRES_OLAP_USER=ofbizolap +OFBIZ_POSTGRES_OLAP_PASSWORD="P7TFUtQHSuvha8gSxMME" + +OFBIZ_POSTGRES_TENANT_DB=ofbiztenantdb +OFBIZ_POSTGRES_TENANT_USER=ofbiztenant +OFBIZ_POSTGRES_TENANT_PASSWORD="4oXET73QGriblUejjbvR" diff --git a/docker/examples/postgres-demo/postgres-initdb.d/10-init-user-db.sh b/docker/examples/postgres-demo/postgres-initdb.d/10-init-user-db.sh new file mode 100644 index 0000000000..3a91a85cba --- /dev/null +++ b/docker/examples/postgres-demo/postgres-initdb.d/10-init-user-db.sh @@ -0,0 +1,16 @@ +#!/bin/bash +set -e + +psql -v ON_ERROR_STOP=1 --username "postgres" --dbname "postgres" <<-EOSQL + CREATE USER $OFBIZ_POSTGRES_OFBIZ_USER WITH PASSWORD '$OFBIZ_POSTGRES_OFBIZ_PASSWORD'; + CREATE DATABASE $OFBIZ_POSTGRES_OFBIZ_DB; + GRANT ALL PRIVILEGES ON DATABASE $OFBIZ_POSTGRES_OFBIZ_DB TO $OFBIZ_POSTGRES_OFBIZ_USER; + + CREATE USER $OFBIZ_POSTGRES_OLAP_USER WITH PASSWORD '$OFBIZ_POSTGRES_OLAP_PASSWORD'; + CREATE DATABASE $OFBIZ_POSTGRES_OLAP_DB; + GRANT ALL PRIVILEGES ON DATABASE $OFBIZ_POSTGRES_OLAP_DB TO $OFBIZ_POSTGRES_OLAP_USER; + + CREATE USER $OFBIZ_POSTGRES_TENANT_USER WITH PASSWORD '$OFBIZ_POSTGRES_TENANT_PASSWORD'; + CREATE DATABASE $OFBIZ_POSTGRES_TENANT_DB; + GRANT ALL PRIVILEGES ON DATABASE $OFBIZ_POSTGRES_TENANT_DB TO $OFBIZ_POSTGRES_TENANT_USER; +EOSQL diff --git a/docker/examples/postgres-demo/postgres.env b/docker/examples/postgres-demo/postgres.env new file mode 100644 index 0000000000..c8b98d69b0 --- /dev/null +++ b/docker/examples/postgres-demo/postgres.env @@ -0,0 +1,2 @@ +# Mandatory environment variable to set the password of the postgres superuser. +POSTGRES_PASSWORD="20wganpfDASBtBXY7GQ6" \ No newline at end of file diff --git a/docker/templates/postgres-entityengine.xml b/docker/templates/postgres-entityengine.xml new file mode 100644 index 0000000000..2cfaa8d39e --- /dev/null +++ b/docker/templates/postgres-entityengine.xml @@ -0,0 +1,188 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<!-- +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. +--> +<!-- + - This file configures the Entity Engine JDBC (or other DataSource) and JTA +access. For a detailed description see the core/docs/entityconfig.html file. +--> +<entity-config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="https://ofbiz.apache.org/dtds/entity-config.xsd"> + <resource-loader name="fieldfile" class="org.apache.ofbiz.base.config.FileLoader" + prepend-env="ofbiz.home" prefix="/framework/entity/fieldtype/"/> + + <!-- the transaction factory class to use, one is needed for each way of getting JTA interfaces --> + <!-- Use this one for Geronimo --> + <transaction-factory class="org.apache.ofbiz.entity.transaction.GeronimoTransactionFactory"/> + + <!-- the connection factory class to use, one is needed for obtaining connections/pools for defined resources --> + <connection-factory class="org.apache.ofbiz.entity.connection.DBCPConnectionFactory"/> + + <debug-xa-resources value="false" /> <!-- see https://issues.apache.org/jira/browse/OFBIZ-4282 for more --> + + <delegator name="default" entity-model-reader="main" entity-group-reader="main" entity-eca-reader="main" distributed-cache-clear-enabled="false"> + <group-map group-name="org.apache.ofbiz" datasource-name="localpostgres"/> + <group-map group-name="org.apache.ofbiz.olap" datasource-name="localpostgresolap"/> + <group-map group-name="org.apache.ofbiz.tenant" datasource-name="localpostgrestenant"/> + </delegator> + + <!-- May be used when you create a service that manages many data for massive imports, this for performance reason or to escape functional cases --> + <delegator name="default-no-eca" entity-model-reader="main" entity-group-reader="main" entity-eca-reader="main" entity-eca-enabled="false" distributed-cache-clear-enabled="false"> + <group-map group-name="org.apache.ofbiz" datasource-name="localpostgres"/> + <group-map group-name="org.apache.ofbiz.olap" datasource-name="localpostgresolap"/> + <group-map group-name="org.apache.ofbiz.tenant" datasource-name="localpostgrestenant"/> + </delegator> + + <!-- Be sure that your default delegator (or the one you use) uses the same datasource for test. You must run "gradlew loadAll" before running "gradlew testIntegration" --> + <delegator name="test" entity-model-reader="main" entity-group-reader="main" entity-eca-reader="main"> + <group-map group-name="org.apache.ofbiz" datasource-name="localderby"/> + <group-map group-name="org.apache.ofbiz.olap" datasource-name="localpostgresolap"/> + <group-map group-name="org.apache.ofbiz.tenant" datasource-name="localpostgrestenant"/> + </delegator> + + + <!-- need to at least define a name for each component to use --> + <entity-model-reader name="main"/> + + <!-- need to at least define a name for each component to use --> + <entity-group-reader name="main"/> + + <!-- need to at least define a name for each component to use --> + <entity-eca-reader name="main"/> + + <!-- need to at least define a name for each component to use --> + <entity-data-reader name="tenant"/> + <entity-data-reader name="seed"/> + <entity-data-reader name="seed-initial"/> + <entity-data-reader name="demo"/> + <entity-data-reader name="ext"/> + <entity-data-reader name="ext-test"/> + <entity-data-reader name="ext-demo"/> + + <field-type name="postgres" loader="fieldfile" location="fieldtypepostgres.xml"/> + + <datasource name="localpostgres" + helper-class="org.apache.ofbiz.entity.datasource.GenericHelperDAO" + schema-name="public" + field-type-name="postgres" + check-on-start="true" + add-missing-on-start="true" + use-fk-initially-deferred="false" + alias-view-columns="false" + join-style="ansi" + use-binary-type-for-blob="true" + use-order-by-nulls="true" + offset-style="limit" + result-fetch-size="50"> <!-- Comment out the result-fetch-size attribute for jdbc driver versions older than 8.0. + Not recommended to use those though. They are archived unsupported versions: http://jdbc.postgresql.org/download.html --> + + <read-data reader-name="tenant"/> + <read-data reader-name="seed"/> + <read-data reader-name="seed-initial"/> + <read-data reader-name="demo"/> + <read-data reader-name="ext"/> + <read-data reader-name="ext-test"/> + <read-data reader-name="ext-demo"/> + <inline-jdbc + jdbc-driver="org.postgresql.Driver" + jdbc-uri="jdbc:postgresql://@HOST@/@OFBIZ_DB@" + jdbc-username="@OFBIZ_USERNAME@" + jdbc-password="@OFBIZ_PASSWORD@" + isolation-level="ReadCommitted" + pool-minsize="2" + pool-maxsize="250" + time-between-eviction-runs-millis="600000"/><!-- Be warned that at this date (2009-09-20) the max_connections parameters in postgresql.conf + is set by default to 100 by the initdb process see http://www.postgresql.org/docs/8.4/static/runtime-config-connection.html#GUC-MAX-CONNECTIONS--> + </datasource> + + <datasource name="localpostgresolap" + helper-class="org.apache.ofbiz.entity.datasource.GenericHelperDAO" + schema-name="public" + field-type-name="postgres" + check-on-start="true" + add-missing-on-start="true" + use-fk-initially-deferred="false" + alias-view-columns="false" + join-style="ansi" + result-fetch-size="50" + use-binary-type-for-blob="true" + use-order-by-nulls="true" + offset-style="limit"> + <read-data reader-name="tenant"/> + <read-data reader-name="seed"/> + <read-data reader-name="seed-initial"/> + <read-data reader-name="demo"/> + <read-data reader-name="ext"/> + <read-data reader-name="ext-test"/> + <read-data reader-name="ext-demo"/> + <inline-jdbc + jdbc-driver="org.postgresql.Driver" + jdbc-uri="jdbc:postgresql://@HOST@/@OLAP_DB@" + jdbc-username="@OLAP_USERNAME@" + jdbc-password="@OLAP_PASSWORD@" + isolation-level="ReadCommitted" + pool-minsize="2" + pool-maxsize="250" + time-between-eviction-runs-millis="600000"/><!-- Be warned that at this date (2009-09-20) the max_connections parameters in postgresql.conf + is set by default to 100 by the initdb process see http://www.postgresql.org/docs/8.4/static/runtime-config-connection.html#GUC-MAX-CONNECTIONS--> + + <!-- <jndi-jdbc jndi-server-name="default" jndi-name="java:comp/env/jdbc/localpostgres" isolation-level="ReadCommitted"/>--> + <!-- <jndi-jdbc jndi-server-name="default" jndi-name="comp/env/jdbc/xa/localpostgres" isolation-level="ReadCommitted"/> --> <!-- Orion Style JNDI name --> + <!-- <jndi-jdbc jndi-server-name="localweblogic" jndi-name="PostgresDataSource"/> --> <!-- Weblogic Style JNDI name --> + <!-- <jndi-jdbc jndi-server-name="default" jndi-name="jdbc/localpostgres" isolation-level="ReadCommitted"/> --> <!-- JRun4 Style JNDI name --> + <!-- <tyrex-dataSource dataSource-name="localpostgres" isolation-level="ReadCommitted"/> --> + </datasource> + + <datasource name="localpostgrestenant" + helper-class="org.apache.ofbiz.entity.datasource.GenericHelperDAO" + schema-name="public" + field-type-name="postgres" + check-on-start="true" + add-missing-on-start="true" + use-fk-initially-deferred="false" + alias-view-columns="false" + join-style="ansi" + result-fetch-size="50" + use-binary-type-for-blob="true" + use-order-by-nulls="true" + offset-style="limit"> + <read-data reader-name="tenant"/> + <read-data reader-name="seed"/> + <read-data reader-name="seed-initial"/> + <read-data reader-name="demo"/> + <read-data reader-name="ext"/> + <read-data reader-name="ext-test"/> + <read-data reader-name="ext-demo"/> + <inline-jdbc + jdbc-driver="org.postgresql.Driver" + jdbc-uri="jdbc:postgresql://@HOST@/@TENANT_DB@" + jdbc-username="@TENANT_USERNAME@" + jdbc-password="@TENANT_PASSWORD@" + isolation-level="ReadCommitted" + pool-minsize="2" + pool-maxsize="250" + time-between-eviction-runs-millis="600000"/><!-- Be warned that at this date (2009-09-20) the max_connections parameters in postgresql.conf + is set by default to 100 by the initdb process see http://www.postgresql.org/docs/8.4/static/runtime-config-connection.html#GUC-MAX-CONNECTIONS--> + + <!-- <jndi-jdbc jndi-server-name="default" jndi-name="java:comp/env/jdbc/localpostgres" isolation-level="ReadCommitted"/>--> + <!-- <jndi-jdbc jndi-server-name="default" jndi-name="comp/env/jdbc/xa/localpostgres" isolation-level="ReadCommitted"/> --> <!-- Orion Style JNDI name --> + <!-- <jndi-jdbc jndi-server-name="localweblogic" jndi-name="PostgresDataSource"/> --> <!-- Weblogic Style JNDI name --> + <!-- <jndi-jdbc jndi-server-name="default" jndi-name="jdbc/localpostgres" isolation-level="ReadCommitted"/> --> <!-- JRun4 Style JNDI name --> + <!-- <tyrex-dataSource dataSource-name="localpostgres" isolation-level="ReadCommitted"/> --> + </datasource> +</entity-config>