Browse Source

new: dev: [compose-core] refactoring out the ``if`` condition

cache-relation
Valentin Lab 9 months ago
parent
commit
5b50f960bd
  1. 82
      bin/compose-core

82
bin/compose-core

@ -1436,42 +1436,40 @@ export -f get_build_hash
##
## Returns on stdout the name of the image if found, or an empty string if not
cache:image:registry:get() {
if [ -n "$COMPOSE_DOCKER_REGISTRY" ]; then
local charm="$1" hash="$2" service="$3"
local charm_image_name="cache/charm/$charm"
local charm_image="$charm_image_name:$hash"
local charm="$1" hash="$2" service="$3"
local charm_image_name="cache/charm/$charm"
local charm_image="$charm_image_name:$hash"
Elt "pulling ${DARKPINK}$charm${NORMAL} image from $COMPOSE_DOCKER_REGISTRY" >&2
if out=$(docker pull "$COMPOSE_DOCKER_REGISTRY/$charm_image" 2>&1); then
docker tag "$COMPOSE_DOCKER_REGISTRY/$charm_image" "$charm_image" || {
err "Failed set image '$COMPOSE_DOCKER_REGISTRY/$charm_image' as '$charm_image'" \
"for ${DARKYELLOW}$service${NORMAL}."
return 1
}
print_info "found" >&2
print_status success >&2
Feed >&2
printf "%s" "$charm_image" | tee "$cache_file"
return $?
fi
if [[ "$out" != *"manifest unknown"* ]]; then
print_status failure >&2
Feed >&2
err "Failed to pull image '$COMPOSE_DOCKER_REGISTRY/$charm_image'" \
"for ${DARKYELLOW}$service${NORMAL}:"
e "$out" | prefix " ${GRAY}|${NORMAL} " >&2
Elt "pulling ${DARKPINK}$charm${NORMAL} image from $COMPOSE_DOCKER_REGISTRY" >&2
if out=$(docker pull "$COMPOSE_DOCKER_REGISTRY/$charm_image" 2>&1); then
docker tag "$COMPOSE_DOCKER_REGISTRY/$charm_image" "$charm_image" || {
err "Failed set image '$COMPOSE_DOCKER_REGISTRY/$charm_image' as '$charm_image'" \
"for ${DARKYELLOW}$service${NORMAL}."
return 1
fi
print_info "not found" >&2
if test "$type_method" = "long"; then
__status="[${NOOP}ABSENT${NORMAL}]"
else
echo -n "${NOOP}"
shift; shift;
echo -n "$*${NORMAL}"
fi >&2
}
print_info "found" >&2
print_status success >&2
Feed >&2
printf "%s" "$charm_image" | tee "$cache_file"
return $?
fi
if [[ "$out" != *"manifest unknown"* ]] && [[ "$out" != *"not found"* ]]; then
print_status failure >&2
Feed >&2
err "Failed to pull image '$COMPOSE_DOCKER_REGISTRY/$charm_image'" \
"for ${DARKYELLOW}$service${NORMAL}:"
e "$out"$'\n' | prefix " ${GRAY}|${NORMAL} " >&2
return 1
fi
print_info "not found" >&2
if test "$type_method" = "long"; then
__status="[${NOOP}ABSENT${NORMAL}]"
else
echo -n "${NOOP}"
shift; shift;
echo -n "$*${NORMAL}"
fi >&2
Feed >&2
}
export -f cache:image:registry:get
@ -1636,16 +1634,16 @@ service_ensure_image_ready() {
fi
## Can we pull it ? Let's check on $COMPOSE_DOCKER_REGISTRY
img=$(cache:image:registry:get "$charm" "$hash" "$service") || {
err "Failed to get image '$charm_image_name:$hash' from registry for ${DARKYELLOW}$service${NORMAL}."
return 1
}
[ -n "$img" ] && {
printf "%s" "$img" | tee "$cache_file"
return $?
}
if [ -n "$COMPOSE_DOCKER_REGISTRY" ]; then
img=$(cache:image:registry:get "$charm" "$hash" "$service") || {
err "Failed to get image '$charm_image_name:$hash' from registry for ${DARKYELLOW}$service${NORMAL}."
return 1
}
[ -n "$img" ] && {
printf "%s" "$img" | tee "$cache_file"
return $?
}
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"

Loading…
Cancel
Save