diff --git a/bin/compose b/bin/compose index 4f1350f..07d617e 100755 --- a/bin/compose +++ b/bin/compose @@ -2091,17 +2091,153 @@ get_docker_compose_single_opts_list() { tr ',' "\n" | xargs echo } -clean_cache() { - local i=0 - for f in $(ls -t "$CACHEDIR/"*.cache.* 2>/dev/null | tail -n +500); do - ((i++)) - rm -f "$f" - done - if (( i > 0 )); then - debug "${WHITE}Cleaned cache:${NORMAL} Removed $((i)) elements (current cache size is $(du -sh "$CACHEDIR" | cut -f 1))" + +_graph_service() { + local service="$1" base="$1" + + charm=$(get_service_charm "$service") || return 1 + metadata=$(charm.metadata "$charm") || return 1 + subordinate=$(echo "$metadata" | shyaml get-value "subordinate" 2>/dev/null) + + if [ "$subordinate" == "True" ]; then + requires="$(echo "$metadata" | shyaml get-value "requires" 2>/dev/null)" + master_charm= + while read-0 relation_name relation; do + [ "$(echo "$relation" | shyaml get-value "scope" 2>/dev/null)" == "container" ] || continue + interface="$(echo "$relation" | shyaml get-value "interface" 2>/dev/null)" + if [ -z "$interface" ]; then + err "No ${WHITE}$interface${NORMAL} set for relation $relation_name." + return 1 + fi + + ## Action provided by relation ? + + target_service= + while read-0 relation_name candidate_target_service _relation_config _tech_dep; do + [ "$interface" == "$relation_name" ] && { + target_service="$candidate_target_service" + break + } + done < <(get_compose_relations "$service") + if [ -z "$target_service" ]; then + err "Couldn't find ${WHITE}relations.$interface${NORMAL} in" \ + "${DARKYELLOW}$service$NORMAL compose definition." + return 1 + fi + master_service="$target_service" + master_charm=$(get_service_charm "$target_service") || return 1 + break + done < <(echo "$requires" | shyaml key-values-0 2>/dev/null) fi + + _graph_node_service "$service" "$base" "$charm" + _graph_edge_service "$service" "$subordinate" "$master_service" + +} + +_graph_node_service() { + local service="$1" base="$2" charm="$3" + + cat < + ]; +EOF + +} + + +_graph_edge_service() { + local service="$1" subordinate="$2" master_service="$3" + while read-0 relation_name target_service relation_config tech_dep; do + cat < "$(_graph_node_service_label ${target_service})" [ + penwidth = $([ "$master_service" == "$target_service" ] && echo 3 || echo 2) + + fontsize = 16 + fontcolor = "black" + style = $([ "$master_service" == "$target_service" ] && echo dashed || echo "\"\"") + weight = $([ "$master_service" == "$target_service" ] && echo 2.0 || echo 1.0) + dir = $([ "$master_service" == "$target_service" ] && echo none || echo both) + arrowtail = odot + # arrowhead = dotlicurve + taillabel = "$relation_name" ]; +EOF + done < <(get_compose_relations "$service") || return 1 +} + + +_graph_node_service_label() { + local service="$1" + echo "service_$service" +} + + +_graph_node_service_content() { + local service="$1" + charm=$(get_service_charm "$service") || return 1 + +cat < + + + $service + + +$(if [ "$charm" != "$service" ]; then +cat < + charm: $charm + +EOF2 +fi) + +EOF +} + +cla_contains () { + local e + for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done + return 1 +} + +graph() { + local services=("$@") + declare -A entries + cat <