This is an automated email from the ASF dual-hosted git repository.

kocolosk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/couchdb-docker.git


The following commit(s) were added to refs/heads/main by this push:
     new efa6e93  Listen for COUCHDB_ERLANG_COOKIE and write it down
efa6e93 is described below

commit efa6e93389c0d1b7980894f9059fb3a5775864b1
Author: Adam Kocoloski <[email protected]>
AuthorDate: Tue Feb 8 18:50:23 2022 -0500

    Listen for COUCHDB_ERLANG_COOKIE and write it down
---
 3.2.1/docker-entrypoint.sh | 15 +++++++++++++++
 README.md                  |  9 ++++++++-
 dev/docker-entrypoint.sh   | 15 +++++++++++++++
 3 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/3.2.1/docker-entrypoint.sh b/3.2.1/docker-entrypoint.sh
index 4b8b4f4..8d6456d 100755
--- a/3.2.1/docker-entrypoint.sh
+++ b/3.2.1/docker-entrypoint.sh
@@ -77,6 +77,21 @@ if [ "$1" = '/opt/couchdb/bin/couchdb' ]; then
                fi
        fi
 
+       if [ "$COUCHDB_ERLANG_COOKIE" ]; then
+               cookieFile='/opt/couchdb/.erlang.cookie'
+               if [ -e "$cookieFile" ]; then
+                       if [ "$(cat "$cookieFile" 2>/dev/null)" != 
"$COUCHDB_ERLANG_COOKIE" ]; then
+                               echo >&2
+                               echo >&2 "warning: $cookieFile contents do not 
match COUCHDB_ERLANG_COOKIE"
+                               echo >&2
+                       fi
+               else
+                       echo "$COUCHDB_ERLANG_COOKIE" > "$cookieFile"
+               fi
+               chown couchdb:couchdb "$cookieFile"
+               chmod 600 "$cookieFile"
+       fi
+
        if [ "$(id -u)" = '0' ]; then
                chown -f couchdb:couchdb /opt/couchdb/etc/local.d/docker.ini || 
true
        fi
diff --git a/README.md b/README.md
index 66110e0..db30db5 100644
--- a/README.md
+++ b/README.md
@@ -52,7 +52,14 @@ If you intend to network this CouchDB instance with others 
in a cluster, you wil
 
 Start your multiple CouchDB instances, then follow the Setup Wizard in the 
[official CouchDB 
documentation](http://docs.couchdb.org/en/stable/setup/cluster.html) to 
complete the process.
 
-For a CouchDB cluster you need to provide the `NODENAME` setting as well as 
the erlang cookie. Settings to Erlang can be made with the environment variable 
`ERL_FLAGS`, e.g. `ERL_FLAGS=-setcookie "brumbrum"`.
+For a CouchDB cluster you need to provide the `NODENAME` setting as well as the
+Erlang distribution cookie. The current version of this image allows the Erlang
+cookie to be set directly using the `COUCHDB_ERLANG_COOKIE` environment
+variable. The contents of that environment variable will be written to
+`/opt/couchdb/.erlang.cookie` with the proper permissions. Previously one would
+need to provide the `-setcookie` flag in the environment variable `ERL_FLAGS`,
+e.g. `ERL_FLAGS=-setcookie "brumbrum"`.
+
 By default, this image exposes the `epmd` port `4369` and the Erlang cluster 
communication port `9100` (i.e. `inet_dist_listen_min` and 
`inet_dist_listen_max` are both 9100).
 Further information can be found 
[here](http://docs.couchdb.org/en/stable/cluster/setup.html).
 
diff --git a/dev/docker-entrypoint.sh b/dev/docker-entrypoint.sh
index 4c1f9bf..95691c2 100755
--- a/dev/docker-entrypoint.sh
+++ b/dev/docker-entrypoint.sh
@@ -69,6 +69,21 @@ if [ "$1" = '/opt/couchdb/bin/couchdb' ]; then
                fi
        fi
 
+       if [ "$COUCHDB_ERLANG_COOKIE" ]; then
+               cookieFile='/opt/couchdb/.erlang.cookie'
+               if [ -e "$cookieFile" ]; then
+                       if [ "$(cat "$cookieFile" 2>/dev/null)" != 
"$COUCHDB_ERLANG_COOKIE" ]; then
+                               echo >&2
+                               echo >&2 "warning: $cookieFile contents do not 
match COUCHDB_ERLANG_COOKIE"
+                               echo >&2
+                       fi
+               else
+                       echo "$COUCHDB_ERLANG_COOKIE" > "$cookieFile"
+               fi
+               chown couchdb:couchdb "$cookieFile"
+               chmod 600 "$cookieFile"
+       fi
+
        chown -f couchdb:couchdb /opt/couchdb/etc/local.d/docker.ini || true
 
        # if we don't find an [admins] section followed by a non-comment, 
display a warning

Reply via email to