From 32aaf2e0ea014a1a71a616334885cc0e19119c25 Mon Sep 17 00:00:00 2001 From: Valentin Lab Date: Thu, 1 Oct 2020 09:28:24 +0200 Subject: [PATCH] fix: dev: prevent duplication of network parameters Previously, ``_set_db_params`` would be called several times and parameters would then be concatenated. We didn't want ``_set_db_params`` to overwrite and start from scratch to let possibility for customization before and after the call. Here ``set_db_params`` will set a global variable to detect if it was already launched prior to running content of ``_set_db_params``. Signed-off-by: Valentin Lab --- bin/compose-core | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/bin/compose-core b/bin/compose-core index deea57d..bb4d000 100755 --- a/bin/compose-core +++ b/bin/compose-core @@ -696,6 +696,15 @@ are_files_locked_in_dir() { export -f are_files_locked_in_dir +set_db_params() { + local docker_ip="$1" docker_network="$2" + if [ -z "$DB_PARAMS_LOADED" ]; then + DB_PARAMS_LOADED=1 + _set_db_params "$docker_ip" "$docker_network" + fi +} +export -f set_db_params + export _PID="$$" ensure_db_docker_running () { local _STATE_FILE @@ -706,7 +715,7 @@ ensure_db_docker_running () { IFS=: read DOCKER_NETWORK DOCKER_IP <<<"$(cat "$_STATE_FILE")" debug "Re-using previous docker/connection '$DOCKER_IP'." - _set_db_params "$DOCKER_IP" "$DOCKER_NETWORK" + set_db_params "$DOCKER_IP" "$DOCKER_NETWORK" return 0 fi @@ -753,7 +762,7 @@ ensure_db_docker_running () { docker pull "$DOCKER_BASE_IMAGE" fi - _set_server_db_params + _set_server_db_params || return 1 debug docker network create "$_DB_NAME" if ! network_id=$(docker network create "$_DB_NAME"); then err "'docker network create $_DB_NAME' failed !" @@ -788,7 +797,7 @@ ensure_db_docker_running () { echo "$docker_ip" > "$_STATE_FILE" debug "written '$_STATE_FILE'" rm "$state_tmpdir/${_DB_NAME}.working" - _set_db_params "$DOCKER_IP" "$DOCKER_NETWORK" + set_db_params "$DOCKER_IP" "$DOCKER_NETWORK" return 0 else errlvl="$?" @@ -923,7 +932,7 @@ wait_for_docker_ip() { err "internal 'wait_docker_ip' did not return a valid IP. Returned IP is '$DOCKER_IP'." return 1 fi - _set_db_params "$DOCKER_IP" "$DOCKER_NETWORK" + set_db_params "$DOCKER_IP" "$DOCKER_NETWORK" while read-0 port; do IFS="/" read port type <<<"$port" [ "$type" == "tcp" ] || continue