Browse Source

chg: dev: [compose,compose-core] rename ``ALL_RELATIONS`` to ``GLOBAL_ALL_RELATIONS``

We aim at making this variable global to a ``compose up`` session.
cache-relation
Valentin Lab 1 month ago
parent
commit
af246b1ad6
  1. 29
      bin/compose
  2. 40
      bin/compose-core

29
bin/compose

@ -1036,20 +1036,25 @@ load_env() {
fi fi
done < "$COMPOSE_LAUNCHER_OPTS" done < "$COMPOSE_LAUNCHER_OPTS"
fi 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."
if [ -n "$GLOBAL_ALL_RELATIONS" ]; then
if ! [ -e "$GLOBAL_ALL_RELATIONS" ]; then
err "Variable \$GLOBAL_ALL_RELATION provided but it doesn't point on an existing file."
return 1 return 1
fi fi
if ! [ -r "$ALL_RELATIONS" ]; then
err "Variable \$ALL_RELATION provided but it doesn't point on a readable file."
if ! [ -r "$GLOBAL_ALL_RELATIONS" ]; then
err "Variable \$GLOBAL_ALL_RELATION provided but it doesn't point on a readable file."
return 1 return 1
fi fi
NEW_ALL_RELATIONS="$COMPOSE_CACHE/${ALL_RELATIONS##*/}"
if [ "$NEW_ALL_RELATIONS" != "$ALL_RELATIONS" ]; then
cp "$ALL_RELATIONS" "$NEW_ALL_RELATIONS" || return 1
if [ -z "$GLOBAL_ALL_RELATIONS_HASH" ]; then
err "Variable \$GLOBAL_ALL_RELATION provided but not \$GLOBAL_ALL_RELATIONS_HASH."
return 1
fi
NEW_GLOBAL_ALL_RELATIONS="$COMPOSE_CACHE/${GLOBAL_ALL_RELATIONS##*/}"
if [ "$NEW_GLOBAL_ALL_RELATIONS" != "$GLOBAL_ALL_RELATIONS" ]; then
cp "$GLOBAL_ALL_RELATIONS" "$NEW_GLOBAL_ALL_RELATIONS" || return 1
fi fi
docker_run_opts+=("-e" "ALL_RELATIONS=$NEW_ALL_RELATIONS")
docker_run_opts+=("-e" "GLOBAL_ALL_RELATIONS=$NEW_GLOBAL_ALL_RELATIONS")
docker_run_opts+=("-e" "GLOBAL_ALL_RELATIONS_HASH=$GLOBAL_ALL_RELATIONS_HASH")
fi fi
if [ -n "$PROJECT_NAME" ]; then if [ -n "$PROJECT_NAME" ]; then
docker_run_opts+=("-e" "PROJECT_NAME=$PROJECT_NAME") docker_run_opts+=("-e" "PROJECT_NAME=$PROJECT_NAME")
@ -1068,8 +1073,10 @@ show_env() {
echo " COMPOSE_LAUNCHER_CACHE: $COMPOSE_LAUNCHER_CACHE" echo " COMPOSE_LAUNCHER_CACHE: $COMPOSE_LAUNCHER_CACHE"
echo " SESSION_DIR: $SESSION_DIR" echo " SESSION_DIR: $SESSION_DIR"
echo " TZ_PATH: $TZ_PATH" echo " TZ_PATH: $TZ_PATH"
[ -n "$ALL_RELATIONS" ] &&
echo " ALL_RELATIONS: $ALL_RELATIONS"
[ -n "$GLOBAL_ALL_RELATIONS" ] && {
echo " GLOBAL_ALL_RELATIONS: $GLOBAL_ALL_RELATIONS"
echo " GLOBAL_ALL_RELATIONS_HASH: $GLOBAL_ALL_RELATIONS_HASH"
}
[ -n "$PROJECT_NAME" ] && [ -n "$PROJECT_NAME" ] &&
echo " PROJECT_NAME: $PROJECT_NAME" echo " PROJECT_NAME: $PROJECT_NAME"

40
bin/compose-core

@ -1746,7 +1746,7 @@ export -f get_service_relation_tech_dep
## Use compose file to get deps, and relation definition in metadata.yml ## Use compose file to get deps, and relation definition in metadata.yml
## for tech-dep attribute. ## for tech-dep attribute.
get_service_deps() { get_service_deps() {
local service="$1" cache_file="$state_tmpdir/$FUNCNAME.cache.$(H "$@" "$ALL_RELATIONS")"
local service="$1" cache_file="$state_tmpdir/$FUNCNAME.cache.$(H "$@" "$GLOBAL_ALL_RELATIONS_HASH")"
if [ -e "$cache_file" ]; then if [ -e "$cache_file" ]; then
# debug "$FUNCNAME: cache hit ($*)" # debug "$FUNCNAME: cache hit ($*)"
cat "$cache_file" cat "$cache_file"
@ -1767,7 +1767,7 @@ export -f get_service_deps
_rec_get_depth() { _rec_get_depth() {
local elt=$1 dep deps max local elt=$1 dep deps max
[ "${depths[$elt]}" ] && return 0 [ "${depths[$elt]}" ] && return 0
local cache_file="$state_tmpdir/$FUNCNAME.cache.$(H "$@" "$(declare -pA depths)" "$ALL_RELATIONS")"
local cache_file="$state_tmpdir/$FUNCNAME.cache.$(H "$@" "$(declare -pA depths)" "$GLOBAL_ALL_RELATIONS_HASH")"
if [ -e "$cache_file.depths" ]; then if [ -e "$cache_file.depths" ]; then
#debug "$FUNCNAME: cache hit ($*) - $cache_file.depths" #debug "$FUNCNAME: cache hit ($*) - $cache_file.depths"
while read-0 k v; do while read-0 k v; do
@ -1810,7 +1810,7 @@ export -f _rec_get_depth
get_ordered_service_dependencies() { get_ordered_service_dependencies() {
local services=("$@") cache_file="$state_tmpdir/$FUNCNAME.cache.$(H "$@" "$ALL_RELATIONS")" \
local services=("$@") cache_file="$state_tmpdir/$FUNCNAME.cache.$(H "$@" "$GLOBAL_ALL_RELATIONS_HASH")" \
i value key heads depths visited i value key heads depths visited
if [ -e "$cache_file" ]; then if [ -e "$cache_file" ]; then
# debug "$FUNCNAME: cache hit ($*)" # debug "$FUNCNAME: cache hit ($*)"
@ -2398,7 +2398,7 @@ export -f get_compose_relations
get_all_services() { get_all_services() {
local cache_file="$state_tmpdir/$FUNCNAME.cache.$(H "$ALL_RELATIONS")" \
local cache_file="$state_tmpdir/$FUNCNAME.cache.$(H "$GLOBAL_ALL_RELATIONS_HASH")" \
s rn ts rc td services s rn ts rc td services
if [ -e "$cache_file" ]; then if [ -e "$cache_file" ]; then
#debug "$FUNCNAME: SESSION cache hit $1" #debug "$FUNCNAME: SESSION cache hit $1"
@ -2406,8 +2406,8 @@ get_all_services() {
return 0 return 0
fi fi
if [ -z "$ALL_RELATIONS" ]; then
err "Can't access global \$ALL_RELATIONS"
if [ -z "$GLOBAL_ALL_RELATIONS" ]; then
err "Can't access global \$GLOBAL_ALL_RELATIONS"
return 1 return 1
fi fi
@ -2418,7 +2418,7 @@ get_all_services() {
services["$service"]=1 services["$service"]=1
echo "$service" echo "$service"
done done
done < <(cat "$ALL_RELATIONS") > "$cache_file"
done < <(cat "$GLOBAL_ALL_RELATIONS") > "$cache_file"
cat "$cache_file" cat "$cache_file"
} }
@ -2426,7 +2426,7 @@ export -f get_all_services
get_service_relations () { get_service_relations () {
local service="$1" cache_file="$state_tmpdir/$FUNCNAME.cache.$(H "$@" "$ALL_RELATIONS")" \
local service="$1" cache_file="$state_tmpdir/$FUNCNAME.cache.$(H "$@" "$GLOBAL_ALL_RELATIONS_HASH")" \
s rn ts rc td s rn ts rc td
if [ -e "$cache_file" ]; then if [ -e "$cache_file" ]; then
#debug "$FUNCNAME: SESSION cache hit $1" #debug "$FUNCNAME: SESSION cache hit $1"
@ -2434,15 +2434,15 @@ get_service_relations () {
return 0 return 0
fi fi
if [ -z "$ALL_RELATIONS" ]; then
err "Can't access global \$ALL_RELATIONS"
if [ -z "$GLOBAL_ALL_RELATIONS" ]; then
err "Can't access global \$GLOBAL_ALL_RELATIONS"
return 1 return 1
fi fi
while read-0 s rn ts rc td; do while read-0 s rn ts rc td; do
[[ "$s" == "$service" ]] || continue [[ "$s" == "$service" ]] || continue
printf "%s\0" "$rn" "$ts" "$rc" "$td" printf "%s\0" "$rn" "$ts" "$rc" "$td"
done < <(cat "$ALL_RELATIONS") > "$cache_file"
done < <(cat "$GLOBAL_ALL_RELATIONS") > "$cache_file"
cat "$cache_file" cat "$cache_file"
} }
@ -2480,15 +2480,15 @@ export -f get_service_relation
## (base_service, relation_config) ## (base_service, relation_config)
## ##
get_service_incoming_relations() { get_service_incoming_relations() {
local service="$1" relation="$2" cache_file="$state_tmpdir/$FUNCNAME.cache.$(H "$@" "$ALL_RELATIONS")" \
local service="$1" relation="$2" cache_file="$state_tmpdir/$FUNCNAME.cache.$(H "$@" "$GLOBAL_ALL_RELATIONS_HASH")" \
s rn ts rc td s rn ts rc td
if [ -e "$cache_file" ]; then if [ -e "$cache_file" ]; then
#debug "$FUNCNAME: SESSION cache hit $1" #debug "$FUNCNAME: SESSION cache hit $1"
cat "$cache_file" cat "$cache_file"
return 0 return 0
fi fi
if [ -z "$ALL_RELATIONS" ]; then
err "Can't access global \$ALL_RELATIONS"
if [ -z "$GLOBAL_ALL_RELATIONS" ]; then
err "Can't access global \$GLOBAL_ALL_RELATIONS"
return 1 return 1
fi fi
@ -2497,7 +2497,7 @@ get_service_incoming_relations() {
[[ "$rn" == "$relation" ]] || continue [[ "$rn" == "$relation" ]] || continue
relation_data_file=$(get_relation_data_file "$s" "$ts" "$rn" "$rc") || return 1 relation_data_file=$(get_relation_data_file "$s" "$ts" "$rn" "$rc") || return 1
printf "%s\0" "$s" "$(cat "$relation_data_file")" printf "%s\0" "$s" "$(cat "$relation_data_file")"
done < <(cat "$ALL_RELATIONS") > "$cache_file"
done < "$GLOBAL_ALL_RELATIONS" > "$cache_file"
cat "$cache_file" cat "$cache_file"
} }
@ -2842,14 +2842,14 @@ get_all_relations () {
local cache_file="$state_tmpdir/$FUNCNAME.cache.$(H "$@" "$(declare -p without_relations)")" \ local cache_file="$state_tmpdir/$FUNCNAME.cache.$(H "$@" "$(declare -p without_relations)")" \
services services
if [ -n "$ALL_RELATIONS" ]; then
cat "$ALL_RELATIONS" || return 1
if [ -n "$GLOBAL_ALL_RELATIONS" ]; then
cat "$GLOBAL_ALL_RELATIONS" || return 1
return 0 return 0
fi fi
if [ -e "${cache_file}" ]; then if [ -e "${cache_file}" ]; then
#debug "$FUNCNAME: SESSION cache hit $1" #debug "$FUNCNAME: SESSION cache hit $1"
export ALL_RELATIONS="$cache_file"
export GLOBAL_ALL_RELATIONS="$cache_file"
cat "${cache_file}" cat "${cache_file}"
return 0 return 0
fi fi
@ -3127,8 +3127,10 @@ get_all_relations () {
mv "${cache_file}.wip."{out,in} mv "${cache_file}.wip."{out,in}
done done
export ALL_RELATIONS="$cache_file"
mv "${cache_file}"{.wip.final,} || return 1 mv "${cache_file}"{.wip.final,} || return 1
export GLOBAL_ALL_RELATIONS="$cache_file"
GLOBAL_ALL_RELATIONS_HASH=$(hash_get < "$cache_file") || return 1
export GLOBAL_ALL_RELATIONS_HASH
cat "$cache_file" cat "$cache_file"
} }
export -f get_all_relations export -f get_all_relations

Loading…
Cancel
Save