From 78d3cb4da1fe8eeb4509f7dcc95454d7313f5958 Mon Sep 17 00:00:00 2001 From: Valentin Lab Date: Wed, 17 Jan 2024 15:40:09 +0100 Subject: [PATCH] new: [compose-core] prevent sub compose command to try to solve again relation constraints This is because sub-compose command are often in a subset of the services and as a consequence they do not share the same environment and might solve the constraints differently. --- bin/compose | 19 +++++++++++++++++++ bin/compose-core | 10 ++++++++++ 2 files changed, 29 insertions(+) diff --git a/bin/compose b/bin/compose index 434533f..6434cdd 100755 --- a/bin/compose +++ b/bin/compose @@ -1006,6 +1006,22 @@ load_env() { fi done < "$COMPOSE_LAUNCHER_OPTS" fi + if [ -n "$ALL_RELATIONS" ]; then + if ! [ -e "$ALL_RELATIONS" ]; then + err "Variable \$ALL_RELATION provided but it doesn't point on an existing file." + return 1 + fi + if ! [ -r "$ALL_RELATIONS" ]; then + err "Variable \$ALL_RELATION provided but it doesn't point on a readable file." + return 1 + fi + NEW_ALL_RELATIONS="$COMPOSE_CACHE/${ALL_RELATIONS##*/}" + if [ "$NEW_ALL_RELATIONS" != "$ALL_RELATIONS" ]; then + cp "$ALL_RELATIONS" "$NEW_ALL_RELATIONS" || return 1 + fi + docker_run_opts+=("-e" "ALL_RELATIONS=$NEW_ALL_RELATIONS") + fi + } show_env() { @@ -1019,6 +1035,9 @@ show_env() { echo " COMPOSE_LAUNCHER_CACHE: $COMPOSE_LAUNCHER_CACHE" echo " SESSION_DIR: $SESSION_DIR" echo " TZ_PATH: $TZ_PATH" + if [ -n "$ALL_RELATIONS" ]; then + echo " ALL_RELATIONS: $ALL_RELATIONS" + fi } diff --git a/bin/compose-core b/bin/compose-core index 34d5406..ea7a418 100755 --- a/bin/compose-core +++ b/bin/compose-core @@ -2548,6 +2548,11 @@ get_all_relations () { local cache_file="$state_tmpdir/$FUNCNAME.cache.$(H "$@" "$(declare -p without_relations)")" \ services + if [ -n "$ALL_RELATIONS" ]; then + cat "$ALL_RELATIONS" || return 1 + return 0 + fi + if [ -e "${cache_file}" ]; then #debug "$FUNCNAME: SESSION cache hit $1" export ALL_RELATIONS="$cache_file" @@ -2899,6 +2904,11 @@ run_service_relations () { # debug " Relations of ${DARKYELLOW}$subservice${NORMAL}:" while read-0 relation_name target_service relation_config tech_dep; do + [ "${without_relations[$service:$relation_name]}" ] && { + debug "Skipping $DARKYELLOW$service$NORMAL --$DARKBLUE$relation_name$NORMAL--> $DARKYELLOW*$NORMAL" + continue + } + export relation_config export TARGET_SERVICE_NAME=$target_service MASTER_TARGET_SERVICE_NAME=$(get_top_master_service_for_service "$target_service") || return 1