You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by da...@apache.org on 2023/03/26 16:11:40 UTC
[ofbiz-framework] branch trunk updated: Implemented: Inhibit loading of components in docker containers (OFBIZ-12783)
This is an automated email from the ASF dual-hosted git repository.
danwatford pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git
The following commit(s) were added to refs/heads/trunk by this push:
new 03f8d3ea79 Implemented: Inhibit loading of components in docker containers (OFBIZ-12783)
03f8d3ea79 is described below
commit 03f8d3ea79eacd77c54ebcf4dbaa2b7e1c325af7
Author: Daniel Watford <da...@watfordconsulting.com>
AuthorDate: Sun Mar 26 17:11:33 2023 +0100
Implemented: Inhibit loading of components in docker containers (OFBIZ-12783)
Container deployments will disable components according to the component
configuration files (ofbiz-component.xml files) listed in environment
variable OFBIZ_DISABLE_COMPONENTS.
---
DOCKER.md | 1 +
Dockerfile | 6 ++++++
docker/disable-component.xslt | 33 ++++++++++++++++++++++++++++++
docker/docker-entrypoint.sh | 47 +++++++++++++++++++++++++++++++++++++++++++
4 files changed, 87 insertions(+)
diff --git a/DOCKER.md b/DOCKER.md
index 5fd7d77ce2..50ecdf093e 100644
--- a/DOCKER.md
+++ b/DOCKER.md
@@ -76,6 +76,7 @@ Environment variables are used in `docker-entrypoint.sh` to control configuratio
|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. |
+|OFBIZ_DISABLE_COMPONENTS | plugins/birt/ofbiz-component.xml | Commas seperated list of paths to ofbiz-component.xml files of the components that should not be loaded. |
### Hooks
At various steps of initialisation, the `docker-entrypoint.sh` script will check for
diff --git a/Dockerfile b/Dockerfile
index c22482f58f..ff816a0eba 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -38,6 +38,11 @@ RUN --mount=type=cache,id=gradle-cache,sharing=locked,target=/root/.gradle \
FROM eclipse-temurin:17 AS runtimebase
+# xsltproc is used to disable OFBiz components during first run.
+RUN apt-get update \
+ && apt-get install -y --no-install-recommends xsltproc \
+ && rm -rf /var/lib/apt/lists/*
+
RUN ["useradd", "ofbiz"]
# Create directories used to mount volumes where hooks into the startup process can be placed.
@@ -60,6 +65,7 @@ RUN --mount=type=bind,from=builder,source=/builder/build/distributions/ofbiz.tar
RUN ["mkdir", "/ofbiz/runtime", "/ofbiz/config", "/ofbiz/lib-extra"]
COPY docker/docker-entrypoint.sh .
+COPY docker/disable-component.xslt .
COPY docker/send_ofbiz_stop_signal.sh .
COPY docker/templates templates
diff --git a/docker/disable-component.xslt b/docker/disable-component.xslt
new file mode 100644
index 0000000000..04e926ba09
--- /dev/null
+++ b/docker/disable-component.xslt
@@ -0,0 +1,33 @@
+<?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.
+-->
+
+<!--
+ Copy all attributes and elements of the root ofbiz-component element in an XML document, changing the enabled
+ attribute to false.
+-->
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+ <xsl:template match="/">
+ <xsl:element name="ofbiz-component">
+ <xsl:copy-of select="ofbiz-component/@*"/>
+ <xsl:attribute name="enabled">false</xsl:attribute>
+ <xsl:copy-of select="ofbiz-component/node()"/>
+ </xsl:element>
+ </xsl:template>
+</xsl:stylesheet>
diff --git a/docker/docker-entrypoint.sh b/docker/docker-entrypoint.sh
index dcb50aa997..4310c7aa04 100755
--- a/docker/docker-entrypoint.sh
+++ b/docker/docker-entrypoint.sh
@@ -80,6 +80,11 @@
# OFBIZ_POSTGRES_TENANT_USER Default: ofbiztenant
# OFBIZ_POSTGRES_TENANT_PASSWORD Default: ofbiztenant
#
+# OFBIZ_DISABLE_COMPONENTS
+# Prevents loading of ofbiz-components.
+# Contains a comma separated list of relative paths from the ofbiz sources directory to the ofbiz-component.xml files
+# that should be prevented from loading.
+# Default: plugins/birt/ofbiz-component.xml
#
# 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:
@@ -140,6 +145,8 @@ ofbiz_setup_env() {
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}
+
+ OFBIZ_DISABLE_COMPONENTS=${OFBIZ_DISABLE_COMPONENTS-plugins/birt/ofbiz-component.xml}
}
###############################################################################
@@ -245,6 +252,42 @@ load_admin_user() {
fi
}
+###############################################################################
+# Modify the given ofbiz-component configuration XML file to set the root
+# component's 'enabled' attribute to false.
+# $1 - Path to the XML file to be modified.
+disable_component() {
+ XML_FILE="/ofbiz/$1"
+ if [ -f "$XML_FILE" ]; then
+ TMPFILE=$(mktemp)
+
+ xsltproc /ofbiz/disable-component.xslt "$XML_FILE" > "$TMPFILE"
+ mv "$TMPFILE" "$XML_FILE"
+ else
+ echo "Cannot find ofbiz-component configuration file. Not disabling component: $XML_FILE"
+ fi
+}
+
+###############################################################################
+# Modify the given ofbiz-component configuration XML files to set their root
+# components' 'enabled' attribute to false.
+# $1 - Comma separated list of paths to configuration XML files to be modified.
+disable_components() {
+ COMMA_SEPARATED_PATHS="$1"
+
+ if [ -n "$COMMA_SEPARATED_PATHS" ]; then
+
+ # Split the comma separated paths into separate arguments.
+ IFS=,
+ set "$COMMA_SEPARATED_PATHS"
+
+ while [ -n "$1" ]; do
+ disable_component "$1"
+ shift
+ done
+ fi
+}
+
###############################################################################
# Apply any configuration changes required.
# Changed property files need to be placed in /ofbiz/config so they appear earlier
@@ -272,6 +315,10 @@ apply_configuration() {
framework/webapp/config/url.properties >config/url.properties
fi
+ if [ -n "$OFBIZ_DISABLE_COMPONENTS" ]; then
+ disable_component "$OFBIZ_DISABLE_COMPONENTS"
+ fi
+
touch "$CONTAINER_CONFIG_APPLIED"
run_init_hooks /docker-entrypoint-hooks/after-config-applied.d/*
fi