fix: set $HOME when stepping down from root
Ticket: https://github.com/apache/couchdb-docker/issues/236
Why:
In https://github.com/apache/couchdb-docker/pull/234 we moved from using
`gosu` to `setpriv` to step down from the root user to the couchdb user.
There is a behavioural difference between and `gosu` and `setpriv` in
that `gosu` will [set the $HOME environment variable](https://github.com/tianon/gosu/blob/master/setup-user.go#L45)
to that of the target user.
Without this behaviour, `couchdb` includes the root user home
directory (`/root`) in various search paths and crashes because it
doesn't have read permissions.
How:
Explicitly set `$HOME` to the `couchdb` user home directory before
we execute as the `couchdb` user, replicating the `gosu` behaviour.
diff --git a/3.2.2/docker-entrypoint.sh b/3.2.2/docker-entrypoint.sh
index e691a66..a8544c7 100755
--- a/3.2.2/docker-entrypoint.sh
+++ b/3.2.2/docker-entrypoint.sh
@@ -114,6 +114,7 @@
fi
if [ "$(id -u)" = '0' ]; then
+ export HOME=$(echo ~couchdb)
exec setpriv --reuid=couchdb --regid=couchdb --clear-groups "$@"
fi
fi
diff --git a/3.3.1/docker-entrypoint.sh b/3.3.1/docker-entrypoint.sh
index e691a66..a8544c7 100755
--- a/3.3.1/docker-entrypoint.sh
+++ b/3.3.1/docker-entrypoint.sh
@@ -114,6 +114,7 @@
fi
if [ "$(id -u)" = '0' ]; then
+ export HOME=$(echo ~couchdb)
exec setpriv --reuid=couchdb --regid=couchdb --clear-groups "$@"
fi
fi
diff --git a/dev/docker-entrypoint.sh b/dev/docker-entrypoint.sh
index 0db874a..7239912 100755
--- a/dev/docker-entrypoint.sh
+++ b/dev/docker-entrypoint.sh
@@ -103,7 +103,7 @@
exit 1
fi
-
+ export HOME=$(echo ~couchdb)
exec setpriv --reuid=couchdb --regid=couchdb --clear-groups "$@"
fi