From 981fcfbc7b21b5ec5ec8be5d8b0f4bc54f6b8d69 Mon Sep 17 00:00:00 2001 From: Jason Kulatunga Date: Mon, 10 Oct 2022 07:46:33 -0700 Subject: [PATCH] fixed standalone couchdb setup. --- docker/README.md | 4 +++- docker/rootfs/etc/cont-init.d/50-couchdb-init | 17 ++++++++++------- docker/rootfs/opt/couchdb/etc/setup.ini | 18 ++++++++++++++++++ 3 files changed, 31 insertions(+), 8 deletions(-) create mode 100644 docker/rootfs/opt/couchdb/etc/setup.ini diff --git a/docker/README.md b/docker/README.md index 4888ea3d..443d3288 100644 --- a/docker/README.md +++ b/docker/README.md @@ -3,5 +3,7 @@ Note, the context for Dockerfiles in this directory is **always** the repository root. ```bash -docker build -f docker/couchdb/Dockerfile . +docker build -f docker/couchdb/Dockerfile -t couchdb-fasten . + +docker run --rm -it -p 5984:5984 -v `pwd`/.couchdb/data:/opt/couchdb/data -v `pwd`/.couchdb/config:/opt/couchdb/etc/local.d couchdb-fasten ``` diff --git a/docker/rootfs/etc/cont-init.d/50-couchdb-init b/docker/rootfs/etc/cont-init.d/50-couchdb-init index 15bff19b..726c537b 100644 --- a/docker/rootfs/etc/cont-init.d/50-couchdb-init +++ b/docker/rootfs/etc/cont-init.d/50-couchdb-init @@ -3,28 +3,31 @@ if [ -f "/opt/couchdb/data/.init_complete" ]; then echo "Couchdb initialization has already completed, skipping" else - + cp /opt/couchdb/etc/setup.ini /opt/couchdb/etc/local.d/setup.ini # start couchdb as a background process (store PID) echo "Couchdb initialization: start couchdb in background mode" - /opt/couchdb/bin/couchdb & + # https://linux.die.net/man/1/couchdb + /opt/couchdb/bin/couchdb -b & COUCHDB_PID=$! # wait for couchdb to be ready - until $(curl --output /dev/null --silent --head --fail http://127.0.0.1:5984/_up); do echo "couchdb not ready" && sleep 5; done + until $(curl --output /dev/null --silent --head --fail http://127.0.0.1:5432/_up); do echo "couchdb not ready" && sleep 5; done # create couch_peruser required system databases manually on startup echo "couchdb ready, start creating system databases" - curl -X PUT http://127.0.0.1:5984/_users - curl -X PUT http://127.0.0.1:5984/_replicator - curl -X PUT http://127.0.0.1:5984/_global_changes + curl --fail -X PUT -u admin:mysetuppassword http://127.0.0.1:5432/_users + curl --fail -X PUT -u admin:mysetuppassword http://127.0.0.1:5432/_replicator + curl --fail -X PUT -u admin:mysetuppassword http://127.0.0.1:5432/_global_changes echo "system databases created successfully" # gracefully stop couchdb process echo "killing couchdb process" - kill -2 $COUCHDB_PID + /opt/couchdb/bin/couchdb -k + rm -f /opt/couchdb/etc/local.d/setup.ini # create the init complete flag echo "Couchdb initialization: complete" touch /opt/couchdb/data/.init_complete + fi diff --git a/docker/rootfs/opt/couchdb/etc/setup.ini b/docker/rootfs/opt/couchdb/etc/setup.ini new file mode 100644 index 00000000..ecafd389 --- /dev/null +++ b/docker/rootfs/opt/couchdb/etc/setup.ini @@ -0,0 +1,18 @@ +; CouchDB Configuration Settings + +; This minimal file is only for use during first setup. It is insecure and WILL NOT be used after setup completes +; it will be copied into /opt/couchdb/etc/local.d temporarily. +[couchdb] +single_node = true + +[couch_peruser] +enable = true + +[chttpd] +; bind to localhost and a non-standard, unexposed port. +port = 5432 +bind_address = 127.0.0.1 + +[admins] +; THIS PASSWORD IS INSECURE, it is only used during setup and does not persist. +admin = mysetuppassword