From b196423053984f5d6fde44fd80b2c8de020c2ea2 Mon Sep 17 00:00:00 2001 From: Valentin Lab Date: Sat, 23 Jan 2016 14:34:10 +0700 Subject: [PATCH] new: added support of ``docker-compose`` options in ``compose.yml``. --- bin/compose | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/bin/compose b/bin/compose index 7982bb5..ee6757a 100755 --- a/bin/compose +++ b/bin/compose @@ -225,6 +225,31 @@ _get_docker_compose_links() { merge_yaml_str "${deps[@]}" | tee "$cache_file" } + +_get_docker_compose_opts() { + local service="$1" cache_file="$state_tmpdir/$FUNCNAME.cache.$(echo "$*" | md5_compat)" \ + links charm charm_part master_charm + 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 + + compose_def="$(get_compose_service_def "$service")" || return 1 + master_charm="$(_get_top_master_charm_for_service "$service")" + docker_compose_opts=$(echo "$compose_def" | shyaml get-value "docker-compose" 2>/dev/null) + + if [ "$docker_compose_opts" ]; then + yaml_key_val_str "$master_charm" "$docker_compose_opts" + fi | tee "$cache_file" +} + + ## ## By Reading the metadata.yml, we create a docker-compose.yml mixin. ## Some metadata.yml (of subordinates) will indeed modify other @@ -247,6 +272,7 @@ _get_docker_compose_service_mixin() { ## The compose part links_yaml=$(_get_docker_compose_links "$service") || return 1 + docker_compose_options=$(_get_docker_compose_opts "$service") || return 1 ## the charm part @@ -257,7 +283,7 @@ _get_docker_compose_service_mixin() { ## Merge results if [ "$charm_part" ]; then charm_yaml="$(yaml_key_val_str "$master_charm" "$charm_part")" || return 1 - merge_yaml_str "$links_yaml" "$charm_yaml" + merge_yaml_str "$links_yaml" "$charm_yaml" "$docker_compose_options" else echo "$links_yaml" fi > "$cache_file"