Browse Source

fix: override for inner compose

We keep the bin override by sending it through the new session variables.

Signed-off-by: Valentin Lab <valentin.lab@kalysto.org>
lokavaluto/dev/master
Valentin Lab 5 years ago
parent
commit
cd7d069af9
  1. 65
      bin/compose

65
bin/compose

@ -384,27 +384,36 @@ check_no_links_subdirs() {
}
## requires docker_run_opts to be set
get_compose_file_opt() {
local compose_docker_image="$1" hash override
shift
image_id=$(docker_image_id "$compose_docker_image")
override=$(get_volume_opt "${docker_run_opts[@]}") || return 1
get_override() {
local override
override=$(get_volume_opt "$@") || return 1
if [ -n "$override" ]; then
if ! [ -f "$override" ]; then
err "Invalid override of 'compose-core' detected. File '$override' does not exist on host."
err "Invalid override of 'compose-core' detected." \
"File '$override' does not exist on host."
return 1
fi
hash=$( { p0 "$image_id"; cat "$override"; } | md5_compat)
else
hash=$(p0 "$image_id" | md5_compat)
echo "$override"
fi
}
_get_compose_file_opt "$hash" "$override" "$@" || return 1
get_hash_image() {
local compose_docker_image="$1" override="$2"
{
docker_image_id "$compose_docker_image" || {
err "Failed to get docker image id of image '$compose_docker_image'."
return 1
}
p0 ""
[ -n "$override" ] && cat "$override"
true
} | md5_compat
return "${PIPESTATUS[0]}"
}
_get_compose_file_opt() {
get_compose_file_opt() {
local hash_bin="$1" override="$2" \
cache_file="$COMPOSE_LAUNCHER_CACHE/$FUNCNAME.cache.$(p0 "$@" | md5_compat)"
if [ -e "$cache_file" ]; then
@ -444,24 +453,6 @@ _get_compose_file_opt() {
replace_compose_file_opt() {
local compose_docker_image="$1" hash override
shift
image_id=$(docker_image_id "$compose_docker_image")
override=$(get_volume_opt "${docker_run_opts[@]}") || return 1
if [ -n "$override" ]; then
if ! [ -f "$override" ]; then
err "Invalid override of 'compose-core' detected. File '$override' does not exist on host."
return 1
fi
hash=$( { p0 "$image_id"; cat "$override"; } | md5_compat)
else
hash=$(p0 "$image_id" | md5_compat)
fi
_replace_compose_file_opt "$hash" "$override" "$@" || return 1
}
_replace_compose_file_opt() {
local hash_bin="$1" override="$2" \
cache_file="$COMPOSE_LAUNCHER_CACHE/$FUNCNAME.cache.$(p0 "$@" | md5_compat)"
if [ -e "$cache_file" ]; then
@ -856,6 +847,9 @@ mk_docker_run_options() {
COMPOSE_LAUNCHER_BIN=$(readlink -f "${BASH_SOURCE[0]}")
docker_run_opts+=("-v" "$COMPOSE_LAUNCHER_BIN:/usr/local/bin/compose")
COMPOSE_LAUNCHER_BIN_OVERRIDE=$(get_override "${docker_run_opts[@]}") || return 1
COMPOSE_LAUNCHER_HASH=$(
get_hash_image "$COMPOSE_DOCKER_IMAGE" "$COMPOSE_LAUNCHER_BIN_OVERRIDE") || return 1
while read-0 var; do
case "$var" in
@ -869,7 +863,9 @@ mk_docker_run_options() {
esac
done < <(list_compose_vars)
ARG_COMPOSE_FILE=$(get_compose_file_opt "$COMPOSE_DOCKER_IMAGE" "$@") || return 1
ARG_COMPOSE_FILE=$(
get_compose_file_opt "$COMPOSE_LAUNCHER_HASH" "$COMPOSE_LAUNCHER_BIN_OVERRIDE" \
"$@") || return 1
if [ -z "$ARG_COMPOSE_FILE" ]; then
## Find a compose.yml in parents
@ -928,7 +924,7 @@ mk_docker_run_options() {
docker_run_opts+=("${additional_docker_run_opts[@]}")
## keep also some env vars:
for var in ARG_COMPOSE_FILE COMPOSE_DOCKER_IMAGE; do
for var in ARG_COMPOSE_FILE COMPOSE_DOCKER_IMAGE COMPOSE_LAUNCHER_{BIN_OVERRIDE,HASH}; do
p0 "!env:$var=${!var}"
done >> "$filename"
@ -973,7 +969,10 @@ run() {
set_os
if [ -n "$ARG_COMPOSE_FILE" ]; then
array_read-0 cmd_args < <(replace_compose_file_opt "$COMPOSE_DOCKER_IMAGE" "$@")
array_read-0 cmd_args < \
<(replace_compose_file_opt "$COMPOSE_LAUNCHER_HASH" \
"$COMPOSE_LAUNCHER_BIN_OVERRIDE" \
"$@")
set -- "${cmd_args[@]}"
fi

Loading…
Cancel
Save