From 4ce15fafb585ea4206041da048a6d3985b127de2 Mon Sep 17 00:00:00 2001 From: Stev Witzel Date: Mon, 16 Sep 2019 22:19:32 +0200 Subject: [PATCH 1/3] Add support for read-only config file mounts This is a pretty common use-case given that as of Kubernetes v1.9.4 configMaps are mounted as read-only. Fixes #368 --- 3.7-rc/alpine/docker-entrypoint.sh | 7 +++++++ 3.7-rc/ubuntu/docker-entrypoint.sh | 7 +++++++ 3.7/alpine/docker-entrypoint.sh | 7 +++++++ 3.7/ubuntu/docker-entrypoint.sh | 7 +++++++ 3.8-rc/alpine/docker-entrypoint.sh | 7 +++++++ 3.8-rc/ubuntu/docker-entrypoint.sh | 7 +++++++ docker-entrypoint.sh | 7 +++++++ 7 files changed, 49 insertions(+) diff --git a/3.7-rc/alpine/docker-entrypoint.sh b/3.7-rc/alpine/docker-entrypoint.sh index 32b765c3..2a744a3e 100755 --- a/3.7-rc/alpine/docker-entrypoint.sh +++ b/3.7-rc/alpine/docker-entrypoint.sh @@ -202,6 +202,13 @@ oldConfigFile="$configBase.config" newConfigFile="$configBase.conf" shouldWriteConfig="$haveConfig" +if [ -n "$shouldWriteConfig" ] && [ -f "$newConfigFile" ] && [ ! -w "$newConfigFile" ]; then + # config file exist but it isn't writeable (e.g. Kubernetes v1.9.4+ configMap mount) + tmp="/tmp/rabbitmq.conf" + cat "$newConfigFile" > "${tmp}" + newConfigFile="${tmp}" + export RABBITMQ_CONFIG_FILE="${tmp}" +fi if [ -n "$shouldWriteConfig" ] && [ -f "$oldConfigFile" ]; then { echo "error: Docker configuration environment variables specified, but old-style (Erlang syntax) configuration file '$oldConfigFile' exists" diff --git a/3.7-rc/ubuntu/docker-entrypoint.sh b/3.7-rc/ubuntu/docker-entrypoint.sh index 4b002977..c7592ac4 100755 --- a/3.7-rc/ubuntu/docker-entrypoint.sh +++ b/3.7-rc/ubuntu/docker-entrypoint.sh @@ -202,6 +202,13 @@ oldConfigFile="$configBase.config" newConfigFile="$configBase.conf" shouldWriteConfig="$haveConfig" +if [ -n "$shouldWriteConfig" ] && [ -f "$newConfigFile" ] && [ ! -w "$newConfigFile" ]; then + # config file exist but it isn't writeable (e.g. Kubernetes v1.9.4+ configMap mount) + tmp="/tmp/rabbitmq.conf" + cat "$newConfigFile" > "${tmp}" + newConfigFile="${tmp}" + export RABBITMQ_CONFIG_FILE="${tmp}" +fi if [ -n "$shouldWriteConfig" ] && [ -f "$oldConfigFile" ]; then { echo "error: Docker configuration environment variables specified, but old-style (Erlang syntax) configuration file '$oldConfigFile' exists" diff --git a/3.7/alpine/docker-entrypoint.sh b/3.7/alpine/docker-entrypoint.sh index 32b765c3..2a744a3e 100755 --- a/3.7/alpine/docker-entrypoint.sh +++ b/3.7/alpine/docker-entrypoint.sh @@ -202,6 +202,13 @@ oldConfigFile="$configBase.config" newConfigFile="$configBase.conf" shouldWriteConfig="$haveConfig" +if [ -n "$shouldWriteConfig" ] && [ -f "$newConfigFile" ] && [ ! -w "$newConfigFile" ]; then + # config file exist but it isn't writeable (e.g. Kubernetes v1.9.4+ configMap mount) + tmp="/tmp/rabbitmq.conf" + cat "$newConfigFile" > "${tmp}" + newConfigFile="${tmp}" + export RABBITMQ_CONFIG_FILE="${tmp}" +fi if [ -n "$shouldWriteConfig" ] && [ -f "$oldConfigFile" ]; then { echo "error: Docker configuration environment variables specified, but old-style (Erlang syntax) configuration file '$oldConfigFile' exists" diff --git a/3.7/ubuntu/docker-entrypoint.sh b/3.7/ubuntu/docker-entrypoint.sh index 4b002977..c7592ac4 100755 --- a/3.7/ubuntu/docker-entrypoint.sh +++ b/3.7/ubuntu/docker-entrypoint.sh @@ -202,6 +202,13 @@ oldConfigFile="$configBase.config" newConfigFile="$configBase.conf" shouldWriteConfig="$haveConfig" +if [ -n "$shouldWriteConfig" ] && [ -f "$newConfigFile" ] && [ ! -w "$newConfigFile" ]; then + # config file exist but it isn't writeable (e.g. Kubernetes v1.9.4+ configMap mount) + tmp="/tmp/rabbitmq.conf" + cat "$newConfigFile" > "${tmp}" + newConfigFile="${tmp}" + export RABBITMQ_CONFIG_FILE="${tmp}" +fi if [ -n "$shouldWriteConfig" ] && [ -f "$oldConfigFile" ]; then { echo "error: Docker configuration environment variables specified, but old-style (Erlang syntax) configuration file '$oldConfigFile' exists" diff --git a/3.8-rc/alpine/docker-entrypoint.sh b/3.8-rc/alpine/docker-entrypoint.sh index 32b765c3..2a744a3e 100755 --- a/3.8-rc/alpine/docker-entrypoint.sh +++ b/3.8-rc/alpine/docker-entrypoint.sh @@ -202,6 +202,13 @@ oldConfigFile="$configBase.config" newConfigFile="$configBase.conf" shouldWriteConfig="$haveConfig" +if [ -n "$shouldWriteConfig" ] && [ -f "$newConfigFile" ] && [ ! -w "$newConfigFile" ]; then + # config file exist but it isn't writeable (e.g. Kubernetes v1.9.4+ configMap mount) + tmp="/tmp/rabbitmq.conf" + cat "$newConfigFile" > "${tmp}" + newConfigFile="${tmp}" + export RABBITMQ_CONFIG_FILE="${tmp}" +fi if [ -n "$shouldWriteConfig" ] && [ -f "$oldConfigFile" ]; then { echo "error: Docker configuration environment variables specified, but old-style (Erlang syntax) configuration file '$oldConfigFile' exists" diff --git a/3.8-rc/ubuntu/docker-entrypoint.sh b/3.8-rc/ubuntu/docker-entrypoint.sh index 4b002977..c7592ac4 100755 --- a/3.8-rc/ubuntu/docker-entrypoint.sh +++ b/3.8-rc/ubuntu/docker-entrypoint.sh @@ -202,6 +202,13 @@ oldConfigFile="$configBase.config" newConfigFile="$configBase.conf" shouldWriteConfig="$haveConfig" +if [ -n "$shouldWriteConfig" ] && [ -f "$newConfigFile" ] && [ ! -w "$newConfigFile" ]; then + # config file exist but it isn't writeable (e.g. Kubernetes v1.9.4+ configMap mount) + tmp="/tmp/rabbitmq.conf" + cat "$newConfigFile" > "${tmp}" + newConfigFile="${tmp}" + export RABBITMQ_CONFIG_FILE="${tmp}" +fi if [ -n "$shouldWriteConfig" ] && [ -f "$oldConfigFile" ]; then { echo "error: Docker configuration environment variables specified, but old-style (Erlang syntax) configuration file '$oldConfigFile' exists" diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 4b002977..c7592ac4 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -202,6 +202,13 @@ oldConfigFile="$configBase.config" newConfigFile="$configBase.conf" shouldWriteConfig="$haveConfig" +if [ -n "$shouldWriteConfig" ] && [ -f "$newConfigFile" ] && [ ! -w "$newConfigFile" ]; then + # config file exist but it isn't writeable (e.g. Kubernetes v1.9.4+ configMap mount) + tmp="/tmp/rabbitmq.conf" + cat "$newConfigFile" > "${tmp}" + newConfigFile="${tmp}" + export RABBITMQ_CONFIG_FILE="${tmp}" +fi if [ -n "$shouldWriteConfig" ] && [ -f "$oldConfigFile" ]; then { echo "error: Docker configuration environment variables specified, but old-style (Erlang syntax) configuration file '$oldConfigFile' exists" From ed7c222e42161c2aab9d42df884abcba3f23e7f5 Mon Sep 17 00:00:00 2001 From: James McNeil <8350153+j4mcs@users.noreply.github.com> Date: Thu, 18 Jun 2020 16:07:35 +0100 Subject: [PATCH 2/3] Check for mounted config file to copy (#1) --- 3.7-rc/alpine/docker-entrypoint.sh | 2 +- 3.7-rc/ubuntu/docker-entrypoint.sh | 2 +- 3.7/alpine/docker-entrypoint.sh | 2 +- 3.7/ubuntu/docker-entrypoint.sh | 2 +- 3.8-rc/alpine/docker-entrypoint.sh | 2 +- 3.8-rc/ubuntu/docker-entrypoint.sh | 2 +- docker-entrypoint.sh | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/3.7-rc/alpine/docker-entrypoint.sh b/3.7-rc/alpine/docker-entrypoint.sh index 2a744a3e..a7f1ebbc 100755 --- a/3.7-rc/alpine/docker-entrypoint.sh +++ b/3.7-rc/alpine/docker-entrypoint.sh @@ -202,7 +202,7 @@ oldConfigFile="$configBase.config" newConfigFile="$configBase.conf" shouldWriteConfig="$haveConfig" -if [ -n "$shouldWriteConfig" ] && [ -f "$newConfigFile" ] && [ ! -w "$newConfigFile" ]; then +if [ -n "$shouldWriteConfig" ] && [ -f "$newConfigFile" ] && { [ ! -w "$newConfigFile" ] || [ "$(grep -sq "$newConfigFile" /proc/mounts; echo $?)" -eq 0 ]; }; then # config file exist but it isn't writeable (e.g. Kubernetes v1.9.4+ configMap mount) tmp="/tmp/rabbitmq.conf" cat "$newConfigFile" > "${tmp}" diff --git a/3.7-rc/ubuntu/docker-entrypoint.sh b/3.7-rc/ubuntu/docker-entrypoint.sh index c7592ac4..76fccc73 100755 --- a/3.7-rc/ubuntu/docker-entrypoint.sh +++ b/3.7-rc/ubuntu/docker-entrypoint.sh @@ -202,7 +202,7 @@ oldConfigFile="$configBase.config" newConfigFile="$configBase.conf" shouldWriteConfig="$haveConfig" -if [ -n "$shouldWriteConfig" ] && [ -f "$newConfigFile" ] && [ ! -w "$newConfigFile" ]; then +if [ -n "$shouldWriteConfig" ] && [ -f "$newConfigFile" ] && { [ ! -w "$newConfigFile" ] || [ "$(grep -sq "$newConfigFile" /proc/mounts; echo $?)" -eq 0 ]; }; then # config file exist but it isn't writeable (e.g. Kubernetes v1.9.4+ configMap mount) tmp="/tmp/rabbitmq.conf" cat "$newConfigFile" > "${tmp}" diff --git a/3.7/alpine/docker-entrypoint.sh b/3.7/alpine/docker-entrypoint.sh index 2a744a3e..a7f1ebbc 100755 --- a/3.7/alpine/docker-entrypoint.sh +++ b/3.7/alpine/docker-entrypoint.sh @@ -202,7 +202,7 @@ oldConfigFile="$configBase.config" newConfigFile="$configBase.conf" shouldWriteConfig="$haveConfig" -if [ -n "$shouldWriteConfig" ] && [ -f "$newConfigFile" ] && [ ! -w "$newConfigFile" ]; then +if [ -n "$shouldWriteConfig" ] && [ -f "$newConfigFile" ] && { [ ! -w "$newConfigFile" ] || [ "$(grep -sq "$newConfigFile" /proc/mounts; echo $?)" -eq 0 ]; }; then # config file exist but it isn't writeable (e.g. Kubernetes v1.9.4+ configMap mount) tmp="/tmp/rabbitmq.conf" cat "$newConfigFile" > "${tmp}" diff --git a/3.7/ubuntu/docker-entrypoint.sh b/3.7/ubuntu/docker-entrypoint.sh index c7592ac4..76fccc73 100755 --- a/3.7/ubuntu/docker-entrypoint.sh +++ b/3.7/ubuntu/docker-entrypoint.sh @@ -202,7 +202,7 @@ oldConfigFile="$configBase.config" newConfigFile="$configBase.conf" shouldWriteConfig="$haveConfig" -if [ -n "$shouldWriteConfig" ] && [ -f "$newConfigFile" ] && [ ! -w "$newConfigFile" ]; then +if [ -n "$shouldWriteConfig" ] && [ -f "$newConfigFile" ] && { [ ! -w "$newConfigFile" ] || [ "$(grep -sq "$newConfigFile" /proc/mounts; echo $?)" -eq 0 ]; }; then # config file exist but it isn't writeable (e.g. Kubernetes v1.9.4+ configMap mount) tmp="/tmp/rabbitmq.conf" cat "$newConfigFile" > "${tmp}" diff --git a/3.8-rc/alpine/docker-entrypoint.sh b/3.8-rc/alpine/docker-entrypoint.sh index 2a744a3e..a7f1ebbc 100755 --- a/3.8-rc/alpine/docker-entrypoint.sh +++ b/3.8-rc/alpine/docker-entrypoint.sh @@ -202,7 +202,7 @@ oldConfigFile="$configBase.config" newConfigFile="$configBase.conf" shouldWriteConfig="$haveConfig" -if [ -n "$shouldWriteConfig" ] && [ -f "$newConfigFile" ] && [ ! -w "$newConfigFile" ]; then +if [ -n "$shouldWriteConfig" ] && [ -f "$newConfigFile" ] && { [ ! -w "$newConfigFile" ] || [ "$(grep -sq "$newConfigFile" /proc/mounts; echo $?)" -eq 0 ]; }; then # config file exist but it isn't writeable (e.g. Kubernetes v1.9.4+ configMap mount) tmp="/tmp/rabbitmq.conf" cat "$newConfigFile" > "${tmp}" diff --git a/3.8-rc/ubuntu/docker-entrypoint.sh b/3.8-rc/ubuntu/docker-entrypoint.sh index c7592ac4..76fccc73 100755 --- a/3.8-rc/ubuntu/docker-entrypoint.sh +++ b/3.8-rc/ubuntu/docker-entrypoint.sh @@ -202,7 +202,7 @@ oldConfigFile="$configBase.config" newConfigFile="$configBase.conf" shouldWriteConfig="$haveConfig" -if [ -n "$shouldWriteConfig" ] && [ -f "$newConfigFile" ] && [ ! -w "$newConfigFile" ]; then +if [ -n "$shouldWriteConfig" ] && [ -f "$newConfigFile" ] && { [ ! -w "$newConfigFile" ] || [ "$(grep -sq "$newConfigFile" /proc/mounts; echo $?)" -eq 0 ]; }; then # config file exist but it isn't writeable (e.g. Kubernetes v1.9.4+ configMap mount) tmp="/tmp/rabbitmq.conf" cat "$newConfigFile" > "${tmp}" diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index c7592ac4..76fccc73 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -202,7 +202,7 @@ oldConfigFile="$configBase.config" newConfigFile="$configBase.conf" shouldWriteConfig="$haveConfig" -if [ -n "$shouldWriteConfig" ] && [ -f "$newConfigFile" ] && [ ! -w "$newConfigFile" ]; then +if [ -n "$shouldWriteConfig" ] && [ -f "$newConfigFile" ] && { [ ! -w "$newConfigFile" ] || [ "$(grep -sq "$newConfigFile" /proc/mounts; echo $?)" -eq 0 ]; }; then # config file exist but it isn't writeable (e.g. Kubernetes v1.9.4+ configMap mount) tmp="/tmp/rabbitmq.conf" cat "$newConfigFile" > "${tmp}" From 34ed62c7a49935d7f3e6f0e1392edba66233fb75 Mon Sep 17 00:00:00 2001 From: James McNeil Date: Tue, 23 Jun 2020 14:09:02 +0100 Subject: [PATCH 3/3] touch config file to verify it is read-only --- 3.7-rc/alpine/docker-entrypoint.sh | 15 +++++++++------ 3.7-rc/ubuntu/docker-entrypoint.sh | 15 +++++++++------ 3.7/alpine/docker-entrypoint.sh | 15 +++++++++------ 3.7/ubuntu/docker-entrypoint.sh | 15 +++++++++------ 3.8-rc/alpine/docker-entrypoint.sh | 15 +++++++++------ 3.8-rc/ubuntu/docker-entrypoint.sh | 15 +++++++++------ docker-entrypoint.sh | 15 +++++++++------ 7 files changed, 63 insertions(+), 42 deletions(-) diff --git a/3.7-rc/alpine/docker-entrypoint.sh b/3.7-rc/alpine/docker-entrypoint.sh index a7f1ebbc..094b72f4 100755 --- a/3.7-rc/alpine/docker-entrypoint.sh +++ b/3.7-rc/alpine/docker-entrypoint.sh @@ -202,12 +202,15 @@ oldConfigFile="$configBase.config" newConfigFile="$configBase.conf" shouldWriteConfig="$haveConfig" -if [ -n "$shouldWriteConfig" ] && [ -f "$newConfigFile" ] && { [ ! -w "$newConfigFile" ] || [ "$(grep -sq "$newConfigFile" /proc/mounts; echo $?)" -eq 0 ]; }; then - # config file exist but it isn't writeable (e.g. Kubernetes v1.9.4+ configMap mount) - tmp="/tmp/rabbitmq.conf" - cat "$newConfigFile" > "${tmp}" - newConfigFile="${tmp}" - export RABBITMQ_CONFIG_FILE="${tmp}" +if [ -n "$shouldWriteConfig" ] && ! touch "$newConfigFile"; then + # config file exists but it isn't writeable (likely read-only mount, such as Kubernetes configMap) + export RABBITMQ_CONFIG_FILE='/tmp/rabbitmq.conf' + cp "$newConfigFile" "$RABBITMQ_CONFIG_FILE" + echo >&2 + echo >&2 "WARNING: '$newConfigFile' is not writable, but environment variables have been provided which request that we write to it" + echo >&2 " We have copied it to '$RABBITMQ_CONFIG_FILE' so it can be amended to work around the problem, but it is recommended that the read-only source file should be modified and the environment variables removed instead." + echo >&2 + newConfigFile="$RABBITMQ_CONFIG_FILE" fi if [ -n "$shouldWriteConfig" ] && [ -f "$oldConfigFile" ]; then { diff --git a/3.7-rc/ubuntu/docker-entrypoint.sh b/3.7-rc/ubuntu/docker-entrypoint.sh index 76fccc73..e159f8b5 100755 --- a/3.7-rc/ubuntu/docker-entrypoint.sh +++ b/3.7-rc/ubuntu/docker-entrypoint.sh @@ -202,12 +202,15 @@ oldConfigFile="$configBase.config" newConfigFile="$configBase.conf" shouldWriteConfig="$haveConfig" -if [ -n "$shouldWriteConfig" ] && [ -f "$newConfigFile" ] && { [ ! -w "$newConfigFile" ] || [ "$(grep -sq "$newConfigFile" /proc/mounts; echo $?)" -eq 0 ]; }; then - # config file exist but it isn't writeable (e.g. Kubernetes v1.9.4+ configMap mount) - tmp="/tmp/rabbitmq.conf" - cat "$newConfigFile" > "${tmp}" - newConfigFile="${tmp}" - export RABBITMQ_CONFIG_FILE="${tmp}" +if [ -n "$shouldWriteConfig" ] && ! touch "$newConfigFile"; then + # config file exists but it isn't writeable (likely read-only mount, such as Kubernetes configMap) + export RABBITMQ_CONFIG_FILE='/tmp/rabbitmq.conf' + cp "$newConfigFile" "$RABBITMQ_CONFIG_FILE" + echo >&2 + echo >&2 "WARNING: '$newConfigFile' is not writable, but environment variables have been provided which request that we write to it" + echo >&2 " We have copied it to '$RABBITMQ_CONFIG_FILE' so it can be amended to work around the problem, but it is recommended that the read-only source file should be modified and the environment variables removed instead." + echo >&2 + newConfigFile="$RABBITMQ_CONFIG_FILE" fi if [ -n "$shouldWriteConfig" ] && [ -f "$oldConfigFile" ]; then { diff --git a/3.7/alpine/docker-entrypoint.sh b/3.7/alpine/docker-entrypoint.sh index a7f1ebbc..094b72f4 100755 --- a/3.7/alpine/docker-entrypoint.sh +++ b/3.7/alpine/docker-entrypoint.sh @@ -202,12 +202,15 @@ oldConfigFile="$configBase.config" newConfigFile="$configBase.conf" shouldWriteConfig="$haveConfig" -if [ -n "$shouldWriteConfig" ] && [ -f "$newConfigFile" ] && { [ ! -w "$newConfigFile" ] || [ "$(grep -sq "$newConfigFile" /proc/mounts; echo $?)" -eq 0 ]; }; then - # config file exist but it isn't writeable (e.g. Kubernetes v1.9.4+ configMap mount) - tmp="/tmp/rabbitmq.conf" - cat "$newConfigFile" > "${tmp}" - newConfigFile="${tmp}" - export RABBITMQ_CONFIG_FILE="${tmp}" +if [ -n "$shouldWriteConfig" ] && ! touch "$newConfigFile"; then + # config file exists but it isn't writeable (likely read-only mount, such as Kubernetes configMap) + export RABBITMQ_CONFIG_FILE='/tmp/rabbitmq.conf' + cp "$newConfigFile" "$RABBITMQ_CONFIG_FILE" + echo >&2 + echo >&2 "WARNING: '$newConfigFile' is not writable, but environment variables have been provided which request that we write to it" + echo >&2 " We have copied it to '$RABBITMQ_CONFIG_FILE' so it can be amended to work around the problem, but it is recommended that the read-only source file should be modified and the environment variables removed instead." + echo >&2 + newConfigFile="$RABBITMQ_CONFIG_FILE" fi if [ -n "$shouldWriteConfig" ] && [ -f "$oldConfigFile" ]; then { diff --git a/3.7/ubuntu/docker-entrypoint.sh b/3.7/ubuntu/docker-entrypoint.sh index 76fccc73..e159f8b5 100755 --- a/3.7/ubuntu/docker-entrypoint.sh +++ b/3.7/ubuntu/docker-entrypoint.sh @@ -202,12 +202,15 @@ oldConfigFile="$configBase.config" newConfigFile="$configBase.conf" shouldWriteConfig="$haveConfig" -if [ -n "$shouldWriteConfig" ] && [ -f "$newConfigFile" ] && { [ ! -w "$newConfigFile" ] || [ "$(grep -sq "$newConfigFile" /proc/mounts; echo $?)" -eq 0 ]; }; then - # config file exist but it isn't writeable (e.g. Kubernetes v1.9.4+ configMap mount) - tmp="/tmp/rabbitmq.conf" - cat "$newConfigFile" > "${tmp}" - newConfigFile="${tmp}" - export RABBITMQ_CONFIG_FILE="${tmp}" +if [ -n "$shouldWriteConfig" ] && ! touch "$newConfigFile"; then + # config file exists but it isn't writeable (likely read-only mount, such as Kubernetes configMap) + export RABBITMQ_CONFIG_FILE='/tmp/rabbitmq.conf' + cp "$newConfigFile" "$RABBITMQ_CONFIG_FILE" + echo >&2 + echo >&2 "WARNING: '$newConfigFile' is not writable, but environment variables have been provided which request that we write to it" + echo >&2 " We have copied it to '$RABBITMQ_CONFIG_FILE' so it can be amended to work around the problem, but it is recommended that the read-only source file should be modified and the environment variables removed instead." + echo >&2 + newConfigFile="$RABBITMQ_CONFIG_FILE" fi if [ -n "$shouldWriteConfig" ] && [ -f "$oldConfigFile" ]; then { diff --git a/3.8-rc/alpine/docker-entrypoint.sh b/3.8-rc/alpine/docker-entrypoint.sh index a7f1ebbc..094b72f4 100755 --- a/3.8-rc/alpine/docker-entrypoint.sh +++ b/3.8-rc/alpine/docker-entrypoint.sh @@ -202,12 +202,15 @@ oldConfigFile="$configBase.config" newConfigFile="$configBase.conf" shouldWriteConfig="$haveConfig" -if [ -n "$shouldWriteConfig" ] && [ -f "$newConfigFile" ] && { [ ! -w "$newConfigFile" ] || [ "$(grep -sq "$newConfigFile" /proc/mounts; echo $?)" -eq 0 ]; }; then - # config file exist but it isn't writeable (e.g. Kubernetes v1.9.4+ configMap mount) - tmp="/tmp/rabbitmq.conf" - cat "$newConfigFile" > "${tmp}" - newConfigFile="${tmp}" - export RABBITMQ_CONFIG_FILE="${tmp}" +if [ -n "$shouldWriteConfig" ] && ! touch "$newConfigFile"; then + # config file exists but it isn't writeable (likely read-only mount, such as Kubernetes configMap) + export RABBITMQ_CONFIG_FILE='/tmp/rabbitmq.conf' + cp "$newConfigFile" "$RABBITMQ_CONFIG_FILE" + echo >&2 + echo >&2 "WARNING: '$newConfigFile' is not writable, but environment variables have been provided which request that we write to it" + echo >&2 " We have copied it to '$RABBITMQ_CONFIG_FILE' so it can be amended to work around the problem, but it is recommended that the read-only source file should be modified and the environment variables removed instead." + echo >&2 + newConfigFile="$RABBITMQ_CONFIG_FILE" fi if [ -n "$shouldWriteConfig" ] && [ -f "$oldConfigFile" ]; then { diff --git a/3.8-rc/ubuntu/docker-entrypoint.sh b/3.8-rc/ubuntu/docker-entrypoint.sh index 76fccc73..e159f8b5 100755 --- a/3.8-rc/ubuntu/docker-entrypoint.sh +++ b/3.8-rc/ubuntu/docker-entrypoint.sh @@ -202,12 +202,15 @@ oldConfigFile="$configBase.config" newConfigFile="$configBase.conf" shouldWriteConfig="$haveConfig" -if [ -n "$shouldWriteConfig" ] && [ -f "$newConfigFile" ] && { [ ! -w "$newConfigFile" ] || [ "$(grep -sq "$newConfigFile" /proc/mounts; echo $?)" -eq 0 ]; }; then - # config file exist but it isn't writeable (e.g. Kubernetes v1.9.4+ configMap mount) - tmp="/tmp/rabbitmq.conf" - cat "$newConfigFile" > "${tmp}" - newConfigFile="${tmp}" - export RABBITMQ_CONFIG_FILE="${tmp}" +if [ -n "$shouldWriteConfig" ] && ! touch "$newConfigFile"; then + # config file exists but it isn't writeable (likely read-only mount, such as Kubernetes configMap) + export RABBITMQ_CONFIG_FILE='/tmp/rabbitmq.conf' + cp "$newConfigFile" "$RABBITMQ_CONFIG_FILE" + echo >&2 + echo >&2 "WARNING: '$newConfigFile' is not writable, but environment variables have been provided which request that we write to it" + echo >&2 " We have copied it to '$RABBITMQ_CONFIG_FILE' so it can be amended to work around the problem, but it is recommended that the read-only source file should be modified and the environment variables removed instead." + echo >&2 + newConfigFile="$RABBITMQ_CONFIG_FILE" fi if [ -n "$shouldWriteConfig" ] && [ -f "$oldConfigFile" ]; then { diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 76fccc73..e159f8b5 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -202,12 +202,15 @@ oldConfigFile="$configBase.config" newConfigFile="$configBase.conf" shouldWriteConfig="$haveConfig" -if [ -n "$shouldWriteConfig" ] && [ -f "$newConfigFile" ] && { [ ! -w "$newConfigFile" ] || [ "$(grep -sq "$newConfigFile" /proc/mounts; echo $?)" -eq 0 ]; }; then - # config file exist but it isn't writeable (e.g. Kubernetes v1.9.4+ configMap mount) - tmp="/tmp/rabbitmq.conf" - cat "$newConfigFile" > "${tmp}" - newConfigFile="${tmp}" - export RABBITMQ_CONFIG_FILE="${tmp}" +if [ -n "$shouldWriteConfig" ] && ! touch "$newConfigFile"; then + # config file exists but it isn't writeable (likely read-only mount, such as Kubernetes configMap) + export RABBITMQ_CONFIG_FILE='/tmp/rabbitmq.conf' + cp "$newConfigFile" "$RABBITMQ_CONFIG_FILE" + echo >&2 + echo >&2 "WARNING: '$newConfigFile' is not writable, but environment variables have been provided which request that we write to it" + echo >&2 " We have copied it to '$RABBITMQ_CONFIG_FILE' so it can be amended to work around the problem, but it is recommended that the read-only source file should be modified and the environment variables removed instead." + echo >&2 + newConfigFile="$RABBITMQ_CONFIG_FILE" fi if [ -n "$shouldWriteConfig" ] && [ -f "$oldConfigFile" ]; then {