|
@ -761,7 +761,11 @@ export -f get_service_base_image_dir_uid_gid |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
get_service_type() { |
|
|
get_service_type() { |
|
|
local service="$1" cache_file="$state_tmpdir/$FUNCNAME.cache.$1" |
|
|
|
|
|
|
|
|
if [ -z "$CHARM_STORE_HASH" ]; then |
|
|
|
|
|
err-d "Expected \$CHARM_STORE_HASH to be set." |
|
|
|
|
|
return 1 |
|
|
|
|
|
fi |
|
|
|
|
|
local service="$1" cache_file="$CACHEDIR/$FUNCNAME.cache.$1.$CHARM_STORE_HASH" |
|
|
if [ -z "$service" ]; then |
|
|
if [ -z "$service" ]; then |
|
|
print_syntax_error "$FUNCNAME: Please specify a service as first argument." |
|
|
print_syntax_error "$FUNCNAME: Please specify a service as first argument." |
|
|
return 1 |
|
|
return 1 |
|
@ -1282,11 +1286,22 @@ export -f _get_docker_compose_service_mixin |
|
|
## @export |
|
|
## @export |
|
|
## @cache: !system !nofail +stdout |
|
|
## @cache: !system !nofail +stdout |
|
|
get_docker_compose () { |
|
|
get_docker_compose () { |
|
|
local cache_file="$state_tmpdir/$FUNCNAME.cache.$(echo "$*" | md5_compat)" \ |
|
|
|
|
|
|
|
|
if [ -z "$CHARM_STORE_HASH" ]; then |
|
|
|
|
|
err-d "Expected \$CHARM_STORE_HASH to be set." |
|
|
|
|
|
return 1 |
|
|
|
|
|
fi |
|
|
|
|
|
if [ -z "$COMPOSE_YML_CONTENT_HASH" ]; then |
|
|
|
|
|
err-d "Expected \$COMPOSE_YML_CONTENT_HASH to be set." |
|
|
|
|
|
return 1 |
|
|
|
|
|
fi |
|
|
|
|
|
local cache_file="$CACHEDIR/$FUNCNAME.cache.$(H "$@" "$CHARM_STORE_HASH" "$COMPOSE_YML_CONTENT_HASH")" \ |
|
|
entries services service start docker_compose_services |
|
|
entries services service start docker_compose_services |
|
|
if [ -e "$cache_file" ]; then |
|
|
if [ -e "$cache_file" ]; then |
|
|
# debug "$FUNCNAME: cache hit ($*)" |
|
|
|
|
|
cat "$cache_file" |
|
|
|
|
|
|
|
|
# debug "$FUNCNAME: cache hit ($*) $cache_file" |
|
|
|
|
|
touch "$cache_file" || return 1 |
|
|
|
|
|
cp "$cache_file"{,.wip} || return 1 |
|
|
|
|
|
export _CURRENT_DOCKER_COMPOSE="$cache_file.wip" |
|
|
|
|
|
cat "$cache_file" || return 1 |
|
|
return 0 |
|
|
return 0 |
|
|
fi |
|
|
fi |
|
|
|
|
|
|
|
@ -1339,8 +1354,9 @@ get_docker_compose () { |
|
|
merge_yaml_str "$(yaml_key_val_str "services" "$docker_compose_services")" \ |
|
|
merge_yaml_str "$(yaml_key_val_str "services" "$docker_compose_services")" \ |
|
|
"$base_v2" > "$cache_file" || return 1 |
|
|
"$base_v2" > "$cache_file" || return 1 |
|
|
|
|
|
|
|
|
export _CURRENT_DOCKER_COMPOSE="$cache_file" |
|
|
|
|
|
cat "$_CURRENT_DOCKER_COMPOSE" |
|
|
|
|
|
|
|
|
cp "$cache_file"{,.wip} || return 1 |
|
|
|
|
|
export _CURRENT_DOCKER_COMPOSE="$cache_file.wip" |
|
|
|
|
|
cat "$_CURRENT_DOCKER_COMPOSE" || return 1 |
|
|
debug " ..compilation of base 'docker-compose.yml' done $GRAY(in $((SECONDS - start_compilation))s)$NORMAL" || true |
|
|
debug " ..compilation of base 'docker-compose.yml' done $GRAY(in $((SECONDS - start_compilation))s)$NORMAL" || true |
|
|
# debug " ** ${WHITE}docker-compose.yml${NORMAL}:" |
|
|
# debug " ** ${WHITE}docker-compose.yml${NORMAL}:" |
|
|
# debug "$_current_docker_compose" |
|
|
# debug "$_current_docker_compose" |
|
@ -1387,7 +1403,11 @@ export -f _get_compose_service_def_cached |
|
|
|
|
|
|
|
|
## XXXvlab: a lot to be done to cache the results |
|
|
## XXXvlab: a lot to be done to cache the results |
|
|
get_compose_service_def () { |
|
|
get_compose_service_def () { |
|
|
local service="$1" docker_compose cache_file="$state_tmpdir/$FUNCNAME.cache.$1" \ |
|
|
|
|
|
|
|
|
if [ -z "$COMBINED_HASH" ]; then |
|
|
|
|
|
err-d "Expected \$COMBINED_HASH to be set." |
|
|
|
|
|
return 1 |
|
|
|
|
|
fi |
|
|
|
|
|
local service="$1" docker_compose cache_file="$CACHEDIR/$FUNCNAME.cache.$1.$COMBINED_HASH" \ |
|
|
result |
|
|
result |
|
|
if [ -e "$cache_file" ]; then |
|
|
if [ -e "$cache_file" ]; then |
|
|
#debug "$FUNCNAME: SESSION cache hit" |
|
|
#debug "$FUNCNAME: SESSION cache hit" |
|
@ -1398,7 +1418,7 @@ get_compose_service_def () { |
|
|
[ -z "$service" ] && print_syntax_error "Missing service as first argument." |
|
|
[ -z "$service" ] && print_syntax_error "Missing service as first argument." |
|
|
docker_compose=$(get_compose_yml_content) || return 1 |
|
|
docker_compose=$(get_compose_yml_content) || return 1 |
|
|
result=$(_get_compose_service_def_cached "$service" "$docker_compose") || return 1 |
|
|
result=$(_get_compose_service_def_cached "$service" "$docker_compose") || return 1 |
|
|
charm=$(echo "$result" | shyaml get-value charm 2>/dev/null) || return 1 |
|
|
|
|
|
|
|
|
charm=$(e "$result" | shyaml get-value charm 2>/dev/null) || return 1 |
|
|
metadata=$(charm.metadata "$charm") || return 1 |
|
|
metadata=$(charm.metadata "$charm") || return 1 |
|
|
if default_options=$(printf "%s" "$metadata" | shyaml -y -q get-value default-options); then |
|
|
if default_options=$(printf "%s" "$metadata" | shyaml -y -q get-value default-options); then |
|
|
default_options=$(yaml_key_val_str "options" "$default_options") || return 1 |
|
|
default_options=$(yaml_key_val_str "options" "$default_options") || return 1 |
|
@ -1632,14 +1652,20 @@ cache:image:produce() { |
|
|
} |
|
|
} |
|
|
export -f cache:image:produce |
|
|
export -f cache:image:produce |
|
|
|
|
|
|
|
|
|
|
|
## Will modify current $_CURRENT_DOCKER_COMPOSE file |
|
|
service_ensure_image_ready() { |
|
|
service_ensure_image_ready() { |
|
|
local service="$1" cache_file="$state_tmpdir/$FUNCNAME.cache.$1" \ |
|
|
|
|
|
|
|
|
if [ -z "$COMBINED_HASH" ]; then |
|
|
|
|
|
err "Expected \$COMBINED_HASH to be set." |
|
|
|
|
|
return 1 |
|
|
|
|
|
fi |
|
|
|
|
|
local service="$1" cache_file="$CACHEDIR/$FUNCNAME.cache.$1.$COMBINED_HASH" \ |
|
|
master_service service_def service_image service_build service_dockerfile image \ |
|
|
master_service service_def service_image service_build service_dockerfile image \ |
|
|
specified_image specified_image_id charm_image_name hash \ |
|
|
specified_image specified_image_id charm_image_name hash \ |
|
|
service_quoted |
|
|
service_quoted |
|
|
|
|
|
|
|
|
if [ -e "$cache_file" ]; then |
|
|
if [ -e "$cache_file" ]; then |
|
|
#debug "$FUNCNAME: cache hit ($*)" |
|
|
#debug "$FUNCNAME: cache hit ($*)" |
|
|
|
|
|
touch "$cache_file" || return 1 |
|
|
cat "$cache_file" |
|
|
cat "$cache_file" |
|
|
return 0 |
|
|
return 0 |
|
|
fi |
|
|
fi |
|
@ -1898,9 +1924,17 @@ get_ordered_service_dependencies() { |
|
|
} |
|
|
} |
|
|
export -f get_ordered_service_dependencies |
|
|
export -f get_ordered_service_dependencies |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Modify $_CURRENT_DOCKER_COMPOSE file, and fills cache |
|
|
run_service_acquire_images () { |
|
|
run_service_acquire_images () { |
|
|
local service subservice subservices loaded |
|
|
local service subservice subservices loaded |
|
|
|
|
|
_CURRENT_DOCKER_COMPOSE_HASH=$(hash_get < "$_CURRENT_DOCKER_COMPOSE") |
|
|
|
|
|
local cache_file="$CACHEDIR/$FUNCNAME.cache.$(H "$@" "$_CURRENT_DOCKER_COMPOSE_HASH" "$COMBINED_HASH")" |
|
|
|
|
|
if [ -e "$cache_file" ]; then |
|
|
|
|
|
# debug "$FUNCNAME: cache hit ($*)" |
|
|
|
|
|
touch "$cache_file" || return 1 |
|
|
|
|
|
cp "$cache_file" "$_CURRENT_DOCKER_COMPOSE" || return 1 |
|
|
|
|
|
return 0 |
|
|
|
|
|
fi |
|
|
declare -A loaded |
|
|
declare -A loaded |
|
|
for service in "$@"; do |
|
|
for service in "$@"; do |
|
|
subservices=$(get_ordered_service_dependencies "$service") || return 1 |
|
|
subservices=$(get_ordered_service_dependencies "$service") || return 1 |
|
@ -1921,6 +1955,7 @@ run_service_acquire_images () { |
|
|
loaded[$subservice]=1 |
|
|
loaded[$subservice]=1 |
|
|
done |
|
|
done |
|
|
done |
|
|
done |
|
|
|
|
|
cp "$_CURRENT_DOCKER_COMPOSE" "$cache_file" || return 1 |
|
|
return 0 |
|
|
return 0 |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -2085,6 +2120,10 @@ export -f cfg-get-value |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
relation-get () { |
|
|
relation-get () { |
|
|
|
|
|
if [ -z "$RELATION_DATA_FILE" ]; then |
|
|
|
|
|
err-d "$FUNCNAME: var \$RELATION_DATA_FILE is not set." |
|
|
|
|
|
return 1 |
|
|
|
|
|
fi |
|
|
cfg-get-value "$1" < "$RELATION_DATA_FILE" |
|
|
cfg-get-value "$1" < "$RELATION_DATA_FILE" |
|
|
} |
|
|
} |
|
|
export -f relation-get |
|
|
export -f relation-get |
|
@ -2428,7 +2467,11 @@ export -f _get_compose_relations_cached |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
get_compose_relations () { |
|
|
get_compose_relations () { |
|
|
local service="$1" cache_file="$state_tmpdir/$FUNCNAME.cache.$1" \ |
|
|
|
|
|
|
|
|
if [ -z "$COMBINED_HASH" ]; then |
|
|
|
|
|
err-d "Expected \$COMBINED_HASH to be set." |
|
|
|
|
|
return 1 |
|
|
|
|
|
fi |
|
|
|
|
|
local service="$1" cache_file="$CACHEDIR/$FUNCNAME.cache.$1.$COMBINED_HASH" \ |
|
|
compose_def |
|
|
compose_def |
|
|
|
|
|
|
|
|
if [ -e "$cache_file" ]; then |
|
|
if [ -e "$cache_file" ]; then |
|
@ -2491,7 +2534,11 @@ export -f get_all_services |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
get_service_relations () { |
|
|
get_service_relations () { |
|
|
local service="$1" cache_file="$state_tmpdir/$FUNCNAME.cache.$(H "$@" "$GLOBAL_ALL_RELATIONS_HASH")" \ |
|
|
|
|
|
|
|
|
if [ -z "$GLOBAL_ALL_RELATIONS" ]; then |
|
|
|
|
|
err-d "Can't access global \$GLOBAL_ALL_RELATIONS" |
|
|
|
|
|
return 1 |
|
|
|
|
|
fi |
|
|
|
|
|
local service="$1" cache_file="$CACHEDIR/$FUNCNAME.cache.$1.$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" |
|
@ -2499,11 +2546,6 @@ get_service_relations () { |
|
|
return 0 |
|
|
return 0 |
|
|
fi |
|
|
fi |
|
|
|
|
|
|
|
|
if [ -z "$GLOBAL_ALL_RELATIONS" ]; then |
|
|
|
|
|
err-d "Can't access global \$GLOBAL_ALL_RELATIONS" |
|
|
|
|
|
return 1 |
|
|
|
|
|
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" |
|
@ -2644,6 +2686,34 @@ relation:get() { |
|
|
} |
|
|
} |
|
|
export -f relation:get |
|
|
export -f relation:get |
|
|
|
|
|
|
|
|
|
|
|
services:get:upable() { |
|
|
|
|
|
if [ -z "$CHARM_STORE_HASH" ]; then |
|
|
|
|
|
err-d "Expected \$CHARM_STORE_HASH to be set." |
|
|
|
|
|
return 1 |
|
|
|
|
|
fi |
|
|
|
|
|
local services_args=("$@") cache_file="$CACHEDIR/$FUNCNAME.cache.$(H "$CHARM_STORE_HASH" "$@")" |
|
|
|
|
|
if [ -e "$cache_file" ]; then |
|
|
|
|
|
touch "$cache_file" || return 1 |
|
|
|
|
|
cat "$cache_file" |
|
|
|
|
|
return 0 |
|
|
|
|
|
fi |
|
|
|
|
|
declare -A seen |
|
|
|
|
|
services=($(get_ordered_service_dependencies "${services_args[@]}")) || exit 1 |
|
|
|
|
|
for service in "${services[@]}"; do |
|
|
|
|
|
mservice=$(get_master_service_for_service "$service") || exit 1 |
|
|
|
|
|
[ "${seen[$mservice]}" ] && continue |
|
|
|
|
|
type="$(get_service_type "$mservice")" || exit 1 |
|
|
|
|
|
## remove run-once |
|
|
|
|
|
[ "$type" == "run-once" ] && continue |
|
|
|
|
|
[ "$type" == "stub" ] && continue |
|
|
|
|
|
seen[$mservice]=1 |
|
|
|
|
|
echo "$mservice" |
|
|
|
|
|
done > "$cache_file".wip |
|
|
|
|
|
mv "$cache_file".wip "$cache_file" |
|
|
|
|
|
cat "$cache_file" |
|
|
|
|
|
} |
|
|
|
|
|
export -f services:get:upable |
|
|
|
|
|
|
|
|
service:state() { |
|
|
service:state() { |
|
|
local service="$1" states state |
|
|
local service="$1" states state |
|
|
project_name=$(get_default_project_name) || return 1 |
|
|
project_name=$(get_default_project_name) || return 1 |
|
@ -2664,6 +2734,39 @@ service:state() { |
|
|
} |
|
|
} |
|
|
export -f service:state |
|
|
export -f service:state |
|
|
|
|
|
|
|
|
|
|
|
charm:upstream-version() { |
|
|
|
|
|
local charm="$1" version cache_file="$state_tmpdir/$FUNCNAME.cache.$1" path |
|
|
|
|
|
if [ -e "$cache_file" ]; then |
|
|
|
|
|
cat "$cache_file" |
|
|
|
|
|
return 0 |
|
|
|
|
|
fi |
|
|
|
|
|
if ! path=$(charm.has_direct_action "$charm" "upstream-versions"); then |
|
|
|
|
|
return 0 |
|
|
|
|
|
fi |
|
|
|
|
|
version=$("$path" -l 1) || { |
|
|
|
|
|
err "Failed to get upstream version for ${DARKYELLOW}$charm${NORMAL}." |
|
|
|
|
|
return 1 |
|
|
|
|
|
} |
|
|
|
|
|
if path=$(charm.has_direct_action "$charm" "upstream-version-normalize"); then |
|
|
|
|
|
version=$("$path" "$version") || { |
|
|
|
|
|
err "Failed to normalize upstream version for ${DARKYELLOW}$charm${NORMAL}." |
|
|
|
|
|
return 1 |
|
|
|
|
|
} |
|
|
|
|
|
fi |
|
|
|
|
|
echo "$version" > "$cache_file" |
|
|
|
|
|
e "$version" |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
service:upstream-version() { |
|
|
|
|
|
local service="$1" version |
|
|
|
|
|
charm=$(get_service_charm "$service") || return 1 |
|
|
|
|
|
version=$(charm:upstream-version "$charm") || return 1 |
|
|
|
|
|
e "$version" |
|
|
|
|
|
} |
|
|
|
|
|
export -f service:upstream-version |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_get_charm_metadata_uses() { |
|
|
_get_charm_metadata_uses() { |
|
|
local metadata="$1" cache_file="$CACHEDIR/$FUNCNAME.cache.$(printf "%s\0" "$@" | md5_compat)" |
|
|
local metadata="$1" cache_file="$CACHEDIR/$FUNCNAME.cache.$(printf "%s\0" "$@" | md5_compat)" |
|
|
if [ -e "$cache_file" ]; then |
|
|
if [ -e "$cache_file" ]; then |
|
@ -2819,7 +2922,11 @@ export -f _get_services_provides |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_get_charm_provides() { |
|
|
_get_charm_provides() { |
|
|
local cache_file="$CACHEDIR/$FUNCNAME.cache.$(charm.store_metadata_hash)" errlvl |
|
|
|
|
|
|
|
|
if [ -z "$CHARM_STORE_HASH" ]; then |
|
|
|
|
|
err-d "Expected \$CHARM_STORE_HASH to be set." |
|
|
|
|
|
return 1 |
|
|
|
|
|
fi |
|
|
|
|
|
local cache_file="$CACHEDIR/$FUNCNAME.cache.$CHARM_STORE_HASH" errlvl |
|
|
if [ -e "$cache_file" ]; then |
|
|
if [ -e "$cache_file" ]; then |
|
|
#debug "$FUNCNAME: SESSION cache hit" |
|
|
#debug "$FUNCNAME: SESSION cache hit" |
|
|
cat "$cache_file" |
|
|
cat "$cache_file" |
|
@ -2958,13 +3065,11 @@ _service:all:relations_cached() { |
|
|
|
|
|
|
|
|
## Outputs all relations array. |
|
|
## Outputs all relations array. |
|
|
service:all:relations() { |
|
|
service:all:relations() { |
|
|
if [ -z "$COMPOSE_YML_CONTENT_HASH" ]; then |
|
|
|
|
|
COMPOSE_YML_CONTENT_HASH=$(compose:yml:hash) || { |
|
|
|
|
|
err "Failed to get compose yml hash." |
|
|
|
|
|
return 1 |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if [ -z "$COMBINED_HASH" ]; then |
|
|
|
|
|
err-d "Expected \$COMBINED_HASH to be set." |
|
|
|
|
|
return 1 |
|
|
fi |
|
|
fi |
|
|
local cache_file="$CACHEDIR/$FUNCNAME.cache.$COMPOSE_YML_CONTENT_HASH" |
|
|
|
|
|
|
|
|
local cache_file="$CACHEDIR/$FUNCNAME.cache.$COMBINED_HASH" |
|
|
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}" |
|
@ -2981,16 +3086,14 @@ service:all:relations() { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
_service:all:relations_hash_cached() { |
|
|
_service:all:relations_hash_cached() { |
|
|
if [ -z "$COMPOSE_YML_CONTENT_HASH" ]; then |
|
|
|
|
|
COMPOSE_YML_CONTENT_HASH=$(compose:yml:hash) || { |
|
|
|
|
|
err "Failed to get compose yml hash." |
|
|
|
|
|
return 1 |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if [ -z "$COMBINED_HASH" ]; then |
|
|
|
|
|
err-d "Expected \$COMBINED_HASH to be set." |
|
|
|
|
|
return 1 |
|
|
fi |
|
|
fi |
|
|
local cache_file="$CACHEDIR/$FUNCNAME.cache.$COMPOSE_YML_CONTENT_HASH" \ |
|
|
|
|
|
|
|
|
local cache_file="$CACHEDIR/$FUNCNAME.cache.x${COMBINED_HASH}" \ |
|
|
hash |
|
|
hash |
|
|
if [ -e "${cache_file}" ]; then |
|
|
if [ -e "${cache_file}" ]; then |
|
|
# debug "$FUNCNAME: SESSION cache hit $1" |
|
|
|
|
|
|
|
|
# debug "$FUNCNAME: SESSION cache hit $cache_file" |
|
|
cat "${cache_file}" |
|
|
cat "${cache_file}" |
|
|
return 0 |
|
|
return 0 |
|
|
fi |
|
|
fi |
|
@ -3027,7 +3130,7 @@ service:all:set_relations_hash() { |
|
|
read-0 GLOBAL_ALL_RELATIONS_HASH || return 1 |
|
|
read-0 GLOBAL_ALL_RELATIONS_HASH || return 1 |
|
|
export GLOBAL_ALL_RELATIONS_HASH |
|
|
export GLOBAL_ALL_RELATIONS_HASH |
|
|
## transfer to statedir |
|
|
## transfer to statedir |
|
|
export GLOBAL_ALL_RELATIONS="$state_tmpdir/$FUNCNAME.cache.$COMPOSE_YML_CONTENT_HASH" |
|
|
|
|
|
|
|
|
export GLOBAL_ALL_RELATIONS="$CACHEDIR/$FUNCNAME.cache.$COMBINED_HASH" |
|
|
cat > "$GLOBAL_ALL_RELATIONS" |
|
|
cat > "$GLOBAL_ALL_RELATIONS" |
|
|
} < <(_service:all:relations_hash_cached) |
|
|
} < <(_service:all:relations_hash_cached) |
|
|
if [ -z "$GLOBAL_ALL_RELATIONS" ]; then |
|
|
if [ -z "$GLOBAL_ALL_RELATIONS" ]; then |
|
@ -3083,14 +3186,15 @@ get_subset_relations () { |
|
|
export -f get_subset_relations |
|
|
export -f get_subset_relations |
|
|
|
|
|
|
|
|
get_all_relations () { |
|
|
get_all_relations () { |
|
|
if [ -z "$COMPOSE_YML_CONTENT_HASH" ]; then |
|
|
|
|
|
COMPOSE_YML_CONTENT_HASH=$(compose:yml:hash) || return 1 |
|
|
|
|
|
|
|
|
if [ -z "$COMBINED_HASH" ]; then |
|
|
|
|
|
err-d "Expected \$COMBINED_HASH to be set." |
|
|
|
|
|
return 1 |
|
|
fi |
|
|
fi |
|
|
if [ -n "$GLOBAL_ALL_RELATIONS" ]; then |
|
|
if [ -n "$GLOBAL_ALL_RELATIONS" ]; then |
|
|
cat "$GLOBAL_ALL_RELATIONS" || return 1 |
|
|
cat "$GLOBAL_ALL_RELATIONS" || return 1 |
|
|
return 0 |
|
|
return 0 |
|
|
fi |
|
|
fi |
|
|
local cache_file="$state_tmpdir/$FUNCNAME.cache.$(H "$@" "$COMPOSE_YML_CONTENT_HASH" "$(declare -p without_relations)")" \ |
|
|
|
|
|
|
|
|
local cache_file="$CACHEDIR/$FUNCNAME.cache.$(H "$@" "$COMBINED_HASH" "$(declare -p without_relations)")" \ |
|
|
services all_services service services_uses services_provides \ |
|
|
services all_services service services_uses services_provides \ |
|
|
changed summon required recommended optional |
|
|
changed summon required recommended optional |
|
|
|
|
|
|
|
@ -3537,6 +3641,7 @@ _run_service_action_relation() { |
|
|
print_syntax_error "$FUNCNAME: too many arguments in action descriptor" |
|
|
print_syntax_error "$FUNCNAME: too many arguments in action descriptor" |
|
|
return 1 |
|
|
return 1 |
|
|
fi |
|
|
fi |
|
|
|
|
|
RELATION_DATA_FILE=$(get_relation_data_file "$service" "$target_service" "$relation_name" "$relation_config") || return 1 |
|
|
|
|
|
|
|
|
export action_errlvl_file="$state_tmpdir/action-$service-$charm-$action-errlvl" |
|
|
export action_errlvl_file="$state_tmpdir/action-$service-$charm-$action-errlvl" |
|
|
export state_tmpdir |
|
|
export state_tmpdir |
|
@ -3548,6 +3653,7 @@ _run_service_action_relation() { |
|
|
export RELATION_TARGET_CHARM="$target_charm" |
|
|
export RELATION_TARGET_CHARM="$target_charm" |
|
|
export RELATION_BASE_SERVICE="$service" |
|
|
export RELATION_BASE_SERVICE="$service" |
|
|
export RELATION_BASE_CHARM="$charm" |
|
|
export RELATION_BASE_CHARM="$charm" |
|
|
|
|
|
export RELATION_DATA_FILE="$RELATION_DATA_FILE" |
|
|
export ACTION_NAME=$action |
|
|
export ACTION_NAME=$action |
|
|
export ACTION_SCRIPT_PATH="$action_script_path" |
|
|
export ACTION_SCRIPT_PATH="$action_script_path" |
|
|
export CONTAINER_NAME=$(get_top_master_service_for_service "$service") |
|
|
export CONTAINER_NAME=$(get_top_master_service_for_service "$service") |
|
@ -3615,13 +3721,21 @@ export -f get_relation_data_file |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
has_service_action () { |
|
|
has_service_action () { |
|
|
local service="$1" action="$2" cache_file="$state_tmpdir/$FUNCNAME.cache.$1" \ |
|
|
|
|
|
|
|
|
if [ -z "$CHARM_STORE_HASH" ]; then |
|
|
|
|
|
err-d "Can't access global \$CHARM_STORE_HASH" |
|
|
|
|
|
return 1 |
|
|
|
|
|
fi |
|
|
|
|
|
local service="$1" action="$2" cache_file="$CACHEDIR/$FUNCNAME.cache.$1.$2.$CHARM_STORE_HASH" \ |
|
|
charm target_charm relation_name target_service relation_config _tech_dep \ |
|
|
charm target_charm relation_name target_service relation_config _tech_dep \ |
|
|
path |
|
|
path |
|
|
if [ -e "$cache_file" ]; then |
|
|
if [ -e "$cache_file" ]; then |
|
|
# debug "$FUNCNAME: cache hit ($*)" |
|
|
# debug "$FUNCNAME: cache hit ($*)" |
|
|
cat "$cache_file" |
|
|
|
|
|
return 0 |
|
|
|
|
|
|
|
|
if [ -s "$cache_file" ]; then |
|
|
|
|
|
cat "$cache_file" |
|
|
|
|
|
return 0 |
|
|
|
|
|
else |
|
|
|
|
|
return 1 |
|
|
|
|
|
fi |
|
|
fi |
|
|
fi |
|
|
|
|
|
|
|
|
charm=$(get_service_charm "$service") || return 1 |
|
|
charm=$(get_service_charm "$service") || return 1 |
|
@ -3643,6 +3757,7 @@ has_service_action () { |
|
|
fi |
|
|
fi |
|
|
done < <(get_service_relations "$service") |
|
|
done < <(get_service_relations "$service") |
|
|
|
|
|
|
|
|
|
|
|
touch "$cache_file" |
|
|
return 1 |
|
|
return 1 |
|
|
# master=$(get_top_master_service_for_service "$service") |
|
|
# master=$(get_top_master_service_for_service "$service") |
|
|
# [ "$master" == "$charm" ] && return 1 |
|
|
# [ "$master" == "$charm" ] && return 1 |
|
@ -3762,7 +3877,11 @@ export -f _get_master_service_for_service_cached |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
get_master_service_for_service() { |
|
|
get_master_service_for_service() { |
|
|
local service="$1" cache_file="$state_tmpdir/$FUNCNAME.cache.$1" \ |
|
|
|
|
|
|
|
|
if [ -z "$CHARM_STORE_HASH" ]; then |
|
|
|
|
|
err-d "Expected \$CHARM_STORE_HASH to be set." |
|
|
|
|
|
return 1 |
|
|
|
|
|
fi |
|
|
|
|
|
local service="$1" cache_file="$CACHEDIR/$FUNCNAME.cache.$1.$CHARM_STORE_HASH" \ |
|
|
charm metadata result |
|
|
charm metadata result |
|
|
|
|
|
|
|
|
if [ -e "$cache_file" ]; then |
|
|
if [ -e "$cache_file" ]; then |
|
@ -3782,11 +3901,16 @@ export -f get_master_service_for_service |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
get_top_master_service_for_service() { |
|
|
get_top_master_service_for_service() { |
|
|
local service="$1" cache_file="$state_tmpdir/$FUNCNAME.cache.$1" \ |
|
|
|
|
|
|
|
|
if [ -z "$CHARM_STORE_HASH" ]; then |
|
|
|
|
|
err-d "Expected \$CHARM_STORE_HASH to be set." |
|
|
|
|
|
return 1 |
|
|
|
|
|
fi |
|
|
|
|
|
local service="$1" cache_file="$CACHEDIR/$FUNCNAME.cache.$1.$CHARM_STORE_HASH" \ |
|
|
current_service |
|
|
current_service |
|
|
|
|
|
|
|
|
if [ -e "$cache_file" ]; then |
|
|
if [ -e "$cache_file" ]; then |
|
|
# debug "$FUNCNAME: cache hit ($*)" |
|
|
# debug "$FUNCNAME: cache hit ($*)" |
|
|
|
|
|
touch "$cache_file" || return 1 |
|
|
cat "$cache_file" |
|
|
cat "$cache_file" |
|
|
return 0 |
|
|
return 0 |
|
|
fi |
|
|
fi |
|
@ -4348,6 +4472,12 @@ export -f get_default_target_services |
|
|
|
|
|
|
|
|
get_master_services() { |
|
|
get_master_services() { |
|
|
local loaded master_service service |
|
|
local loaded master_service service |
|
|
|
|
|
local cache_file="$CACHEDIR/$FUNCNAME.cache.$(H "$@" )" |
|
|
|
|
|
if [ -e "$cache_file" ]; then |
|
|
|
|
|
cat "$cache_file" && |
|
|
|
|
|
touch "$cache_file" || return 1 |
|
|
|
|
|
return 0 |
|
|
|
|
|
fi |
|
|
declare -A loaded |
|
|
declare -A loaded |
|
|
for service in "$@"; do |
|
|
for service in "$@"; do |
|
|
master_service=$(get_top_master_service_for_service "$service") || return 1 |
|
|
master_service=$(get_top_master_service_for_service "$service") || return 1 |
|
@ -4356,8 +4486,10 @@ get_master_services() { |
|
|
fi |
|
|
fi |
|
|
echo "$master_service" |
|
|
echo "$master_service" |
|
|
loaded["$master_service"]=1 |
|
|
loaded["$master_service"]=1 |
|
|
done | nspc |
|
|
|
|
|
return "${PIPESTATUS[0]}" |
|
|
|
|
|
|
|
|
done > "$cache_file".wip || return 1 |
|
|
|
|
|
|
|
|
|
|
|
mv "$cache_file"{.wip,} || return 1 |
|
|
|
|
|
cat "$cache_file" || return 1 |
|
|
} |
|
|
} |
|
|
export -f get_master_services |
|
|
export -f get_master_services |
|
|
|
|
|
|
|
@ -5264,12 +5396,12 @@ aexport remainder_args |
|
|
## Actual code |
|
|
## Actual code |
|
|
## |
|
|
## |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
COMPOSE_YML_FILE=$(get_compose_yml_location) || exit 1 |
|
|
COMPOSE_YML_FILE=$(get_compose_yml_location) || exit 1 |
|
|
COMPOSE_YML_CONTENT=$(get_compose_yml_content) || exit 1 |
|
|
COMPOSE_YML_CONTENT=$(get_compose_yml_content) || exit 1 |
|
|
COMPOSE_YML_CONTENT_HASH=$(compose:yml:hash) || exit 1 |
|
|
COMPOSE_YML_CONTENT_HASH=$(compose:yml:hash) || exit 1 |
|
|
export COMPOSE_YML_FILE COMPOSE_YML_CONTENT COMPOSE_YML_CONTENT_HASH |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CHARM_STORE_HASH=$(charm.store_metadata_hash) || exit 1 |
|
|
|
|
|
COMBINED_HASH=$(H "$COMPOSE_YML_CONTENT_HASH" "$CHARM_STORE_HASH") || exit 1 |
|
|
|
|
|
export COMPOSE_YML_FILE COMPOSE_YML_CONTENT COMPOSE_YML_CONTENT_HASH CHARM_STORE_HASH COMBINED_HASH |
|
|
charm.sanity_checks || die "Sanity checks about charm-store failed. Please correct." |
|
|
charm.sanity_checks || die "Sanity checks about charm-store failed. Please correct." |
|
|
|
|
|
|
|
|
## |
|
|
## |
|
@ -5340,7 +5472,7 @@ fi |
|
|
export COMPOSE_ACTION="$action" |
|
|
export COMPOSE_ACTION="$action" |
|
|
NO_CONSTRAINT_CHECK=True |
|
|
NO_CONSTRAINT_CHECK=True |
|
|
case "$action" in |
|
|
case "$action" in |
|
|
up|status) |
|
|
|
|
|
|
|
|
up|status|run) |
|
|
NO_CONSTRAINT_CHECK= |
|
|
NO_CONSTRAINT_CHECK= |
|
|
if [ -n "$DEBUG" ]; then |
|
|
if [ -n "$DEBUG" ]; then |
|
|
Elt "solve all relations" |
|
|
Elt "solve all relations" |
|
@ -5427,36 +5559,23 @@ case "$action" in |
|
|
;; |
|
|
;; |
|
|
esac |
|
|
esac |
|
|
|
|
|
|
|
|
if [ -n "$is_docker_compose_action_multi_service" ]; then |
|
|
|
|
|
if [ -n "$DEBUG" ]; then |
|
|
|
|
|
Elt "get relation subset" |
|
|
|
|
|
start=$(time_now) |
|
|
|
|
|
fi |
|
|
|
|
|
|
|
|
if [ -n "$DEBUG" ]; then |
|
|
|
|
|
Elt "get relation subset" |
|
|
|
|
|
start=$(time_now) |
|
|
|
|
|
fi |
|
|
|
|
|
|
|
|
get_subset_relations "${services_args[@]}" >/dev/null || exit 1 |
|
|
|
|
|
|
|
|
get_subset_relations "${services_args[@]}" >/dev/null || exit 1 |
|
|
|
|
|
|
|
|
if [ -n "$DEBUG" ]; then |
|
|
|
|
|
elapsed="$(time_elapsed $start "$(time_now)")" || exit 1 |
|
|
|
|
|
print_info "$(printf "%.3fs" "$elapsed")" |
|
|
|
|
|
Feedback |
|
|
|
|
|
fi |
|
|
|
|
|
|
|
|
if [ -n "$DEBUG" ]; then |
|
|
|
|
|
elapsed="$(time_elapsed $start "$(time_now)")" || exit 1 |
|
|
|
|
|
print_info "$(printf "%.3fs" "$elapsed")" |
|
|
|
|
|
Feedback |
|
|
fi |
|
|
fi |
|
|
|
|
|
|
|
|
if [ -n "$is_docker_compose_action" ] && [ "${#services_args[@]}" -gt 0 ]; then |
|
|
if [ -n "$is_docker_compose_action" ] && [ "${#services_args[@]}" -gt 0 ]; then |
|
|
services=($(get_master_services "${services_args[@]}")) || exit 1 |
|
|
services=($(get_master_services "${services_args[@]}")) || exit 1 |
|
|
if [ "$action" == "up" ]; then |
|
|
if [ "$action" == "up" ]; then |
|
|
declare -A seen |
|
|
|
|
|
services=($(get_ordered_service_dependencies "${services_args[@]}")) || exit 1 |
|
|
|
|
|
for service in "${services[@]}"; do |
|
|
|
|
|
mservice=$(get_master_service_for_service "$service") || exit 1 |
|
|
|
|
|
[ "${seen[$mservice]}" ] && continue |
|
|
|
|
|
type="$(get_service_type "$mservice")" || exit 1 |
|
|
|
|
|
## remove run-once |
|
|
|
|
|
[ "$type" == "run-once" ] && continue |
|
|
|
|
|
[ "$type" == "stub" ] && continue |
|
|
|
|
|
seen[$mservice]=1 |
|
|
|
|
|
action_posargs+=("$mservice") |
|
|
|
|
|
done |
|
|
|
|
|
|
|
|
action_posargs+=($(services:get:upable "${services_args[@]}")) || exit 1 |
|
|
elif [ "$is_docker_compose_action_multi_service" == "1" ]; then |
|
|
elif [ "$is_docker_compose_action_multi_service" == "1" ]; then |
|
|
action_posargs+=("${services[@]}") |
|
|
action_posargs+=("${services[@]}") |
|
|
elif [ "$is_docker_compose_action_multi_service" == "0" ]; then |
|
|
elif [ "$is_docker_compose_action_multi_service" == "0" ]; then |
|
@ -5564,7 +5683,7 @@ if [ "$action" == "status" ]; then |
|
|
if [[ "$col" == "-"* ]]; then |
|
|
if [[ "$col" == "-"* ]]; then |
|
|
col=${col#-} |
|
|
col=${col#-} |
|
|
fi |
|
|
fi |
|
|
state_columns_raw+=("$col") |
|
|
|
|
|
|
|
|
state_columns_raw+=("${col//-/_}") |
|
|
done |
|
|
done |
|
|
state_columns_align="" |
|
|
state_columns_align="" |
|
|
for col in "${state_columns[@]}"; do |
|
|
for col in "${state_columns[@]}"; do |
|
@ -5581,7 +5700,7 @@ if [ "$action" == "status" ]; then |
|
|
color= |
|
|
color= |
|
|
value="${!col}" |
|
|
value="${!col}" |
|
|
read -r -- value_trim <<<"${!col}" |
|
|
read -r -- value_trim <<<"${!col}" |
|
|
case "$col" in |
|
|
|
|
|
|
|
|
case "${col//_/-}" in |
|
|
root) |
|
|
root) |
|
|
case "$value_trim" in |
|
|
case "$value_trim" in |
|
|
0) value=" ";; |
|
|
0) value=" ";; |
|
@ -5635,12 +5754,12 @@ if [ "$action" == "status" ]; then |
|
|
IFS="=" read -r key value <<<"$filter" |
|
|
IFS="=" read -r key value <<<"$filter" |
|
|
## if not already in state_columns_raw |
|
|
## if not already in state_columns_raw |
|
|
[[ " ${state_columns_raw[*]} " == *" $key "* ]] || |
|
|
[[ " ${state_columns_raw[*]} " == *" $key "* ]] || |
|
|
filter_cols+=("$key") |
|
|
|
|
|
|
|
|
filter_cols+=("${key//-/_}") |
|
|
done |
|
|
done |
|
|
for service in "${services_args[@]}"; do |
|
|
for service in "${services_args[@]}"; do |
|
|
declare -A values=() |
|
|
declare -A values=() |
|
|
for col in "${state_columns_raw[@]}" "${filter_cols[@]}"; do |
|
|
for col in "${state_columns_raw[@]}" "${filter_cols[@]}"; do |
|
|
case "$col" in |
|
|
|
|
|
|
|
|
case "${col//_/-}" in |
|
|
root) |
|
|
root) |
|
|
if [[ " ${compose_yml_services[*]} " == *" ${service} "* ]]; then |
|
|
if [[ " ${compose_yml_services[*]} " == *" ${service} "* ]]; then |
|
|
value="1" |
|
|
value="1" |
|
@ -5658,6 +5777,10 @@ if [ "$action" == "status" ]; then |
|
|
type) |
|
|
type) |
|
|
value=$(get_service_type "$service") || { echo 1; exit 1; } |
|
|
value=$(get_service_type "$service") || { echo 1; exit 1; } |
|
|
;; |
|
|
;; |
|
|
|
|
|
upstream-version) |
|
|
|
|
|
value=$(service:upstream-version "$service") || { echo 1; exit 1; } |
|
|
|
|
|
value=${value:-N/A} |
|
|
|
|
|
;; |
|
|
*) |
|
|
*) |
|
|
if has_service_action "$service" "get-$col" >/dev/null; then |
|
|
if has_service_action "$service" "get-$col" >/dev/null; then |
|
|
state_msg=$(run_service_action "$service" "get-$col") || { echo 1; exit 1 ; } |
|
|
state_msg=$(run_service_action "$service" "get-$col") || { echo 1; exit 1 ; } |
|
|