Implemented: Use docker container deployment to host demo-trunk site (OFBIZ-12786)

diff --git a/demo-backup/ofbizdocker/README.md b/demo-backup/ofbizdocker/README.md
new file mode 100644
index 0000000..4464f71
--- /dev/null
+++ b/demo-backup/ofbizdocker/README.md
@@ -0,0 +1,36 @@
+# Docker deployments of OFBiz
+
+As part of OFBIZ-12757 and OFBIZ-12786, docker deployments are being carried on VM ofbiz-vm1.apache.org for the
+demo-trunk site.
+
+Work under OFBIZ-12757 also created 3 experimental sites:
+* exp1.ofbiz.apache.org
+* exp2.ofbiz.apache.org
+* exp3.ofbiz.apache.org
+
+These sites may be disabled at any time, but the hostnames will be left configured to enable rapid experimentation with 
+demo sites in the future.
+
+Files in this subdirectory of the ofbiz-tools repository reflect files which should be created on the root filesystem of ofbiz-vm1.apache.org with the following additions and/or settings:
+* /etc/cron.d/ofbizdocker
+  * Owned by root with permissions 0644
+* /home/ofbizdocker/pull-rebuild-restart.sh
+  * Owned by ofbizdocker user with permissions 0775
+* /home/ofbizdocker/ofbiz-framework
+  * Git clone of https://github.com/apache/ofbiz-framework with the experimental-docker branch checked otu.
+
+
+## How do the Docker deployments work
+
+At 02:35h UTC each day, the cronttab defined by `/etc/cron.d/ofbizdocker` will execute script `pull-and-restart.sh`. 
+
+The `pull-and-restart.sh` script does the following:
+* For each directory in /home/ofbizdocker/[demo-trunk, exp*]
+  * Change to the directory.
+  * Run `docker compose pull` to pull the latest container images needed to support the docker compose application.
+  * Run `docker compose down --volumes` to shutdown and remove any existing containers and volumes for the docker compose application.
+  * Run `docker compose up -d` to start the containers for the docker compose application.
+
+The `demo-trunk` application listens on AJP port 8009.
+
+If in use, the `exp1` application listens on AJP port 38009, the `exp2` application listens on AJP port 48009, and the `exp3` application listens on AJP port 58009. The Apache server on ofbiz-vm1.apache.org has been configured to reverse-proxy to these applications for hostnames exp1.ofbiz.apache.org, exp2.ofbiz.apache.org and exp3.ofbiz.apache.org respectively.
diff --git a/demo-backup/ofbizdocker/etc/cron.d/ofbizdocker b/demo-backup/ofbizdocker/etc/cron.d/ofbizdocker
new file mode 100644
index 0000000..0ce8c48
--- /dev/null
+++ b/demo-backup/ofbizdocker/etc/cron.d/ofbizdocker
@@ -0,0 +1 @@
+35 2 * * *   ofbizdocker    /home/ofbizdocker/pull-and-restart.sh > /home/ofbizdocker/pull-and-restart.log 2>&1
diff --git a/demo-backup/ofbizdocker/home/ofbizdocker/demo-trunk/after-config-applied.d/apply-fop-config.sh b/demo-backup/ofbizdocker/home/ofbizdocker/demo-trunk/after-config-applied.d/apply-fop-config.sh
new file mode 100644
index 0000000..644baf4
--- /dev/null
+++ b/demo-backup/ofbizdocker/home/ofbizdocker/demo-trunk/after-config-applied.d/apply-fop-config.sh
@@ -0,0 +1,9 @@
+#!/usr/bin/env bash
+set -x
+
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
+FOP_XML_FILE="/ofbiz/framework/webapp/config/fop.xconf"
+TMPFILE=$(mktemp)
+
+xsltproc --output "$TMPFILE" "$SCRIPT_DIR/fop-xconf-update.xslt" "$FOP_XML_FILE"
+mv "$TMPFILE" "$FOP_XML_FILE"
diff --git a/demo-backup/ofbizdocker/home/ofbizdocker/demo-trunk/after-config-applied.d/apply-solr-config.sh b/demo-backup/ofbizdocker/home/ofbizdocker/demo-trunk/after-config-applied.d/apply-solr-config.sh
new file mode 100644
index 0000000..0b10bc5
--- /dev/null
+++ b/demo-backup/ofbizdocker/home/ofbizdocker/demo-trunk/after-config-applied.d/apply-solr-config.sh
@@ -0,0 +1,7 @@
+#!/usr/bin/env bash
+set -x
+
+if [ -d /ofbiz/plugins/solr ]; then
+        sed "s/^solr.webapp.domainName=.*/solr.webapp.domainName=${OFBIZ_HOST}/" \
+                /ofbiz/plugins/solr/config/solrconfig.properties > /ofbiz/config/solrconfig.properties
+fi
diff --git a/demo-backup/ofbizdocker/home/ofbizdocker/demo-trunk/after-config-applied.d/fop-xconf-update.xslt b/demo-backup/ofbizdocker/home/ofbizdocker/demo-trunk/after-config-applied.d/fop-xconf-update.xslt
new file mode 100644
index 0000000..0220243
--- /dev/null
+++ b/demo-backup/ofbizdocker/home/ofbizdocker/demo-trunk/after-config-applied.d/fop-xconf-update.xslt
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+  <xsl:template match="/fop">
+    <xsl:element name="fop">
+      <xsl:copy-of select="@*"/>
+      <base>https://demo-trunk.ofbiz.apache.org</base>
+      <xsl:copy-of select="node()[not(self::base)]"/>
+    </xsl:element>
+  </xsl:template>
+</xsl:stylesheet>
diff --git a/demo-backup/ofbizdocker/home/ofbizdocker/demo-trunk/docker-compose.yml b/demo-backup/ofbizdocker/home/ofbizdocker/demo-trunk/docker-compose.yml
new file mode 100644
index 0000000..ed8923a
--- /dev/null
+++ b/demo-backup/ofbizdocker/home/ofbizdocker/demo-trunk/docker-compose.yml
@@ -0,0 +1,31 @@
+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: ghcr.io/apache/ofbiz:trunk-plugins-snapshot
+    mem_limit: 2400M
+    memswap_limit: 2400M
+    cpu_shares: 200
+    ports:
+      - 127.0.0.1:8009:8009
+    volumes:
+      - ./after-config-applied.d:/docker-entrypoint-hooks/after-config-applied.d
+    env_file:
+      - ofbiz-postgres.env
+    environment:
+      OFBIZ_HOST: demo-trunk.ofbiz.apache.org
+      OFBIZ_ENABLE_AJP_PORT: 1
+      OFBIZ_DATA_LOAD: demo
+      OFBIZ_CONTENT_URL_PREFIX: https://demo-trunk.ofbiz.apache.org
diff --git a/demo-backup/ofbizdocker/home/ofbizdocker/demo-trunk/ofbiz-postgres.env b/demo-backup/ofbizdocker/home/ofbizdocker/demo-trunk/ofbiz-postgres.env
new file mode 100644
index 0000000..9d713da
--- /dev/null
+++ b/demo-backup/ofbizdocker/home/ofbizdocker/demo-trunk/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="CHANGEME"
+
+OFBIZ_POSTGRES_OLAP_DB=ofbizolapdb
+OFBIZ_POSTGRES_OLAP_USER=ofbizolap
+OFBIZ_POSTGRES_OLAP_PASSWORD="CHANGEME"
+
+OFBIZ_POSTGRES_TENANT_DB=ofbiztenantdb
+OFBIZ_POSTGRES_TENANT_USER=ofbiztenant
+OFBIZ_POSTGRES_TENANT_PASSWORD="CHANGEME"
diff --git a/demo-backup/ofbizdocker/home/ofbizdocker/demo-trunk/postgres-initdb.d/10-init-user-db.sh b/demo-backup/ofbizdocker/home/ofbizdocker/demo-trunk/postgres-initdb.d/10-init-user-db.sh
new file mode 100644
index 0000000..3a91a85
--- /dev/null
+++ b/demo-backup/ofbizdocker/home/ofbizdocker/demo-trunk/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/demo-backup/ofbizdocker/home/ofbizdocker/demo-trunk/postgres.env b/demo-backup/ofbizdocker/home/ofbizdocker/demo-trunk/postgres.env
new file mode 100644
index 0000000..d86bdb9
--- /dev/null
+++ b/demo-backup/ofbizdocker/home/ofbizdocker/demo-trunk/postgres.env
@@ -0,0 +1,2 @@
+# Mandatory environment variable to set the password of the postgres superuser.
+POSTGRES_PASSWORD="CHANGEME"
diff --git a/demo-backup/ofbizdocker/home/ofbizdocker/exp1/docker-compose.yml b/demo-backup/ofbizdocker/home/ofbizdocker/exp1/docker-compose.yml
new file mode 100644
index 0000000..0921c62
--- /dev/null
+++ b/demo-backup/ofbizdocker/home/ofbizdocker/exp1/docker-compose.yml
@@ -0,0 +1,13 @@
+version: "2.4"
+
+services:
+  ofbiz:
+    image: ghcr.io/apache/ofbiz:experimental-docker-branch-preloaddemo-snapshot
+    mem_limit: 1600M
+    memswap_limit: 1600M
+    cpu_shares: 200
+    ports:
+      - 127.0.0.1:38009:8009
+    environment:
+      OFBIZ_HOST: exp1.ofbiz.apache.org
+      OFBIZ_ENABLE_AJP_PORT: 1
diff --git a/demo-backup/ofbizdocker/home/ofbizdocker/exp2/docker-compose.yml b/demo-backup/ofbizdocker/home/ofbizdocker/exp2/docker-compose.yml
new file mode 100644
index 0000000..b62f093
--- /dev/null
+++ b/demo-backup/ofbizdocker/home/ofbizdocker/exp2/docker-compose.yml
@@ -0,0 +1,13 @@
+version: "2.4"
+
+services:
+  ofbiz:
+    image: ghcr.io/apache/ofbiz:experimental-docker-branch-snapshot
+    mem_limit: 1600M
+    memswap_limit: 1600M
+    cpu_shares: 200
+    ports:
+      - 127.0.0.1:48009:8009
+    environment:
+      OFBIZ_HOST: exp2.ofbiz.apache.org
+      OFBIZ_ENABLE_AJP_PORT: 1
diff --git a/demo-backup/ofbizdocker/home/ofbizdocker/exp3/docker-compose.yml b/demo-backup/ofbizdocker/home/ofbizdocker/exp3/docker-compose.yml
new file mode 100644
index 0000000..7fef262
--- /dev/null
+++ b/demo-backup/ofbizdocker/home/ofbizdocker/exp3/docker-compose.yml
@@ -0,0 +1,28 @@
+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: ghcr.io/apache/ofbiz:experimental-docker-branch-plugins-snapshot
+    mem_limit: 1600M
+    memswap_limit: 1600M
+    cpu_shares: 200
+    ports:
+      - 127.0.0.1:58009:8009
+    env_file:
+      - ofbiz-postgres.env
+    environment:
+      OFBIZ_HOST: exp3.ofbiz.apache.org
+      OFBIZ_ENABLE_AJP_PORT: 1
+      OFBIZ_DATA_LOAD: demo
diff --git a/demo-backup/ofbizdocker/home/ofbizdocker/exp3/ofbiz-postgres.env b/demo-backup/ofbizdocker/home/ofbizdocker/exp3/ofbiz-postgres.env
new file mode 100644
index 0000000..9d713da
--- /dev/null
+++ b/demo-backup/ofbizdocker/home/ofbizdocker/exp3/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="CHANGEME"
+
+OFBIZ_POSTGRES_OLAP_DB=ofbizolapdb
+OFBIZ_POSTGRES_OLAP_USER=ofbizolap
+OFBIZ_POSTGRES_OLAP_PASSWORD="CHANGEME"
+
+OFBIZ_POSTGRES_TENANT_DB=ofbiztenantdb
+OFBIZ_POSTGRES_TENANT_USER=ofbiztenant
+OFBIZ_POSTGRES_TENANT_PASSWORD="CHANGEME"
diff --git a/demo-backup/ofbizdocker/home/ofbizdocker/exp3/postgres-initdb.d/10-init-user-db.sh b/demo-backup/ofbizdocker/home/ofbizdocker/exp3/postgres-initdb.d/10-init-user-db.sh
new file mode 100644
index 0000000..3a91a85
--- /dev/null
+++ b/demo-backup/ofbizdocker/home/ofbizdocker/exp3/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/demo-backup/ofbizdocker/home/ofbizdocker/exp3/postgres.env b/demo-backup/ofbizdocker/home/ofbizdocker/exp3/postgres.env
new file mode 100644
index 0000000..c8cd75c
--- /dev/null
+++ b/demo-backup/ofbizdocker/home/ofbizdocker/exp3/postgres.env
@@ -0,0 +1,2 @@
+# Mandatory environment variable to set the password of the postgres superuser.
+POSTGRES_PASSWORD="CHANGEME"
\ No newline at end of file
diff --git a/demo-backup/ofbizdocker/home/ofbizdocker/pull-and-restart.sh b/demo-backup/ofbizdocker/home/ofbizdocker/pull-and-restart.sh
new file mode 100644
index 0000000..caa10c9
--- /dev/null
+++ b/demo-backup/ofbizdocker/home/ofbizdocker/pull-and-restart.sh
@@ -0,0 +1,17 @@
+#!/usr/bin/env bash
+# Script to pull and redeploy OFBiz container images to docker-compose applications.
+
+set -x
+set -e
+
+cd /home/ofbizdocker
+
+for appDir in exp1 exp2 exp3; do
+    echo "Restarting $appDir docker-compose application with latest container images."
+    pushd "$appDir"
+    docker compose pull
+    docker compose down --volumes
+    docker compose up --detach
+    popd
+    echo "$appDir docker-compose application restarted."
+done
diff --git a/demo-backup/trunk.sh b/demo-backup/trunk.sh
index 77b9b68..a700c8e 100755
--- a/demo-backup/trunk.sh
+++ b/demo-backup/trunk.sh
@@ -1,4 +1,6 @@
 #!/bin/bash
+set -x
+set -e
 
 echo This cant be used alone, see OFBIZ-10287. You need for now to use all-manual-nicely.sh
 
@@ -14,7 +16,7 @@
 patch -p0 < /home/ofbizDemo/trunk/fop.xconf.patch
 
 # We don't want *.jks, we use "Let's encrypt"
-rm /home/ofbizDemo/trunk/framework/base/config/*.jks
+rm /home/ofbizDemo/trunk/framework/base/config/*.jks || true
 
 
 ./gradlew --no-daemon pullAllPluginsSource
@@ -24,7 +26,8 @@
 patch -p0 < /home/ofbizDemo/trunk/birt.patch
 cd ..
 
-./gradlew --no-daemon terminateOfbiz
+./gradlew --no-daemon "ofbiz --shutdown"
+#./gradlew --no-daemon terminateOfbiz
 ./gradlew --no-daemon cleanAll
 ./gradlew --no-daemon loadAll
 ./gradlew --no-daemon gitInfoFooter