Skip to content

Commit

Permalink
[FEATURE] Introduce TYPO3_SOLR_ENABLED_CORES docker env variable
Browse files Browse the repository at this point in the history
This adds a startup script which disables all unneeded cores.

Usage:

`docker run -e 'TYPO3_SOLR_ENABLED_CORES=english german' -it typo3solr/ext-solr`

This enables only the english and german core (core_en, core_de) during startup.

If the env variable is not set, then all cores are enabled (= default behaviour).

The additional cores can be enabled afterwards by adding them to the TYPO3_SOLR_ENABLED_CORES env. variable.

Fixes: #3502
  • Loading branch information
Christoph Lehmann authored and dkd-kaehm committed Jun 7, 2023
1 parent fb9043c commit 1dda542
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 0 deletions.
52 changes: 52 additions & 0 deletions Build/Test/cibuild_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,14 @@ isCoreAvailable ()
return 0;
}

isCoreUnavailable ()
{
if ! isCoreAvailable $1; then
return 0;
fi
return 1;
}

pingCore ()
{
# shellcheck disable=SC2015
Expand Down Expand Up @@ -262,6 +270,48 @@ assertNecessaryPathsAreOwnedBySolr ()
isPathOwnedBySolr "${paths[@]}" || { echo -e "${RED}"'\nThe image has files, which are not owned by solr(8983) user.\n Please fix this issue.'"${NC}"; cleanUp; exit 1; }
}

assertCoresAreSwitchableViaEnvVar ()
{
echo -e "\nCheck all cores are disabled except desired by \$TYPO3_SOLR_ENABLED_CORES env:"
echo -n " stop container $LOCAL_CONTAINER_NAME" prettyPrintOrExitOnError $? "$(docker stop "$LOCAL_CONTAINER_NAME" 2>&1)"

echo -n "Starting container"
prettyPrintOrExitOnError $? "$(docker run --env TYPO3_SOLR_ENABLED_CORES='german english danish' --name="$LOCAL_CONTAINER_NAME" -d -p 127.0.0.1:8998:8983 -v "$LOCAL_VOLUME_NAME":"$DEFAULT_IMAGE_VOLUME_EXPORT_PATH" "$LOCAL_IMAGE_NAME" 2>&1)"

ENABLED_CORES=(
"core_de"
"core_en"
"core_da"
)

SOME_DISABLED_CORES=(
"core_fi"
"core_fr"
"core_gl"
"core_el"
"core_hi"
"core_hu"
"core_id"
"core_it"
"core_ja"
)

echo -e "\nCheck enabled cores are available:"
for core in "${ENABLED_CORES[@]}"
do
echo -n " $core is enabled"
prettyPrintOrExitOnError $? "$(isCoreAvailable "$core" 2>&1)"
done

echo -e "\nCheck few other cores are really disabled:"
for core in "${SOME_DISABLED_CORES[@]}"
do
echo -n " $core is disabled"
prettyPrintOrExitOnError $? "$(isCoreUnavailable "$core" 2>&1)"
done

}

### run the tests

assertDockerVersionIsGtOrEq193
Expand All @@ -276,6 +326,8 @@ assertAllCoresAreQueriable
assertDataPathIsCreatedByApacheSolr
assertNecessaryPathsAreOwnedBySolr

assertCoresAreSwitchableViaEnvVar


echo -e "${GREEN}"'\nAll checks passed successfully!\n'"${NC}"

Expand Down
1 change: 1 addition & 0 deletions Docker/SolrServer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ ENV TERM linux

USER root
RUN rm -fR /opt/solr/server/solr/*
COPY Docker/SolrServer/docker-entrypoint-initdb.d/ /docker-entrypoint-initdb.d
USER solr

COPY --chown=solr:solr Resources/Private/Solr/ /var/solr/data
Expand Down
17 changes: 17 additions & 0 deletions Docker/SolrServer/docker-entrypoint-initdb.d/disable-cores.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash

shopt -s extglob

if [ -n "${TYPO3_SOLR_ENABLED_CORES}" ]
then
for CORE_TO_DISABLE in /var/solr/data/cores/*/core.properties
do
mv "${CORE_TO_DISABLE}" "${CORE_TO_DISABLE}_disabled";
done

for CORE_to_ENABLE in ${TYPO3_SOLR_ENABLED_CORES}
do
echo "Enable core ${CORE_to_ENABLE}"
mv "/var/solr/data/cores/${CORE_to_ENABLE}/core.properties_disabled" "/var/solr/data/cores/${CORE_to_ENABLE}/core.properties"
done
fi
21 changes: 21 additions & 0 deletions Documentation/Appendix/DockerTweaks.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.. include:: /Includes.rst.txt


.. _appendix-docker-tweaks:

Appendix - Docker Tweaks
========================

Beside of original Apache Solr Docker image, on which is our image based on we provide some tweaks to make our and your work simpler.

Disable unnecessary cores on container start
--------------------------------------------

By defining env ``TYPO3_SOLR_ENABLED_CORES`` with a space separated list of languages/cores to enable, only those cores will be initialized on start-up.
This allows to save memory usage of Apache Solr server instance.

Usage:

.. code-block:: bash
docker run -e 'TYPO3_SOLR_ENABLED_CORES=english german' -it typo3solr/ext-solr
5 changes: 5 additions & 0 deletions Documentation/GettingStarted/Solr.rst
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ The following example shows how you can run our configuration with the official
sudo chown -R 8983:8983 ~/mysolr
docker run -d -p 8983:8983 -v ~/mysolr:/var/solr/data solr:8.5
Advanced settings and tweaks
----------------------------

For more settings and tweak possibilities for our Docker image, please refer to the :ref:`appendix-docker-tweaks`.

Other Setup
-----------

Expand Down

0 comments on commit 1dda542

Please sign in to comment.