Skip to content

Commit a5cccf2

Browse files
authored
Merge pull request #369 from st3v/master
Add support for read-only config file mounts
2 parents acec97e + 34ed62c commit a5cccf2

File tree

7 files changed

+70
-0
lines changed

7 files changed

+70
-0
lines changed

3.7-rc/alpine/docker-entrypoint.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,16 @@ oldConfigFile="$configBase.config"
202202
newConfigFile="$configBase.conf"
203203

204204
shouldWriteConfig="$haveConfig"
205+
if [ -n "$shouldWriteConfig" ] && ! touch "$newConfigFile"; then
206+
# config file exists but it isn't writeable (likely read-only mount, such as Kubernetes configMap)
207+
export RABBITMQ_CONFIG_FILE='/tmp/rabbitmq.conf'
208+
cp "$newConfigFile" "$RABBITMQ_CONFIG_FILE"
209+
echo >&2
210+
echo >&2 "WARNING: '$newConfigFile' is not writable, but environment variables have been provided which request that we write to it"
211+
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."
212+
echo >&2
213+
newConfigFile="$RABBITMQ_CONFIG_FILE"
214+
fi
205215
if [ -n "$shouldWriteConfig" ] && [ -f "$oldConfigFile" ]; then
206216
{
207217
echo "error: Docker configuration environment variables specified, but old-style (Erlang syntax) configuration file '$oldConfigFile' exists"

3.7-rc/ubuntu/docker-entrypoint.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,16 @@ oldConfigFile="$configBase.config"
202202
newConfigFile="$configBase.conf"
203203

204204
shouldWriteConfig="$haveConfig"
205+
if [ -n "$shouldWriteConfig" ] && ! touch "$newConfigFile"; then
206+
# config file exists but it isn't writeable (likely read-only mount, such as Kubernetes configMap)
207+
export RABBITMQ_CONFIG_FILE='/tmp/rabbitmq.conf'
208+
cp "$newConfigFile" "$RABBITMQ_CONFIG_FILE"
209+
echo >&2
210+
echo >&2 "WARNING: '$newConfigFile' is not writable, but environment variables have been provided which request that we write to it"
211+
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."
212+
echo >&2
213+
newConfigFile="$RABBITMQ_CONFIG_FILE"
214+
fi
205215
if [ -n "$shouldWriteConfig" ] && [ -f "$oldConfigFile" ]; then
206216
{
207217
echo "error: Docker configuration environment variables specified, but old-style (Erlang syntax) configuration file '$oldConfigFile' exists"

3.7/alpine/docker-entrypoint.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,16 @@ oldConfigFile="$configBase.config"
202202
newConfigFile="$configBase.conf"
203203

204204
shouldWriteConfig="$haveConfig"
205+
if [ -n "$shouldWriteConfig" ] && ! touch "$newConfigFile"; then
206+
# config file exists but it isn't writeable (likely read-only mount, such as Kubernetes configMap)
207+
export RABBITMQ_CONFIG_FILE='/tmp/rabbitmq.conf'
208+
cp "$newConfigFile" "$RABBITMQ_CONFIG_FILE"
209+
echo >&2
210+
echo >&2 "WARNING: '$newConfigFile' is not writable, but environment variables have been provided which request that we write to it"
211+
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."
212+
echo >&2
213+
newConfigFile="$RABBITMQ_CONFIG_FILE"
214+
fi
205215
if [ -n "$shouldWriteConfig" ] && [ -f "$oldConfigFile" ]; then
206216
{
207217
echo "error: Docker configuration environment variables specified, but old-style (Erlang syntax) configuration file '$oldConfigFile' exists"

3.7/ubuntu/docker-entrypoint.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,16 @@ oldConfigFile="$configBase.config"
202202
newConfigFile="$configBase.conf"
203203

204204
shouldWriteConfig="$haveConfig"
205+
if [ -n "$shouldWriteConfig" ] && ! touch "$newConfigFile"; then
206+
# config file exists but it isn't writeable (likely read-only mount, such as Kubernetes configMap)
207+
export RABBITMQ_CONFIG_FILE='/tmp/rabbitmq.conf'
208+
cp "$newConfigFile" "$RABBITMQ_CONFIG_FILE"
209+
echo >&2
210+
echo >&2 "WARNING: '$newConfigFile' is not writable, but environment variables have been provided which request that we write to it"
211+
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."
212+
echo >&2
213+
newConfigFile="$RABBITMQ_CONFIG_FILE"
214+
fi
205215
if [ -n "$shouldWriteConfig" ] && [ -f "$oldConfigFile" ]; then
206216
{
207217
echo "error: Docker configuration environment variables specified, but old-style (Erlang syntax) configuration file '$oldConfigFile' exists"

3.8-rc/alpine/docker-entrypoint.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,16 @@ oldConfigFile="$configBase.config"
202202
newConfigFile="$configBase.conf"
203203

204204
shouldWriteConfig="$haveConfig"
205+
if [ -n "$shouldWriteConfig" ] && ! touch "$newConfigFile"; then
206+
# config file exists but it isn't writeable (likely read-only mount, such as Kubernetes configMap)
207+
export RABBITMQ_CONFIG_FILE='/tmp/rabbitmq.conf'
208+
cp "$newConfigFile" "$RABBITMQ_CONFIG_FILE"
209+
echo >&2
210+
echo >&2 "WARNING: '$newConfigFile' is not writable, but environment variables have been provided which request that we write to it"
211+
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."
212+
echo >&2
213+
newConfigFile="$RABBITMQ_CONFIG_FILE"
214+
fi
205215
if [ -n "$shouldWriteConfig" ] && [ -f "$oldConfigFile" ]; then
206216
{
207217
echo "error: Docker configuration environment variables specified, but old-style (Erlang syntax) configuration file '$oldConfigFile' exists"

3.8-rc/ubuntu/docker-entrypoint.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,16 @@ oldConfigFile="$configBase.config"
202202
newConfigFile="$configBase.conf"
203203

204204
shouldWriteConfig="$haveConfig"
205+
if [ -n "$shouldWriteConfig" ] && ! touch "$newConfigFile"; then
206+
# config file exists but it isn't writeable (likely read-only mount, such as Kubernetes configMap)
207+
export RABBITMQ_CONFIG_FILE='/tmp/rabbitmq.conf'
208+
cp "$newConfigFile" "$RABBITMQ_CONFIG_FILE"
209+
echo >&2
210+
echo >&2 "WARNING: '$newConfigFile' is not writable, but environment variables have been provided which request that we write to it"
211+
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."
212+
echo >&2
213+
newConfigFile="$RABBITMQ_CONFIG_FILE"
214+
fi
205215
if [ -n "$shouldWriteConfig" ] && [ -f "$oldConfigFile" ]; then
206216
{
207217
echo "error: Docker configuration environment variables specified, but old-style (Erlang syntax) configuration file '$oldConfigFile' exists"

docker-entrypoint.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,16 @@ oldConfigFile="$configBase.config"
202202
newConfigFile="$configBase.conf"
203203

204204
shouldWriteConfig="$haveConfig"
205+
if [ -n "$shouldWriteConfig" ] && ! touch "$newConfigFile"; then
206+
# config file exists but it isn't writeable (likely read-only mount, such as Kubernetes configMap)
207+
export RABBITMQ_CONFIG_FILE='/tmp/rabbitmq.conf'
208+
cp "$newConfigFile" "$RABBITMQ_CONFIG_FILE"
209+
echo >&2
210+
echo >&2 "WARNING: '$newConfigFile' is not writable, but environment variables have been provided which request that we write to it"
211+
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."
212+
echo >&2
213+
newConfigFile="$RABBITMQ_CONFIG_FILE"
214+
fi
205215
if [ -n "$shouldWriteConfig" ] && [ -f "$oldConfigFile" ]; then
206216
{
207217
echo "error: Docker configuration environment variables specified, but old-style (Erlang syntax) configuration file '$oldConfigFile' exists"

0 commit comments

Comments
 (0)