Browse Source

chg: dev: factorize and cache ``get_service_type``

test
Valentin Lab 6 years ago
parent
commit
72930065d6
  1. 24
      bin/compose

24
bin/compose

@ -457,6 +457,26 @@ get_service_base_image_dir_uid_gid() {
export -f get_service_base_image_dir_uid_gid export -f get_service_base_image_dir_uid_gid
get_service_type() {
local service="$1" cache_file="$state_tmpdir/$FUNCNAME.cache.$1"
if [ -z "$service" ]; then
print_syntax_error "$FUNCNAME: Please specify a service as first argument."
return 1
fi
if [ -e "$cache_file" ]; then
# debug "$FUNCNAME: cache hit ($*)"
cat "$cache_file"
return 0
fi
charm=$(get_service_charm "$service") || return 1
metadata=$(charm.metadata "$charm") || return 1
printf "%s" "$metadata" | shyaml get-value type service 2>/dev/null |
tee "$cache_file"
}
are_files_locked_in_dir() { are_files_locked_in_dir() {
local dir="$1" device hdev ldev local dir="$1" device hdev ldev
device=$(stat -c %d "$dir") || { device=$(stat -c %d "$dir") || {
@ -2923,9 +2943,7 @@ else
up) up)
if [ "${#services_args[@]}" == 0 ]; then if [ "${#services_args[@]}" == 0 ]; then
while read-0 service; do while read-0 service; do
charm=$(get_service_charm "$service")
metadata=$(charm.metadata "$charm")
type="$(printf "%s" "$metadata" | shyaml get-value type 2>/dev/null)" || true
type="$(get_service_type "$service")" || exit 1
if [ "$type" != "run-once" ]; then if [ "$type" != "run-once" ]; then
services_args+=("$service") services_args+=("$service")
fi fi

Loading…
Cancel
Save