Browse Source

new: support of ``docker-compose.yml`` v2.0

raw-remaining-args
Valentin Lab 7 years ago
parent
commit
bab67d0ee6
  1. 31
      bin/compose

31
bin/compose

@ -811,7 +811,21 @@ get_docker_compose () {
debug " ..finished all mixins for $DARKYELLOW$target_service$NORMAL $GRAY(in $((SECONDS - start))s)$NORMAL" debug " ..finished all mixins for $DARKYELLOW$target_service$NORMAL $GRAY(in $((SECONDS - start))s)$NORMAL"
done done
merge_yaml_str "${entries[@]}" > "$cache_file"
docker_compose_services=$(merge_yaml_str "${entries[@]}") || return 1
base_v2="version: '2.0'
networks:
static:
driver: bridge
ipam:
driver: default
config:
- subnet: 172.25.1.0/24
"
merge_yaml_str "$(yaml_key_val_str "services" "$docker_compose_services")" \
"$base_v2" > "$cache_file" || return 1
export _current_docker_compose="$(cat "$cache_file")" export _current_docker_compose="$(cat "$cache_file")"
echo "$_current_docker_compose" echo "$_current_docker_compose"
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
@ -897,7 +911,7 @@ get_service_def () {
"\$_current_docker_compose has been calculated." "\$_current_docker_compose has been calculated."
fi fi
def=$(echo "$_current_docker_compose" | shyaml get-value "$service" 2>/dev/null)
def=$(echo "$_current_docker_compose" | shyaml get-value "services.$service" 2>/dev/null)
if [ -z "$def" ]; then if [ -z "$def" ]; then
err "No definition for service $DARKYELLOW$service$NORMAL in compiled 'docker-compose.yml'." err "No definition for service $DARKYELLOW$service$NORMAL in compiled 'docker-compose.yml'."
return 1 return 1
@ -1273,7 +1287,8 @@ export -f config-add
## XXXvlab; this can be used only in relation, I'd like to use it in init. ## XXXvlab; this can be used only in relation, I'd like to use it in init.
init-config-add() { init-config-add() {
local metadata="$1" local metadata="$1"
_config_merge "$state_tmpdir/to-merge-in-docker-compose.yml" <(echo "$metadata")
_config_merge "$state_tmpdir/to-merge-in-docker-compose.yml" \
<(yaml_key_val_str "services" "$metadata")
} }
export -f init-config-add export -f init-config-add
@ -1862,9 +1877,13 @@ _get_docker_compose_mixin_from_metadata_cached() {
mixin=$(echo -en "volumes:\n$volumes") mixin=$(echo -en "volumes:\n$volumes")
fi fi
docker_compose=$(echo "$metadata" | shyaml get-value "docker-compose" 2>/dev/null)
docker_compose=$(echo "$metadata" | shyaml get-value -y "docker-compose" 2>/dev/null)
if [ "$docker_compose" ]; then if [ "$docker_compose" ]; then
mixin=$(merge_yaml_str "$mixin" "$docker_compose")
mixin=$(merge_yaml_str "$mixin" "$docker_compose") || {
err "Failed to merge mixin with ${WHITE}docker-compose${NORMAL} option" \
"from charm ${DARKYELLOW}$charm$NORMAL."
return 1
}
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
@ -1960,7 +1979,7 @@ launch_docker_compose() {
fi fi
## XXXvlab: could be more specific and only link the needed charms ## XXXvlab: could be more specific and only link the needed charms
for charm in $(shyaml keys < "$docker_compose_dir/docker-compose.yml"); do
for charm in $(shyaml keys services < "$docker_compose_dir/docker-compose.yml"); do
if charm.exists "$charm"; then if charm.exists "$charm"; then
ln -sf "$(charm.get_dir "$charm")" "$docker_compose_dir/$charm" || exit 1 ln -sf "$(charm.get_dir "$charm")" "$docker_compose_dir/$charm" || exit 1
fi fi

Loading…
Cancel
Save