From 5d3a3fde83ffa6f52707467754ea09c837e9c595 Mon Sep 17 00:00:00 2001 From: Valentin Lab Date: Wed, 28 Nov 2018 10:18:04 +0100 Subject: [PATCH] chg: database password file can now be stored in a different directory than host !api ``DB_PASSFILE`` is split into ``HOST_DB_PASSFILE`` and ``CLIENT_DB_PASSFILE`` to allow to use a ``HOST_DB_PASSFILE`` in a directory that is accessible to ``compose`` even when run in docker mode. Using this, we can store HOST_DB_PASSFILE along with the database files, which makes a lot more sense as it resolv issues of synchronising the database with the content of this file (namely, the authorization scheme). So when restoring the datastore of the database, the charm scripts will be able to use the db password file and will not have to worry about if it is in sync with the files or not. Note that ``db_docker_opts`` and ``db_cmd_opts`` are now bash arrays. As previous implementation was brittle, especially for handling spaces in arguments. --- bin/compose-core | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/bin/compose-core b/bin/compose-core index 28de05e..2ea12d2 100755 --- a/bin/compose-core +++ b/bin/compose-core @@ -560,10 +560,6 @@ ensure_db_docker_running () { fi docker_opts= - if [ -f "$DB_PASSFILE" ]; then - verb "Found and using '$DB_PASSFILE'." - docker_opts="$db_docker_opts -v $SERVER_ROOT_PREFIX$DB_PASSFILE:$DB_PASSFILE" - fi debug docker network create "$_DB_NAME" if ! network_id=$(docker network create "$_DB_NAME"); then err "'docker network create' failed !" @@ -619,18 +615,20 @@ _dcmd() { debug "Db> $command $@" - if [ -f "$DB_PASSFILE" ]; then - verb "Found and using '$DB_PASSFILE'." - db_docker_opts="$db_docker_opts -v $SERVER_ROOT_PREFIX$DB_PASSFILE:$DB_PASSFILE" + if [ -f "$HOST_DB_PASSFILE" -a "$CLIENT_DB_PASSFILE" ]; then + verb "Found and using '$HOST_DB_PASSFILE' as '$CLIENT_DB_PASSFILE'." + docker_opts=("${db_docker_opts[@]}" "-v" "$HOST_DB_PASSFILE:$CLIENT_DB_PASSFILE") + else + docker_opts=("${db_docker_opts[@]}") fi ## XXXX was here: actualy, we need only connection between this version and the client version debug docker run -i --rm \ - $db_docker_opts \ - --entrypoint "$command" "$DOCKER_BASE_IMAGE" $db_cmd_opts "$@" + "${docker_opts[@]}" \ + --entrypoint "$command" "$DOCKER_BASE_IMAGE" "${db_cmd_opts[@]}" "$@" docker run -i --rm \ - $db_docker_opts \ - --entrypoint "$command" "$DOCKER_BASE_IMAGE" $db_cmd_opts "$@" + "${docker_opts[@]}" \ + --entrypoint "$command" "$DOCKER_BASE_IMAGE" "${db_cmd_opts[@]}" "$@" } export -f _dcmd