Browse Source

fix: in WSL, make compose file accessible

We need to copy compose file in a docker host accessible
directory.

Signed-off-by: Valentin Lab <valentin.lab@kalysto.org>
cache-relation
Valentin Lab 5 years ago
parent
commit
59cb64ff92
  1. 45
      bin/compose

45
bin/compose

@ -826,26 +826,6 @@ mk_docker_run_options() {
) )
check_no_links_subdirs "$CHARM_STORE"/* || return 1 check_no_links_subdirs "$CHARM_STORE"/* || return 1
## DEFAULT_COMPOSE_FILE
if [ "${DEFAULT_COMPOSE_FILE+x}" ]; then
DEFAULT_COMPOSE_FILE=$(realpath "$DEFAULT_COMPOSE_FILE")
dirname=$(dirname "$DEFAULT_COMPOSE_FILE")/
if [ -e "${DEFAULT_COMPOSE_FILE}" ]; then
docker_run_opts+=("-v" "$dirname:$dirname:ro")
fi
fi
## COMPOSE_YML_FILE
if [ "${COMPOSE_YML_FILE+x}" ]; then
if [ -e "${COMPOSE_YML_FILE}" ]; then
docker_run_opts+=(
"-v" "$COMPOSE_YML_FILE:/tmp/compose.yml:ro"
"-e" "COMPOSE_YML_FILE=/tmp/compose.yml"
"-e" "HOST_COMPOSE_YML_FILE=/tmp/compose.yml"
)
fi
fi
## DATASTORE and CONFIGSTORE ## DATASTORE and CONFIGSTORE
docker_run_opts+=( docker_run_opts+=(
@ -897,7 +877,9 @@ mk_docker_run_options() {
get_compose_file_opt "$COMPOSE_LAUNCHER_HASH" "$COMPOSE_LAUNCHER_BIN_OVERRIDE" \ get_compose_file_opt "$COMPOSE_LAUNCHER_HASH" "$COMPOSE_LAUNCHER_BIN_OVERRIDE" \
"$@") || return 1 "$@") || return 1
if [ -z "$ARG_COMPOSE_FILE" ]; then
compose_file="${ARG_COMPOSE_FILE:-$COMPOSE_YML_FILE}"
if [ -z "$compose_file" ]; then
## Find a compose.yml in parents ## Find a compose.yml in parents
debug "No config file specified on command line arguments" debug "No config file specified on command line arguments"
debug "Looking for 'compose.yml' in self and parents.." debug "Looking for 'compose.yml' in self and parents.."
@ -915,8 +897,11 @@ mk_docker_run_options() {
else else
debug " .. not found." debug " .. not found."
fi fi
else
compose_file="$ARG_COMPOSE_FILE"
fi
if [ -z "$compose_file" ] && [ "${DEFAULT_COMPOSE_FILE+x}" ]; then
debug "Using \$DEFAULT_COMPOSE_FILE value '$DEFAULT_COMPOSE_FILE' as compose file."
compose_file="$DEFAULT_COMPOSE_FILE"
fi fi
if [ -n "$compose_file" ]; then if [ -n "$compose_file" ]; then
@ -924,11 +909,23 @@ mk_docker_run_options() {
die "Specified compose file '$compose_file' not found." die "Specified compose file '$compose_file' not found."
fi fi
compose_file="$(realpath "$compose_file")" compose_file="$(realpath "$compose_file")"
if [ "$OS" == "wsl" ]; then
## Docker host is not same linux than WSL, so
## access to root files are not the same.
##YYYvlab, check on cp where is the base
dst="$COMPOSE_LAUNCHER_CACHE/compose.$(md5_compat < "$compose_file").yml"
cp "$compose_file" "$dst"
## docker host start with /c/... whereas WSL could start with /mnt/c/...
local="$dst"
else
local="$compose_file"
fi
parent_dir="${compose_file%/*}" parent_dir="${compose_file%/*}"
docker_path=/var/lib/compose/root/${parent_dir##*/}/${compose_file##*/} docker_path=/var/lib/compose/root/${parent_dir##*/}/${compose_file##*/}
docker_run_opts+=( docker_run_opts+=(
"-e" "COMPOSE_YML_FILE=${compose_file##*/}" "-e" "COMPOSE_YML_FILE=${compose_file##*/}"
"-v" "${compose_file}:${docker_path}:ro"
"-v" "${local}:${docker_path}:ro"
"-w" "${docker_path%/*}" "-w" "${docker_path%/*}"
) )
else else

Loading…
Cancel
Save