|
|
@ -2783,8 +2783,11 @@ export -f get_top_master_service_for_service |
|
|
|
## docker-compose entry (thinking of subordinates). The result |
|
|
|
## will be merge with master charms. |
|
|
|
_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 |
|
|
|
#debug "$FUNCNAME: STATIC cache hit $1" |
|
|
|
cat "$cache_file" && |
|
|
@ -2792,7 +2795,7 @@ _get_docker_compose_mixin_from_metadata_cached() { |
|
|
|
return 0 |
|
|
|
fi |
|
|
|
|
|
|
|
mixin=$(echo -en "labels:\n- compose.charm=$charm") |
|
|
|
mixins=("$(echo -en "labels:\n- compose.charm=$charm")") |
|
|
|
if [ "$metadata" ]; then |
|
|
|
## resources to volumes |
|
|
|
volumes=$( |
|
|
@ -2813,7 +2816,7 @@ _get_docker_compose_mixin_from_metadata_cached() { |
|
|
|
else |
|
|
|
die "Invalid host-resource specified in 'metadata.yml'." |
|
|
|
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 |
|
|
|
dest="$(charm.get_dir "$charm")/resources$resource" |
|
|
|
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) |
|
|
|
) || return 1 |
|
|
|
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 |
|
|
|
|
|
|
|
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 |
|
|
|
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 |
|
|
|
|
|
|
|
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" == "None" ] && image="" |
|
|
|
image_or_build_statement= |
|
|
|
if [ "$image" ]; then |
|
|
|
if [ "$subordinate" ]; then |
|
|
|
err "Subordinate charm can not have a ${WHITE}docker-image${NORMAL} value." |
|
|
|
return 1 |
|
|
|
fi |
|
|
|
image_or_build_statement="image: $image" |
|
|
|
mixins+=("image: $image") |
|
|
|
elif [ "$has_build_dir" ]; then |
|
|
|
if [ "$subordinate" ]; then |
|
|
|
err "Subordinate charm can not have a 'build' sub directory." |
|
|
|
return 1 |
|
|
|
fi |
|
|
|
image_or_build_statement="build: $(charm.get_dir "$charm")/build" |
|
|
|
mixins+=("build: $(charm.get_dir "$charm")/build") |
|
|
|
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 |
|
|
|
} |
|
|
|
fi |
|
|
|
echo "$mixin" | tee "$cache_file" |
|
|
|
} |
|
|
|
export -f _get_docker_compose_mixin_from_metadata_cached |
|
|
|