Browse Source

chg: dev: do only one merging when computing docker-compose yaml from metadata.

hostresources
Valentin Lab 6 years ago
parent
commit
90ae781fe6
  1. 36
      bin/compose-core

36
bin/compose-core

@ -2783,8 +2783,11 @@ export -f get_top_master_service_for_service
## docker-compose entry (thinking of subordinates). The result ## docker-compose entry (thinking of subordinates). The result
## will be merge with master charms. ## will be merge with master charms.
_get_docker_compose_mixin_from_metadata_cached() { _get_docker_compose_mixin_from_metadata_cached() {
local service="$1" charm="$2" metadata="$3" has_build_dir="$4" cache_file="$CACHEDIR/$FUNCNAME.cache.$(echo "$*" | md5_compat)" \
metadata_file metadata volumes docker_compose subordinate image
local service="$1" charm="$2" metadata="$3" \
has_build_dir="$4" \
cache_file="$CACHEDIR/$FUNCNAME.cache.$(echo "$*" | md5_compat)" \
metadata_file metadata volumes docker_compose subordinate image mixin mixins
if [ -e "$cache_file" ]; then if [ -e "$cache_file" ]; then
#debug "$FUNCNAME: STATIC cache hit $1" #debug "$FUNCNAME: STATIC cache hit $1"
cat "$cache_file" && cat "$cache_file" &&
@ -2792,7 +2795,7 @@ _get_docker_compose_mixin_from_metadata_cached() {
return 0 return 0
fi fi
mixin=$(echo -en "labels:\n- compose.charm=$charm")
mixins=("$(echo -en "labels:\n- compose.charm=$charm")")
if [ "$metadata" ]; then if [ "$metadata" ]; then
## resources to volumes ## resources to volumes
volumes=$( volumes=$(
@ -2813,7 +2816,7 @@ _get_docker_compose_mixin_from_metadata_cached() {
else else
die "Invalid host-resource specified in 'metadata.yml'." die "Invalid host-resource specified in 'metadata.yml'."
fi fi
done < <(echo "$metadata" | shyaml get-values-0 "host-resources" 2>/dev/null)
done < <(printf "%s" "$metadata" | shyaml get-values-0 "host-resources" 2>/dev/null)
while read-0 resource; do while read-0 resource; do
dest="$(charm.get_dir "$charm")/resources$resource" dest="$(charm.get_dir "$charm")/resources$resource"
if ! [ -e "$dest" ]; then if ! [ -e "$dest" ]; then
@ -2823,20 +2826,12 @@ _get_docker_compose_mixin_from_metadata_cached() {
done < <(echo "$metadata" | shyaml get-values-0 "charm-resources" 2>/dev/null) done < <(echo "$metadata" | shyaml get-values-0 "charm-resources" 2>/dev/null)
) || return 1 ) || return 1
if [ "$volumes" ]; then if [ "$volumes" ]; then
mixin=$(merge_yaml_str "$mixin" "$(echo -en "volumes:\n$volumes")") || {
err "Failed to merge mixin with ${WHITE}docker-compose${NORMAL} option" \
"from charm ${DARKPINK}$charm$NORMAL."
return 1
}
mixins+=("volumes:"$'\n'"$volumes")
fi fi
docker_compose=$(echo "$metadata" | shyaml get-value -y "docker-compose" 2>/dev/null)
docker_compose=$(printf "%s" "$metadata" | shyaml get-value -y "docker-compose" 2>/dev/null) || true
if [ "$docker_compose" ]; then if [ "$docker_compose" ]; then
mixin=$(merge_yaml_str "$mixin" "$docker_compose") || {
err "Failed to merge mixin with ${WHITE}docker-compose${NORMAL} option" \
"from charm ${DARKPINK}$charm$NORMAL."
return 1
}
mixins+=("$docker_compose")
fi fi
if [ "$(echo "$metadata" | shyaml get-value "subordinate" 2>/dev/null)" == "True" ]; then if [ "$(echo "$metadata" | shyaml get-value "subordinate" 2>/dev/null)" == "True" ]; then
@ -2846,26 +2841,23 @@ _get_docker_compose_mixin_from_metadata_cached() {
image=$(echo "$metadata" | shyaml get-value "docker-image" 2>/dev/null) image=$(echo "$metadata" | shyaml get-value "docker-image" 2>/dev/null)
[ "$image" == "None" ] && image="" [ "$image" == "None" ] && image=""
image_or_build_statement=
if [ "$image" ]; then if [ "$image" ]; then
if [ "$subordinate" ]; then if [ "$subordinate" ]; then
err "Subordinate charm can not have a ${WHITE}docker-image${NORMAL} value." err "Subordinate charm can not have a ${WHITE}docker-image${NORMAL} value."
return 1 return 1
fi fi
image_or_build_statement="image: $image"
mixins+=("image: $image")
elif [ "$has_build_dir" ]; then elif [ "$has_build_dir" ]; then
if [ "$subordinate" ]; then if [ "$subordinate" ]; then
err "Subordinate charm can not have a 'build' sub directory." err "Subordinate charm can not have a 'build' sub directory."
return 1 return 1
fi fi
image_or_build_statement="build: $(charm.get_dir "$charm")/build"
mixins+=("build: $(charm.get_dir "$charm")/build")
fi fi
if [ "$image_or_build_statement" ]; then
mixin=$(merge_yaml_str "$mixin" "$image_or_build_statement") || {
err "Failed to merge yaml with image or build YAML statement."
mixin=$(merge_yaml_str "${mixins[@]}") || {
err "Failed to merge mixins from ${DARKPINK}${charm}${NORMAL} metadata."
return 1 return 1
} }
fi
echo "$mixin" | tee "$cache_file" echo "$mixin" | tee "$cache_file"
} }
export -f _get_docker_compose_mixin_from_metadata_cached export -f _get_docker_compose_mixin_from_metadata_cached

Loading…
Cancel
Save