Browse Source

chg: dev: store env vars in session file

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

58
bin/compose

@ -869,9 +869,9 @@ mk_docker_run_options() {
esac
done < <(list_compose_vars)
compose_file=$(get_compose_file_opt "$COMPOSE_DOCKER_IMAGE" "$@") || return 1
ARG_COMPOSE_FILE=$(get_compose_file_opt "$COMPOSE_DOCKER_IMAGE" "$@") || return 1
if [ -z "$compose_file" ]; then
if [ -z "$ARG_COMPOSE_FILE" ]; then
## Find a compose.yml in parents
debug "No config file specified on command line arguments"
debug "Looking for 'compose.yml' in self and parents.."
@ -889,6 +889,8 @@ mk_docker_run_options() {
else
debug " .. not found."
fi
else
compose_file="$ARG_COMPOSE_FILE"
fi
if [ -n "$compose_file" ]; then
@ -917,15 +919,21 @@ mk_docker_run_options() {
sha=${sha:0:64}
src="$SESSION_DIR/$UID-$sha"
dest="/var/lib/compose/sessions/$UID-$sha"
{
p0 "-v" "$SESSION_DIR/$UID-$sha:$dest:ro"
p0 "-e" "COMPOSE_LAUNCHER_OPTS=$dest"
p0 "-e" "COMPOSE_LAUNCHER_BIN=$COMPOSE_LAUNCHER_BIN"
} >> "$filename"
additional_docker_run_opts=(
"-v" "$SESSION_DIR/$UID-$sha:$dest:ro"
"-e" "COMPOSE_LAUNCHER_OPTS=$dest"
"-e" "COMPOSE_LAUNCHER_BIN=$COMPOSE_LAUNCHER_BIN"
)
p0 "${additional_docker_run_opts[@]}" >> "$filename"
docker_run_opts+=("${additional_docker_run_opts[@]}")
## keep also some env vars:
for var in ARG_COMPOSE_FILE COMPOSE_DOCKER_IMAGE; do
p0 "!env:$var=${!var}"
done >> "$filename"
mkdir -p "$SESSION_DIR" || return 1
mv -f "$filename" "$SESSION_DIR/$UID-$sha" || return 1
e "$SESSION_DIR/$UID-$sha"
mv -f "$filename" "$src" || return 1
if [ -n "$DEBUG" ]; then
echo "${WHITE}Environment:${NORMAL}"
@ -947,25 +955,27 @@ run() {
docker_run_opts=()
if [ -z "$COMPOSE_LAUNCHER_OPTS" ]; then
COMPOSE_LAUNCHER_OPTS="$(mk_docker_run_options "$@")" || return 1
mk_docker_run_options "$@" || return 1
else
while read-0 opt; do
if [[ "$opt" == "!env:"* ]]; then
opt="${opt##!env:}"
var="${opt%%=*}"
value="${opt#*=}"
debug "Loading var: $var=$value"
export "$var"="$value"
else
docker_run_opts+=("$opt")
fi
done < <(cat "$COMPOSE_LAUNCHER_OPTS")
fi
while read-0 opt; do
docker_run_opts+=("$opt")
## catch COMPOSE_DOCKER_IMAGE
if [[ "$env" == "true" && "$opt" == "COMPOSE_DOCKER_IMAGE="* ]]; then
COMPOSE_DOCKER_IMAGE=${opt##COMPOSE_DOCKER_IMAGE=}
elif [ "$opt" == "-e" ]; then
env=true
else
env=
fi
done < <(cat "$COMPOSE_LAUNCHER_OPTS")
set_os
array_read-0 cmd_args < <(replace_compose_file_opt "$COMPOSE_DOCKER_IMAGE" "$@")
set -- "${cmd_args[@]}"
if [ -n "$ARG_COMPOSE_FILE" ]; then
array_read-0 cmd_args < <(replace_compose_file_opt "$COMPOSE_DOCKER_IMAGE" "$@")
set -- "${cmd_args[@]}"
fi
[ -t 0 ] && docker_run_opts+=("-i")
[ -t 1 ] && docker_run_opts+=("-t")

Loading…
Cancel
Save