Browse Source

new: ``host-resources`` implementation.

raw-remaining-args
Valentin Lab 9 years ago
parent
commit
dbba0b1d89
  1. 95
      bin/compose

95
bin/compose

@ -299,6 +299,10 @@ export -f image_exposed_ports_0
## Generic ## Generic
## ##
fn.exists() {
declare -F "$1" >/dev/null
}
str_matches() { str_matches() {
local str="$1" local str="$1"
shift shift
@ -1104,6 +1108,95 @@ EOF
} }
host_resource_get() {
local location="$1" cfg="$2"
type=$(echo "$cfg" | shyaml get-value type 2>/dev/null) || {
err "Missing ${WHITE}type$NORMAL option in ${WHITE}get$NORMAL config for location '$location'"
return 1
}
if fn.exists host_resource_get_$type; then
host_resource_get_$type "$location" "$cfg"
else
err "Source ${WHITE}source$NORMAL type '$type' unknown for" \
"${WHITE}host-resource$NORMAL '$location' defined in" \
"$DARKYELLOW$subservice$NORMAL config."
return 1
fi
}
export -f host_resource_get
host_resource_get_git() {
local location="$1" cfg="$2" branch parent url
branch=$(echo "$cfg" | shyaml get-value branch 2>/dev/null)
branch=${branch:-master}
url=$(echo "$cfg" | shyaml get-value url 2>/dev/null)
parent="$(dirname "$location")"
(
mkdir -p "$parent" && cd "$parent" &&
git clone -b "$branch" "$url" "$(basename "$location")"
) || return 1
}
export -f host_resource_get_git
host_resource_get_git-sub() {
local location="$1" cfg="$2" branch parent url
branch=$(echo "$cfg" | shyaml get-value branch 2>/dev/null)
branch=${branch:-master}
url=$(echo "$cfg" | shyaml get-value url 2>/dev/null)
parent="$(dirname "$location")"
(
mkdir -p "$parent" && cd "$parent" &&
git sub clone -b "$branch" "$url" "$(basename "$location")"
) || return 1
}
export -f host_resource_get_git-sub
setup_host_resources () {
local services="$1" action="$2" loaded location cfg
declare -A loaded
for service in $services; do
for subservice in $(get_ordered_service_dependencies "$service"); do
if [ "${loaded[$subservice]}" ]; then
## Prevent double inclusion of same service if this
## service is deps of two or more of your
## requirements.
continue
fi
service_def=$(get_compose_service_def "$subservice") || return 1
while read-0 location cfg; do
## XXXvlab: will it be a git resources always ?
if [ -d "$location" -a ! -d "$location/.git" ]; then
err "Hum, location '$location' does not seem to be a git directory."
return 1
fi
if [ -d "$location" ]; then
info "host resource '$location' already set up."
continue
fi
get=$(echo "$cfg" | shyaml get-value get 2>/dev/null)
if [ -z "$get" ]; then
err "No host directory '$location' found, and no ${WHITE}source$NORMAL" \
"specified for $DARKYELLOW$subservice$NORMAL."
return 1
fi
host_resource_get "$location" "$get" || return 1
done < <(echo "$service_def" | shyaml key-values-0 host-resources 2>/dev/null)
loaded[$subservice]=1
done
done
return 0
}
relation-get () { relation-get () {
local key="$1" local key="$1"
cat "$RELATION_DATA_FILE" | shyaml get-value "$key" 2>/dev/null cat "$RELATION_DATA_FILE" | shyaml get-value "$key" 2>/dev/null
@ -2240,6 +2333,8 @@ esac
if [ "$full_init" ]; then if [ "$full_init" ]; then
## init in order ## init in order
if [ -z "$no_init" ]; then if [ -z "$no_init" ]; then
Section setup host resources
setup_host_resources "$services" || exit 1
Section initialisation Section initialisation
run_service_hook "$services" init || exit 1 run_service_hook "$services" init || exit 1
fi fi

Loading…
Cancel
Save