Skip to content

Commit

Permalink
MIR-1282 improve expandability of configuration of docker images
Browse files Browse the repository at this point in the history
  • Loading branch information
sebhofmann committed Feb 28, 2024
1 parent 1802653 commit 28383e1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ The docker container has its own install script which uses the environment varia
| XMS | 1g | The value of the -Xms parameter for Tomcat. |
| FIX_FILE_SYSTEM_RIGHTS | false | If true the file system rights of the mounted volumes get corrected to be owned by the right user. |
| MIR_OPTS | | Additional options which will be passed as JAVA_OPTS to the tomcat process |
| MIR_EXTRA_PROPERTIES | | A Path to a additional property file which will be included in to the default mycore.properties. |

### Mount Points

Expand Down
1 change: 1 addition & 0 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ services:
- XMX=${MIR_XMX}
- XMS=${MIR_XMS}
- FIX_FILE_SYSTEM_RIGHTS=false
- EXTRA_PROPERTIES=${MIR_EXTRA_PROPERTIES}
volumes:
- ${MIR_HOME}:/mcr/home/
- ${MIR_DATA}:/mcr/data/
Expand Down
23 changes: 12 additions & 11 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ MCR_CONFIG_DIR_ESCAPED=$(echo "$MCR_CONFIG_DIR" | sed 's/\//\\\//g')

MYCORE_PROPERTIES="${MCR_CONFIG_DIR}mycore.properties"

DOCKER_PROPERTIES="${MCR_CONFIG_DIR}docker.properties"

PERSISTENCE_XML="${MCR_CONFIG_DIR}resources/META-INF/persistence.xml"

function fixDirectoryRights() {
Expand Down Expand Up @@ -71,17 +73,19 @@ function migrateC3P0toHikari {
function setOrAddProperty() {
KEY=$1
VALUE=$2
PROPERTIES_FILE=${3:-$DOCKER_PROPERTIES}

if grep -q "$KEY=" "${MYCORE_PROPERTIES}" ; then
if grep -q "$KEY=" "${PROPERTIES_FILE}" ; then
ESCAPED_KEY=$(echo "${KEY}" | sed 's/\//\\\//g')
ESCAPED_VALUE=$(echo "${VALUE}" | sed 's/\//\\\//g')
sed -ri "s/($ESCAPED_KEY=).+/\1$ESCAPED_VALUE/" "${MYCORE_PROPERTIES}"
sed -ri "s/($ESCAPED_KEY=).+/\1$ESCAPED_VALUE/" "${PROPERTIES_FILE}"
else
echo "$KEY=$VALUE">>"${MYCORE_PROPERTIES}"
echo "$KEY=$VALUE">>"${PROPERTIES_FILE}"
fi
}

function setDockerValues() {
rm -f "${DOCKER_PROPERTIES}"
echo "Set Docker Values to Config!"

if [ -n "${SOLR_URL}" ]; then
Expand Down Expand Up @@ -147,14 +151,11 @@ function setDockerValues() {

downloadDriver https://repo1.maven.org/maven2/com/zaxxer/HikariCP/5.1.0/HikariCP-5.1.0.jar

# iterate over all environment variables starting with MCR.JPA. and add them to the mycore.properties
for var in $(env | grep -E "^MCR.JPA."); do
key=$(echo $var | cut -d'=' -f1 | sed 's/MCR.JPA.//g')
value=$(echo $var | cut -d'=' -f2)
complete_key="MCR.JPA.$key"

setOrAddProperty "$complete_key" "$value"
done
if [[ -z "${EXTRA_PROPERTIES}" ]]; then
setOrAddProperty "MCR.Configuration.Include" "${DOCKER_PROPERTIES}" "${MYCORE_PROPERTIES}"
else
setOrAddProperty "MCR.Configuration.Include" "${DOCKER_PROPERTIES} ${EXTRA_PROPERTIES}" "${MYCORE_PROPERTIES}"
fi

rm -f "${PERSISTENCE_XML}"
}
Expand Down

0 comments on commit 28383e1

Please sign in to comment.