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
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."
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
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
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
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
if [ -n "$PROJECT_NAME" ]; then
docker_run_opts+=("-e" "PROJECT_NAME=$PROJECT_NAME")
@ -1068,8 +1073,10 @@ show_env() {
echo " COMPOSE_LAUNCHER_CACHE: $COMPOSE_LAUNCHER_CACHE"
echo " SESSION_DIR: $SESSION_DIR"
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" ] &&
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
## for tech-dep attribute.
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
# debug "$FUNCNAME: cache hit ($*)"
cat "$cache_file"
@ -1767,7 +1767,7 @@ export -f get_service_deps
_rec_get_depth() {
local elt=$1 dep deps max
[ "${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
#debug "$FUNCNAME: cache hit ($*) - $cache_file.depths"
while read-0 k v; do
@ -1810,7 +1810,7 @@ export -f _rec_get_depth
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
if [ -e "$cache_file" ]; then
# debug "$FUNCNAME: cache hit ($*)"
@ -2398,7 +2398,7 @@ export -f get_compose_relations
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
if [ -e "$cache_file" ]; then
#debug "$FUNCNAME: SESSION cache hit $1"
@ -2406,8 +2406,8 @@ get_all_services() {
return 0
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
fi
@ -2418,7 +2418,7 @@ get_all_services() {
services["$service"]=1
echo "$service"
done
done < <(cat "$ALL_RELATIONS") > "$cache_file"
done < <(cat "$GLOBAL_ALL_RELATIONS") > "$cache_file"
cat "$cache_file"
}
@ -2426,7 +2426,7 @@ export -f get_all_services
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
if [ -e "$cache_file" ]; then
#debug "$FUNCNAME: SESSION cache hit $1"
@ -2434,15 +2434,15 @@ get_service_relations () {
return 0
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
fi
while read-0 s rn ts rc td; do
[[ "$s" == "$service" ]] || continue
printf "%s\0" "$rn" "$ts" "$rc" "$td"
done < <(cat "$ALL_RELATIONS") > "$cache_file"
done < <(cat "$GLOBAL_ALL_RELATIONS") > "$cache_file"
cat "$cache_file"
}
@ -2480,15 +2480,15 @@ export -f get_service_relation
## (base_service, relation_config)
##
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
if [ -e "$cache_file" ]; then
#debug "$FUNCNAME: SESSION cache hit $1"
cat "$cache_file"
return 0
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
fi
@ -2497,7 +2497,7 @@ get_service_incoming_relations() {
[[ "$rn" == "$relation" ]] || continue
relation_data_file=$(get_relation_data_file "$s" "$ts" "$rn" "$rc") || return 1
printf "%s\0" "$s" "$(cat "$relation_data_file")"
done < <(cat "$ALL_RELATIONS") > "$cache_file"
done < "$GLOBAL_ALL_RELATIONS" > "$cache_file"
cat "$cache_file"
}
@ -2842,14 +2842,14 @@ 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
if [ -n "$GLOBAL_ALL_RELATIONS" ]; then
cat "$GLOBAL_ALL_RELATIONS" || return 1
return 0
fi
if [ -e "${cache_file}" ]; then
#debug "$FUNCNAME: SESSION cache hit $1"
export ALL_RELATIONS="$cache_file"
export GLOBAL_ALL_RELATIONS="$cache_file"
cat "${cache_file}"
return 0
fi
@ -3127,8 +3127,10 @@ get_all_relations () {
mv "${cache_file}.wip."{out,in}
done
export ALL_RELATIONS="$cache_file"
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"
}
export -f get_all_relations

Loading…
Cancel
Save