From 6e6fcc2286f1aa2d93b1151c3da77d84c03a0b8c Mon Sep 17 00:00:00 2001 From: pasindu Date: Sat, 20 Jul 2024 14:26:41 +0530 Subject: [PATCH] Fix config mapping issue --- Dockerfile | 4 ++-- entrypoint.sh | 33 +++++++++++++++++++++++++++------ 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 36ea1d6..74cb217 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,8 +23,8 @@ USER root COPY /static/css/* ${STATIC_CONFIG_PATH}/css/ COPY /static/img/* ${STATIC_CONFIG_PATH}/img/ -# Copy configuration and data files -COPY /configs/emqx_exhook.conf /opt/emqx/etc/plugins/ +# Copy configuration and data files to the container +COPY /configs/emqx_exhook.conf /opt/emqx/configs/ COPY /data/loaded_plugins /opt/data/ EXPOSE 1883 8083 8084 8883 11883 18083 4370 5369 diff --git a/entrypoint.sh b/entrypoint.sh index a4578d3..34490ea 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -16,14 +16,35 @@ # specific language governing permissions and limitations # under the License. -CONFIG_PATH=/opt/emqx/etc/plugins/emqx_exhook.conf +CONFIG_PATH=/opt/emqx/configs/emqx_exhook.conf +EMQX_DATA_PATH=/opt/emqx/data/loaded_plugins -# Set emqx_exhook.conf configs -sed -i 's/${SERVER_HOSTNAME}/'$SERVER_HOSTNAME'/g' $CONFIG_PATH +if [ -f "$CONFIG_PATH" ] +then + echo "$CONFIG_PATH found. Populating templates" + # Backup config files + cp $CONFIG_PATH $CONFIG_PATH.template + CONFIG_TEMPLATE_PATH=$CONFIG_PATH.template -# Add plugins -rm -f /opt/emqx/data/loaded_plugins -mv /opt/data/loaded_plugins /opt/emqx/data/loaded_plugins + echo "Setting up configurations" + # emqx_exhook.conf + sed -i 's/${SERVER_HOSTNAME}/'$SERVER_HOSTNAME'/g' $CONFIG_PATH +fi + +# Copy configuration and data file +cp $CONFIG_PATH /opt/emqx/etc/plugins/emqx_exhook.conf + +rm -f $EMQX_DATA_PATH +cp /opt/data/loaded_plugins $EMQX_DATA_PATH + + +if [ -f "$CONFIG_PATH" ] +then + # Removing edited files + rm -f $CONFIG_PATH + # Reverting template files to originals + mv $CONFIG_TEMPLATE_PATH $CONFIG_PATH +fi echo "Starting server.." sh /opt/emqx/bin/emqx foreground -- 2.36.3