From 07d8e57588f87106135bed1fa5e932df18862a68 Mon Sep 17 00:00:00 2001 From: Valentin Lab Date: Thu, 5 Dec 2024 07:18:49 +0100 Subject: [PATCH] fix: [compose-core] use proper cache for ``service_ensure_image_ready()`` --- bin/compose-core | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/bin/compose-core b/bin/compose-core index 05d5a93..0dddb71 100755 --- a/bin/compose-core +++ b/bin/compose-core @@ -1773,7 +1773,8 @@ service_ensure_image_ready() { err "Expected \$COMBINED_HASH to be set." return 1 fi - local service="$1" cache_file="$CACHEDIR/$FUNCNAME.cache.$1.$COMBINED_HASH" \ + local service="$1" \ + cache_file="$CACHEDIR/$FUNCNAME.cache.$1.$(H "$COMBINED_HASH" "$(cat "$_CURRENT_DOCKER_COMPOSE")")" \ master_service service_def service_image service_build service_dockerfile image \ specified_image specified_image_id charm_image_name hash \ service_quoted @@ -1781,6 +1782,7 @@ service_ensure_image_ready() { if [ -e "$cache_file" ]; then #debug "$FUNCNAME: cache hit ($*)" touch "$cache_file" || return 1 + cp "$cache_file.cdc" "$_CURRENT_DOCKER_COMPOSE" || return 1 cat "$cache_file" return 0 fi @@ -1798,8 +1800,9 @@ service_ensure_image_ready() { } if [ "$master_service" != "$service" ]; then image=$(service_ensure_image_ready "$master_service") || return 1 - printf "%s" "$image" | tee "$cache_file" - return $? + printf "%s" "$image" | tee "$cache_file" || return 1 + cp "$_CURRENT_DOCKER_COMPOSE" "$cache_file.cdc" || return 1 + return 0 fi ## check if \$_CURRENT_DOCKER_COMPOSE's service def is already correctly setup @@ -1813,7 +1816,8 @@ service_ensure_image_ready() { if specified_image=$(e "$service_def" | shyaml get-value image 2>/dev/null); then if [[ "$specified_image" == "$charm_image_name:"* ]]; then ## Assume we already did the change - printf "%s" "$specified_image" | tee "$cache_file" + printf "%s" "$specified_image" | tee "$cache_file" || return 1 + cp "$_CURRENT_DOCKER_COMPOSE" "$cache_file.cdc" || return 1 return 0 fi if [[ "$specified_image" == "${COMPOSE_DOCKER_REGISTRY}/"* ]]; then @@ -1829,7 +1833,8 @@ service_ensure_image_ready() { fi fi ## Already on the cache server - printf "%s" "$specified_image" | tee "$cache_file" + printf "%s" "$specified_image" | tee "$cache_file" || return 1 + cp "$_CURRENT_DOCKER_COMPOSE" "$cache_file.cdc" || return 1 return 0 fi src="$specified_image" @@ -1841,7 +1846,7 @@ service_ensure_image_ready() { "$_CURRENT_DOCKER_COMPOSE" || return 1 else - if ! src=$(echo "$service_def" | shyaml get-value build 2>/dev/null); then + if ! src=$(e "$service_def" | shyaml get-value build 2>/dev/null); then err "Service $DARKYELLOW$service$NORMAL has no ${WHITE}image${NORMAL} nor ${WHITE}build${NORMAL} parameter." echo "$service_def" >&2 return 1 @@ -1864,22 +1869,25 @@ service_ensure_image_ready() { Feed >&2 fi cache:image:registry:put "$charm" "$hash" "$service" || return 1 - printf "%s" "${charm_image_name}:${hash}" | tee "$cache_file" - return $? + printf "%s" "${charm_image_name}:${hash}" | tee "$cache_file" || return 1 + cp "$_CURRENT_DOCKER_COMPOSE" "$cache_file.cdc" || return 1 + return 0 fi ## Can we pull it ? Let's check on $COMPOSE_DOCKER_REGISTRY if [ "$COMPOSE_ACTION" != "build" ] && [ -n "$COMPOSE_DOCKER_REGISTRY" ]; then img=$(cache:image:registry:get "$charm" "$hash" "$service" 2>/dev/null) [ -n "$img" ] && { - printf "%s" "$img" | tee "$cache_file" - return $? + printf "%s" "$img" | tee "$cache_file" || return 1 + cp "$_CURRENT_DOCKER_COMPOSE" "$cache_file.cdc" || return 1 + return 0 } fi cache:image:produce "$type" "$src" "$charm" "$hash" "$service" || return 1 cache:image:registry:put "$charm" "$hash" "$service" || return 1 - printf "%s" "${charm_image_name}:$hash" | tee "$cache_file" - return $? + printf "%s" "${charm_image_name}:$hash" | tee "$cache_file" || return 1 + cp "$_CURRENT_DOCKER_COMPOSE" "$cache_file.cdc" || return 1 + return 0 } export -f service_ensure_image_ready