Skip to content

Commit

Permalink
Fix eclipse-che#4005 only gives -it docker run option if it was given…
Browse files Browse the repository at this point in the history
… from the command line (eclipse-che#4037)

It avoids to give the option when it was not added on the original command line and that the sub action is not requiring a terminal

Also now print a warning if a terminal is given without interactive mode

Change-Id: Ib76480ccf4320748a4fbc4704773b9337048ef61
Signed-off-by: Florent BENOIT <fbenoit@codenvy.com>
  • Loading branch information
benoitf authored Feb 7, 2017
1 parent b8aadda commit ee95f2c
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 4 deletions.
2 changes: 1 addition & 1 deletion dockerfiles/base/scripts/base/commands/cmd_action.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ pre_cmd_action() {
}

cmd_action() {
docker_run -it ${UTILITY_IMAGE_CHEACTION} "$@"
docker_run $(get_docker_run_terminal_options) ${UTILITY_IMAGE_CHEACTION} "$@"
}
2 changes: 1 addition & 1 deletion dockerfiles/base/scripts/base/commands/cmd_dir.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ cmd_dir() {
warning "':/chedir' not mounted - using ${DATA_MOUNT} as source location"
fi

docker_run -it -v ${HOST_FOLDER_TO_USE}:${HOST_FOLDER_TO_USE} \
docker_run $(get_docker_run_terminal_options) -v ${HOST_FOLDER_TO_USE}:${HOST_FOLDER_TO_USE} \
${UTILITY_IMAGE_CHEDIR} ${HOST_FOLDER_TO_USE} "$@"
}
2 changes: 1 addition & 1 deletion dockerfiles/base/scripts/base/commands/cmd_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ pre_cmd_test() {
}

cmd_test() {
docker_run -it ${UTILITY_IMAGE_CHETEST} "$@"
docker_run $(get_docker_run_terminal_options) ${UTILITY_IMAGE_CHETEST} "$@"
}
15 changes: 14 additions & 1 deletion dockerfiles/base/scripts/base/library.sh
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ check_all_ports(){
HTTPD_PORT_STRING+=" -p $PORT"
done

EXECUTION_STRING="docker run -it --rm ${DOCKER_PORT_STRING} ${BOOTSTRAP_IMAGE_ALPINE} \
EXECUTION_STRING="docker run --rm ${DOCKER_PORT_STRING} ${BOOTSTRAP_IMAGE_ALPINE} \
sh -c \"echo hi\" > /dev/null 2>&1"
eval ${EXECUTION_STRING}
NETSTAT_EXIT=$?
Expand Down Expand Up @@ -464,3 +464,16 @@ check_http_code() {
return 1
fi
}

# return options for docker run used by end-user when calling cli
get_docker_run_terminal_options() {
local DOCKER_RUN_OPTIONS=""
# if TTY is there, need to use -ti
if [[ ${TTY_ACTIVATED} == "true" ]]; then
DOCKER_RUN_OPTIONS="-t"
fi
if [[ ${CHE_CLI_IS_INTERACTIVE} == "true" ]]; then
DOCKER_RUN_OPTIONS+="i"
fi
echo ${DOCKER_RUN_OPTIONS}
}
13 changes: 13 additions & 0 deletions dockerfiles/base/scripts/base/startup_02_pre_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -362,10 +362,23 @@ check_docker_networking() {
check_interactive() {
# Detect and verify that the CLI container was started with -it option.
TTY_ACTIVATED=true
CHE_CLI_IS_INTERACTIVE=true

# check if no terminal
if [ ! -t 1 ]; then
TTY_ACTIVATED=false
CHE_CLI_IS_INTERACTIVE=false
warning "Did not detect TTY - interactive mode disabled"
else
# There is a terminal, check if it's in interactive mode
CHE_CLI_IS_INTERACTIVE=$(docker inspect --format='{{.Config.AttachStdin}}' $(get_this_container_id))
if [[ ${CHE_CLI_IS_INTERACTIVE} == "false" ]]; then
CHE_CLI_IS_INTERACTIVE=false
warning "Did detect TTY but not in interactive mode"
fi

fi

}

check_mounts() {
Expand Down

0 comments on commit ee95f2c

Please sign in to comment.